2021-04-20 17:14:52 +03:00
|
|
|
# This pipeline aims at building Glances for the following targets:
|
|
|
|
# - Docker Hub
|
|
|
|
# - Pypi
|
2021-04-20 11:09:31 +03:00
|
|
|
|
2021-04-20 17:14:52 +03:00
|
|
|
name: CI
|
2021-04-20 11:09:31 +03:00
|
|
|
|
2021-04-20 17:14:52 +03:00
|
|
|
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') }}
|
2023-07-20 23:42:25 +03:00
|
|
|
DOCKER_PLATFORMS: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386
|
2023-03-12 12:22:53 +03:00
|
|
|
# Ubuntu image only support linux/amd64 and linux/arm64 - See issue #2185
|
|
|
|
DOCKER_PLATFORMS_UBUNTU: linux/amd64,linux/arm64
|
2021-04-20 17:14:52 +03:00
|
|
|
|
|
|
|
on:
|
|
|
|
pull_request:
|
|
|
|
branches: [ develop ]
|
|
|
|
push:
|
|
|
|
branches: [ master, develop ]
|
|
|
|
tags:
|
|
|
|
- v*
|
2021-04-20 11:09:31 +03:00
|
|
|
|
|
|
|
jobs:
|
2021-05-15 10:43:26 +03:00
|
|
|
|
|
|
|
pypi:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
|
2023-09-04 17:43:42 +03:00
|
|
|
- uses: actions/checkout@v4
|
2021-05-15 10:43:26 +03:00
|
|
|
|
|
|
|
- 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
|
2023-12-09 13:24:27 +03:00
|
|
|
uses: pypa/gh-action-pypi-publish@release/v1
|
2021-05-15 10:43:26 +03:00
|
|
|
with:
|
|
|
|
user: __token__
|
|
|
|
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
|
2023-12-09 13:24:27 +03:00
|
|
|
repository-url: https://test.pypi.org/legacy/
|
|
|
|
skip-existing: true
|
2021-05-15 10:43:26 +03:00
|
|
|
|
|
|
|
- name: Publish distribution package to PyPI
|
|
|
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
|
2023-12-09 13:24:27 +03:00
|
|
|
uses: pypa/gh-action-pypi-publish@release/v1
|
2021-05-15 10:43:26 +03:00
|
|
|
with:
|
|
|
|
user: __token__
|
|
|
|
password: ${{ secrets.PYPI_API_TOKEN }}
|
|
|
|
|
2021-05-15 11:26:25 +03:00
|
|
|
create_Docker_builds:
|
2021-04-20 11:09:31 +03:00
|
|
|
runs-on: ubuntu-latest
|
2021-05-15 10:43:26 +03:00
|
|
|
# Make sure we release the python package first. So we are sure to get the latest.
|
|
|
|
needs:
|
|
|
|
- pypi
|
2021-05-15 11:26:25 +03:00
|
|
|
outputs:
|
|
|
|
tags: ${{ steps.config.outputs.tags }}
|
2021-04-20 11:09:31 +03:00
|
|
|
steps:
|
2021-05-15 11:26:25 +03:00
|
|
|
- name: Determine image tags
|
2021-05-14 15:41:12 +03:00
|
|
|
id: config
|
2021-05-15 11:26:25 +03:00
|
|
|
shell: bash
|
2021-04-20 17:14:52 +03:00
|
|
|
run: |
|
2021-05-15 11:26:25 +03:00
|
|
|
TAG_ARRAY='['
|
2021-04-20 17:14:52 +03:00
|
|
|
|
|
|
|
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
|
|
|
VERSION=${GITHUB_REF#refs/tags/v}
|
2021-05-15 11:26:25 +03:00
|
|
|
TAG_ARRAY="$TAG_ARRAY { \"target\": \"minimal\", \"tag\": \"${VERSION}\" },"
|
|
|
|
TAG_ARRAY="$TAG_ARRAY { \"target\": \"full\", \"tag\": \"${VERSION}-full\" },"
|
2021-04-20 11:09:31 +03:00
|
|
|
|
2021-05-14 15:41:12 +03:00
|
|
|
elif [[ $GITHUB_REF == refs/heads/develop ]]; then
|
2021-05-15 11:26:25 +03:00
|
|
|
TAG_ARRAY="$TAG_ARRAY { \"target\": \"dev\", \"tag\": \"dev\" },"
|
2021-05-14 15:41:12 +03:00
|
|
|
|
|
|
|
else
|
2021-05-15 11:26:25 +03:00
|
|
|
TAG_ARRAY="$TAG_ARRAY { \"target\": \"minimal\", \"tag\": \"latest\" },"
|
|
|
|
TAG_ARRAY="$TAG_ARRAY { \"target\": \"full\", \"tag\": \"latest-full\" },"
|
2021-04-20 17:14:52 +03:00
|
|
|
fi
|
|
|
|
|
2021-05-15 11:26:25 +03:00
|
|
|
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:
|
2023-03-12 11:08:12 +03:00
|
|
|
os: ['alpine', 'ubuntu']
|
2021-05-15 11:26:25 +03:00
|
|
|
tag: ${{ fromJson(needs.create_Docker_builds.outputs.tags) }}
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
2023-09-04 17:43:42 +03:00
|
|
|
uses: actions/checkout@v4
|
2021-04-20 17:14:52 +03:00
|
|
|
|
2021-05-14 15:47:41 +03:00
|
|
|
- name: Retrieve Repository Docker metadata
|
|
|
|
id: docker_meta
|
2023-09-12 11:54:09 +03:00
|
|
|
uses: crazy-max/ghaction-docker-meta@v5.0.0
|
2021-05-14 15:47:41 +03:00
|
|
|
with:
|
|
|
|
images: ${{ env.DEFAULT_DOCKER_IMAGE }}
|
|
|
|
labels: |
|
|
|
|
org.opencontainers.image.url=https://nicolargo.github.io/glances/
|
|
|
|
|
2021-05-15 11:26:25 +03:00
|
|
|
- name: Cache Docker layers
|
2022-10-25 16:44:22 +03:00
|
|
|
uses: actions/cache@v3
|
2021-05-15 11:26:25 +03:00
|
|
|
with:
|
|
|
|
path: /tmp/.buildx-cache
|
2021-05-15 15:51:42 +03:00
|
|
|
key: ${{ runner.os }}-buildx-${{ env.NODE_ENV }}-${{ matrix.os }}-${{ matrix.tag.tag }}
|
|
|
|
restore-keys: ${{ runner.os }}-buildx-${{ env.NODE_ENV }}-${{ matrix.os }}
|
2021-05-15 11:26:25 +03:00
|
|
|
|
2021-04-20 17:14:52 +03:00
|
|
|
- name: Set up QEMU
|
2023-09-12 17:09:31 +03:00
|
|
|
uses: docker/setup-qemu-action@v3
|
2021-04-20 11:09:31 +03:00
|
|
|
with:
|
2021-04-20 17:14:52 +03:00
|
|
|
platforms: all
|
2021-04-20 11:09:31 +03:00
|
|
|
|
2021-04-20 17:14:52 +03:00
|
|
|
- name: Set up Docker Buildx
|
|
|
|
id: buildx
|
2023-09-12 14:58:13 +03:00
|
|
|
uses: docker/setup-buildx-action@v3
|
2021-04-20 17:14:52 +03:00
|
|
|
with:
|
|
|
|
version: latest
|
2021-04-20 11:09:31 +03:00
|
|
|
|
2021-04-20 17:14:52 +03:00
|
|
|
- name: Login to DockerHub
|
2023-09-12 14:58:09 +03:00
|
|
|
uses: docker/login-action@v3
|
2021-04-20 17:14:52 +03:00
|
|
|
if: ${{ env.PUSH_BRANCH == 'true' }}
|
|
|
|
with:
|
|
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
2022-10-22 10:29:19 +03:00
|
|
|
password: ${{ secrets.DOCKER_TOKEN }}
|
2021-04-20 17:14:52 +03:00
|
|
|
|
2021-05-15 11:26:25 +03:00
|
|
|
- name: Build and push image
|
2023-09-12 11:54:14 +03:00
|
|
|
uses: docker/build-push-action@v5
|
2021-04-20 17:14:52 +03:00
|
|
|
with:
|
|
|
|
push: ${{ env.PUSH_BRANCH == 'true' }}
|
2022-11-03 17:05:57 +03:00
|
|
|
tags: "${{ env.DEFAULT_DOCKER_IMAGE }}:${{ matrix.os != 'alpine' && format('{0}-', matrix.os) || '' }}${{ matrix.tag.tag }}"
|
2021-04-20 17:14:52 +03:00
|
|
|
build-args: |
|
2021-05-15 11:26:25 +03:00
|
|
|
CHANGING_ARG=${{ github.sha }}
|
2021-04-20 17:14:52 +03:00
|
|
|
context: .
|
2021-05-15 11:26:25 +03:00
|
|
|
file: "docker-files/${{ matrix.os }}.Dockerfile"
|
2023-03-12 12:22:53 +03:00
|
|
|
platforms: ${{ matrix.os != 'ubuntu' && env.DOCKER_PLATFORMS || env.DOCKER_PLATFORMS_UBUNTU }}
|
2021-05-15 11:26:25 +03:00
|
|
|
target: ${{ matrix.tag.target }}
|
2021-05-14 15:47:41 +03:00
|
|
|
labels: ${{ steps.docker_meta.outputs.labels }}
|
2021-04-20 17:14:52 +03:00
|
|
|
cache-from: type=local,src=/tmp/.buildx-cache
|
|
|
|
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
|