summaryrefslogtreecommitdiffstats
path: root/.github/workflows/build.yml
blob: ba83fa83a948fb5fd9a30e6ee29ae171817a8359 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# This pipeline aims at building Glances for the following targets:
# - Docker Hub
# - Pypi

name: CI

env:
  DEFAULT_DOCKER_IMAGE: nicolargo/glances
  NODE_ENV: ${{ (contains('refs/heads/master', github.ref) || startsWith(github.ref, 'refs/tags/v')) && 'prod' || 'dev' }}
  PUSH_BRANCH: ${{ 'refs/heads/develop' == github.ref || 'refs/heads/master' == github.ref || startsWith(github.ref, 'refs/tags/v') }}
  DOCKER_PLATFORMS: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386

on:
  pull_request:
    branches: [ develop ]
  push:
    branches: [ master, develop ]
    tags:
      - v*

jobs:

  pypi:
    runs-on: ubuntu-latest
    steps:

      - uses: actions/checkout@v2

      - name: Install pip install build tools
        run: >-
          python -m
          pip install
          build
          --user

      - name: Build a binary wheel and a source tarball
        run: >-
          python -m
          build
          --sdist
          --wheel
          --outdir dist/

      - name: Publish distribution package to Test PyPI
        uses: pypa/gh-action-pypi-publish@master
        with:
          user: __token__
          password: ${{ secrets.TEST_PYPI_API_TOKEN }}
          repository_url: https://test.pypi.org/legacy/
          skip_existing: true

      - name: Publish distribution package to PyPI
        if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
        uses: pypa/gh-action-pypi-publish@master
        with:
          user: __token__
          password: ${{ secrets.PYPI_API_TOKEN }}

  docker-images:
    runs-on: ubuntu-latest
    # Make sure we release the python package first. So we are sure to get the latest.
    needs:
      - pypi
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Cache Docker layers
        uses: actions/cache@v2
        with:
          path: /tmp/.buildx-cache
          key: ${{ runner.os }}-buildx-${{ env.NODE_ENV }}-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-buildx-${{ env.NODE_ENV }}

      - name: Configure
        id: config
        run: |
          ls -la /tmp/.buildx-cache || true
          DEFAULT_TAGET='minimal'

          if [[ $GITHUB_REF == refs/tags/* ]]; then
            VERSION=${GITHUB_REF#refs/tags/v}
            DEFAULT_TAG="${VERSION}"s
            FULL_TAG="${VERSION}-full"

          elif [[ $GITHUB_REF == refs/heads/develop ]]; then
            VERSION=dev
            DEFAULT_TAG="${VERSION}"
            DEFAULT_TAGET='dev'

          else
            VERSION=latest
            DEFAULT_TAG="${VERSION}"
          fi

          echo "::set-output name=defaultTag::$DEFAULT_TAG"
          echo "::set-output name=fullTag::$FULL_TAG"
          echo "::set-output name=defaultTarget::$DEFAULT_TAGET"

      - name: Retrieve Repository Docker metadata
        id: docker_meta
        uses: crazy-max/ghaction-docker-meta@v2.5.0
        with:
          images: ${{ env.DEFAULT_DOCKER_IMAGE }}
          labels: |
            org.opencontainers.image.url=https://nicolargo.github.io/glances/

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1
        with:
          platforms: all

      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v1
        with:
          version: latest

      - name: Login to DockerHub
        uses: docker/login-action@v1
        if: ${{ env.PUSH_BRANCH == 'true' }}
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Build and push minimal image
        uses: docker/build-push-action@v2
        with:
          push: ${{ env.PUSH_BRANCH == 'true' }}
          tags: ${{ steps.config.outputs.defaultTag }}
          build-args: |
            ACTION_ID=${{env.GITHUB_ACTION}}
          context: .
          file: docker-files/debian.Dockerfile
          platforms: ${{env.DOCKER_PLATFORMS}}
          target: ${{ steps.config.outputs.defaultTarget }}
          labels: ${{ steps.docker_meta.outputs.labels }}
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache,mode=max

      - name: Build and push full image
        if: ${{ steps.config.outputs.fullTag != '' }}
        uses: docker/build-push-action@v2
        with:
          push: ${{ env.PUSH_BRANCH == 'true' }}
          tags: ${{ steps.config.outputs.fullTag }}
          build-args: |
            CHANGING_ARG=${{env.GITHUB_SHA}}
          context: .
          file: docker-files/debian.Dockerfile
          target: full
          platforms: ${{env.DOCKER_PLATFORMS}}
          labels: ${{ steps.docker_meta.outputs.labels }}
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache,mode=max