mirror of https://github.com/nicolargo/glances.git
Rework CI to split build Pypi packages and build Docker images
This commit is contained in:
parent
ddd7e5ebe4
commit
a36c2bf87a
|
|
@ -1,34 +1,15 @@
|
||||||
# This pipeline aims at building Glances for the following targets:
|
# This pipeline aims at building Glances Pypi packages
|
||||||
# - Pypi
|
|
||||||
# - Docker Hub
|
|
||||||
|
|
||||||
name: build
|
name: build
|
||||||
|
|
||||||
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') }}
|
|
||||||
# Alpine image platform: https://hub.docker.com/_/alpine
|
|
||||||
# linux/arm/v6,linux/arm/v7 do not work (timeout during the build)
|
|
||||||
DOCKER_PLATFORMS: linux/amd64,linux/arm64/v8
|
|
||||||
# Ubuntu image platforms list: https://hub.docker.com/_/ubuntu
|
|
||||||
# linux/arm/v7 do not work (Cargo/Rust not available)
|
|
||||||
DOCKER_PLATFORMS_UBUNTU: linux/amd64,linux/arm64/v8
|
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
secrets:
|
|
||||||
DOCKER_USERNAME:
|
|
||||||
description: 'Docker Hub username'
|
|
||||||
required: true
|
|
||||||
DOCKER_TOKEN:
|
|
||||||
description: 'Docker Hub token'
|
|
||||||
required: true
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: Build distribution 📦
|
name: Build distribution 📦
|
||||||
|
if: github.event_name == 'push'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
@ -52,7 +33,7 @@ jobs:
|
||||||
|
|
||||||
pypi:
|
pypi:
|
||||||
name: Publish Python 🐍 distribution 📦 to PyPI
|
name: Publish Python 🐍 distribution 📦 to PyPI
|
||||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
|
if: startsWith(github.ref, 'refs/tags')
|
||||||
needs:
|
needs:
|
||||||
- build
|
- build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
@ -76,7 +57,7 @@ jobs:
|
||||||
|
|
||||||
pypi_test:
|
pypi_test:
|
||||||
name: Publish Python 🐍 distribution 📦 to TestPyPI
|
name: Publish Python 🐍 distribution 📦 to TestPyPI
|
||||||
if: github.event_name == 'push' && github.ref == 'refs/heads/develop'
|
if: github.ref == 'refs/heads/develop'
|
||||||
needs:
|
needs:
|
||||||
- build
|
- build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
@ -98,91 +79,3 @@ jobs:
|
||||||
repository-url: https://test.pypi.org/legacy/
|
repository-url: https://test.pypi.org/legacy/
|
||||||
skip-existing: true
|
skip-existing: true
|
||||||
attestations: false
|
attestations: false
|
||||||
|
|
||||||
create_Docker_builds:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs:
|
|
||||||
- pypi
|
|
||||||
- pypi_test
|
|
||||||
outputs:
|
|
||||||
tags: ${{ steps.config.outputs.tags }}
|
|
||||||
steps:
|
|
||||||
- name: Determine image tags
|
|
||||||
id: config
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
TAG_ARRAY='['
|
|
||||||
|
|
||||||
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
|
||||||
VERSION=${GITHUB_REF#refs/tags/v}
|
|
||||||
TAG_ARRAY="$TAG_ARRAY { \"target\": \"minimal\", \"tag\": \"${VERSION}\" },"
|
|
||||||
TAG_ARRAY="$TAG_ARRAY { \"target\": \"full\", \"tag\": \"${VERSION}-full\" },"
|
|
||||||
|
|
||||||
elif [[ $GITHUB_REF == refs/heads/develop ]]; then
|
|
||||||
TAG_ARRAY="$TAG_ARRAY { \"target\": \"dev\", \"tag\": \"dev\" },"
|
|
||||||
|
|
||||||
else
|
|
||||||
TAG_ARRAY="$TAG_ARRAY { \"target\": \"minimal\", \"tag\": \"latest\" },"
|
|
||||||
TAG_ARRAY="$TAG_ARRAY { \"target\": \"full\", \"tag\": \"latest-full\" },"
|
|
||||||
fi
|
|
||||||
|
|
||||||
TAG_ARRAY="${TAG_ARRAY::-1} ]"
|
|
||||||
|
|
||||||
echo "Tags to build: $TAG_ARRAY"
|
|
||||||
echo "tags=$TAG_ARRAY" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
build_Docker_image:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs:
|
|
||||||
- create_Docker_builds
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: ['alpine', 'ubuntu']
|
|
||||||
tag: ${{ fromJson(needs.create_Docker_builds.outputs.tags) }}
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Retrieve Repository Docker metadata
|
|
||||||
id: docker_meta
|
|
||||||
uses: docker/metadata-action@v5
|
|
||||||
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@v3
|
|
||||||
with:
|
|
||||||
platforms: all
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
id: buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
version: latest
|
|
||||||
|
|
||||||
- name: Login to DockerHub
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
if: ${{ env.PUSH_BRANCH == 'true' }}
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKER_TOKEN }}
|
|
||||||
|
|
||||||
- name: Build and push image
|
|
||||||
uses: docker/build-push-action@v5
|
|
||||||
with:
|
|
||||||
push: ${{ env.PUSH_BRANCH == 'true' }}
|
|
||||||
tags: "${{ env.DEFAULT_DOCKER_IMAGE }}:${{ matrix.os != 'alpine' && format('{0}-', matrix.os) || '' }}${{ matrix.tag.tag }}"
|
|
||||||
build-args: |
|
|
||||||
CHANGING_ARG=${{ github.sha }}
|
|
||||||
context: .
|
|
||||||
file: "docker-files/${{ matrix.os }}.Dockerfile"
|
|
||||||
platforms: ${{ matrix.os != 'ubuntu' && env.DOCKER_PLATFORMS || env.DOCKER_PLATFORMS_UBUNTU }}
|
|
||||||
target: ${{ matrix.tag.target }}
|
|
||||||
labels: ${{ steps.docker_meta.outputs.labels }}
|
|
||||||
# GHA default behaviour overwrites last build cache. Causes alpine and ubuntu cache to overwrite each other.
|
|
||||||
# Use `scope` with the os name to prevent that
|
|
||||||
cache-from: 'type=gha,scope=${{ matrix.os }}'
|
|
||||||
cache-to: 'type=gha,mode=max,scope=${{ matrix.os }}'
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,109 @@
|
||||||
|
# This pipeline aims at building Glances Docker images
|
||||||
|
|
||||||
|
name: build_docker
|
||||||
|
|
||||||
|
env:
|
||||||
|
DEFAULT_DOCKER_IMAGE: nicolargo/glances
|
||||||
|
PUSH_BRANCH: ${{ 'refs/heads/develop' == github.ref || 'refs/heads/master' == github.ref || startsWith(github.ref, 'refs/tags/v') }}
|
||||||
|
# Alpine image platform: https://hub.docker.com/_/alpine
|
||||||
|
# linux/arm/v6,linux/arm/v7 do not work (timeout during the build)
|
||||||
|
DOCKER_PLATFORMS: linux/amd64,linux/arm64/v8
|
||||||
|
# Ubuntu image platforms list: https://hub.docker.com/_/ubuntu
|
||||||
|
# linux/arm/v7 do not work (Cargo/Rust not available)
|
||||||
|
DOCKER_PLATFORMS_UBUNTU: linux/amd64,linux/arm64/v8
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
secrets:
|
||||||
|
DOCKER_USERNAME:
|
||||||
|
description: 'Docker Hub username'
|
||||||
|
required: true
|
||||||
|
DOCKER_TOKEN:
|
||||||
|
description: 'Docker Hub token'
|
||||||
|
required: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
create_docker_images_list:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
tags: ${{ steps.config.outputs.tags }}
|
||||||
|
steps:
|
||||||
|
- name: Determine image tags
|
||||||
|
id: config
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
||||||
|
VERSION=${GITHUB_REF#refs/tags/v}
|
||||||
|
TAG_ARRAY="[{ \"target\": \"minimal\", \"tag\": \"${VERSION}\" },"
|
||||||
|
TAG_ARRAY="$TAG_ARRAY { \"target\": \"full\", \"tag\": \"${VERSION}-full\" }]"
|
||||||
|
elif [[ $GITHUB_REF == refs/heads/develop ]]; then
|
||||||
|
TAG_ARRAY="[{ \"target\": \"dev\", \"tag\": \"dev\" }]"
|
||||||
|
elif [[ $GITHUB_REF == refs/heads/master ]]; then
|
||||||
|
TAG_ARRAY="[{ \"target\": \"minimal\", \"tag\": \"latest\" },"
|
||||||
|
TAG_ARRAY="$TAG_ARRAY { \"target\": \"full\", \"tag\": \"latest-full\" }]"
|
||||||
|
elif [[ $GITHUB_REF == refs/heads/main ]]; then
|
||||||
|
TAG_ARRAY="[{ \"target\": \"minimal\", \"tag\": \"latest\" },"
|
||||||
|
TAG_ARRAY="$TAG_ARRAY { \"target\": \"full\", \"tag\": \"latest-full\" }]"
|
||||||
|
else
|
||||||
|
TAG_ARRAY="[]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Tags to build: $TAG_ARRAY"
|
||||||
|
echo "tags=$TAG_ARRAY" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
build_docker_images:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs:
|
||||||
|
- create_docker_images_list
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: ['alpine', 'ubuntu']
|
||||||
|
tag: ${{ fromJson(needs.create_docker_images_list.outputs.tags) }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Retrieve Repository Docker metadata
|
||||||
|
id: docker_meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
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@v3
|
||||||
|
with:
|
||||||
|
platforms: all
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
id: buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
|
||||||
|
- name: Login to DockerHub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
if: ${{ env.PUSH_BRANCH == 'true' }}
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push image
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
push: ${{ env.PUSH_BRANCH == 'true' }}
|
||||||
|
tags: "${{ env.DEFAULT_DOCKER_IMAGE }}:${{ matrix.os != 'alpine' && format('{0}-', matrix.os) || '' }}${{ matrix.tag.tag }}"
|
||||||
|
build-args: |
|
||||||
|
CHANGING_ARG=${{ github.sha }}
|
||||||
|
context: .
|
||||||
|
file: "docker-files/${{ matrix.os }}.Dockerfile"
|
||||||
|
platforms: ${{ matrix.os != 'ubuntu' && env.DOCKER_PLATFORMS || env.DOCKER_PLATFORMS_UBUNTU }}
|
||||||
|
target: ${{ matrix.tag.target }}
|
||||||
|
labels: ${{ steps.docker_meta.outputs.labels }}
|
||||||
|
# GHA default behaviour overwrites last build cache. Causes alpine and ubuntu cache to overwrite each other.
|
||||||
|
# Use `scope` with the os name to prevent that
|
||||||
|
cache-from: 'type=gha,scope=${{ matrix.os }}'
|
||||||
|
cache-to: 'type=gha,mode=max,scope=${{ matrix.os }}'
|
||||||
|
|
@ -17,6 +17,10 @@ jobs:
|
||||||
build:
|
build:
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
uses: ./.github/workflows/build.yml
|
uses: ./.github/workflows/build.yml
|
||||||
|
needs: [quality, test]
|
||||||
|
build_docker:
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
uses: ./.github/workflows/build_docker.yml
|
||||||
secrets:
|
secrets:
|
||||||
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
||||||
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
|
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,8 @@ RUN apk add --no-cache \
|
||||||
pkgconfig \
|
pkgconfig \
|
||||||
libffi-dev \
|
libffi-dev \
|
||||||
openssl-dev \
|
openssl-dev \
|
||||||
cmake # Issue: https://github.com/nicolargo/glances/issues/2735
|
cmake
|
||||||
|
# for cmake: Issue: https://github.com/nicolargo/glances/issues/2735
|
||||||
|
|
||||||
RUN python${PYTHON_VERSION} -m venv venv-build
|
RUN python${PYTHON_VERSION} -m venv venv-build
|
||||||
RUN /venv-build/bin/python${PYTHON_VERSION} -m pip install --upgrade pip
|
RUN /venv-build/bin/python${PYTHON_VERSION} -m pip install --upgrade pip
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue