build.yml 4.5 KB
Newer Older
N
nicolargo 已提交
1 2 3
# This pipeline aims at building Glances for the following targets:
# - Docker Hub
# - Pypi
4

N
nicolargo 已提交
5
name: CI
6

N
nicolargo 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19
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*
20 21

jobs:
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

  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 }}

M
Markus Pöschl 已提交
59
  create_Docker_builds:
60
    runs-on: ubuntu-latest
61 62 63
    # Make sure we release the python package first. So we are sure to get the latest.
    needs:
      - pypi
M
Markus Pöschl 已提交
64 65
    outputs:
      tags: ${{ steps.config.outputs.tags }}
66
    steps:
M
Markus Pöschl 已提交
67
      - name: Determine image tags
68
        id: config
M
Markus Pöschl 已提交
69
        shell: bash
N
nicolargo 已提交
70
        run: |
M
Markus Pöschl 已提交
71
          TAG_ARRAY='['
N
nicolargo 已提交
72 73 74

          if [[ $GITHUB_REF == refs/tags/* ]]; then
            VERSION=${GITHUB_REF#refs/tags/v}
M
Markus Pöschl 已提交
75 76
            TAG_ARRAY="$TAG_ARRAY { \"target\": \"minimal\", \"tag\": \"${VERSION}\" },"
            TAG_ARRAY="$TAG_ARRAY { \"target\": \"full\", \"tag\": \"${VERSION}-full\" },"
77

78
          elif [[ $GITHUB_REF == refs/heads/develop ]]; then
M
Markus Pöschl 已提交
79
            TAG_ARRAY="$TAG_ARRAY { \"target\": \"dev\", \"tag\": \"dev\" },"
80 81

          else
M
Markus Pöschl 已提交
82 83
            TAG_ARRAY="$TAG_ARRAY { \"target\": \"minimal\", \"tag\": \"latest\" },"
            TAG_ARRAY="$TAG_ARRAY { \"target\": \"full\", \"tag\": \"latest-full\" },"
N
nicolargo 已提交
84 85
          fi

M
Markus Pöschl 已提交
86 87 88 89 90 91 92 93 94 95 96 97
          TAG_ARRAY="${TAG_ARRAY::-1} ]"

          echo "Tags to build: $TAG_ARRAY"
          echo "::set-output name=tags::$TAG_ARRAY"

  build_Docker_image:
    runs-on: ubuntu-latest
    needs:
      - create_Docker_builds
    strategy:
      fail-fast: false
      matrix:
M
Markus Pöschl 已提交
98
        os: ['debian', 'alpine']
M
Markus Pöschl 已提交
99 100 101 102
        tag: ${{ fromJson(needs.create_Docker_builds.outputs.tags) }}
    steps:
      - name: Checkout
        uses: actions/checkout@v2
N
nicolargo 已提交
103

104 105 106 107 108 109 110 111
      - 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/

M
Markus Pöschl 已提交
112 113 114 115 116 117 118 119
      - 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 }}

N
nicolargo 已提交
120 121
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1
122
        with:
N
nicolargo 已提交
123
          platforms: all
124

N
nicolargo 已提交
125 126 127 128 129
      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v1
        with:
          version: latest
130

N
nicolargo 已提交
131 132 133 134 135 136 137
      - name: Login to DockerHub
        uses: docker/login-action@v1
        if: ${{ env.PUSH_BRANCH == 'true' }}
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

M
Markus Pöschl 已提交
138
      - name: Build and push image
N
nicolargo 已提交
139 140 141
        uses: docker/build-push-action@v2
        with:
          push: ${{ env.PUSH_BRANCH == 'true' }}
M
Markus Pöschl 已提交
142
          tags: ${{ matrix.tag.tag }}
N
nicolargo 已提交
143
          build-args: |
M
Markus Pöschl 已提交
144
            CHANGING_ARG=${{ github.sha }}
N
nicolargo 已提交
145
          context: .
M
Markus Pöschl 已提交
146
          file: "docker-files/${{ matrix.os }}.Dockerfile"
N
nicolargo 已提交
147
          platforms: ${{env.DOCKER_PLATFORMS}}
M
Markus Pöschl 已提交
148
          target: ${{ matrix.tag.target }}
149
          labels: ${{ steps.docker_meta.outputs.labels }}
N
nicolargo 已提交
150 151
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache,mode=max