add comment #932
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a basic workflow to help you get started with Actions | |
name: main | |
# Controls when the action will run. Triggers the workflow on push or pull request | |
# events but only for the master branch | |
on: [push, pull_request] | |
env: | |
imagetag: ${{ github.head_ref || github.ref_name || 'dev' }} | |
branch: ${{ github.head_ref || github.ref_name || 'dev' }} | |
node_version: '20' | |
REGISTRY_IMAGE: abcdesktopio/pyos | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
# This workflow contains a single job called "build" | |
build: | |
strategy: | |
fail-fast: false | |
matrix: | |
# only platform to build, not the image target | |
platform-runs: [ ubuntu-latest, ubuntu-24.04-arm ] | |
# this is the target build image | |
# debian_bookworm -> debian and bookworm | |
# alpine_latest -> alpine and latest | |
distribs: [ debian_bookworm, alpine_latest ] | |
runs-on: ${{ matrix.platform-runs }} | |
steps: | |
- name: Prepare | |
id: prepare | |
run : | | |
# this instance is running on ubuntu-latest or ubuntu-24.04-arm | |
# dump values for debug | |
echo matrix.platform-run on ${{ matrix.platform-runs }} | |
echo matrix.distribs= ${{ matrix.distribs }} | |
# parse distribs debian_bookworm -> DISTRIB=debian and RELEASE=bookworm | |
# parse distribs ubuntu_24.04 -> DISTRIB=ubuntu and RELEASE=24.04 | |
echo ${{ matrix.distribs }} | awk -F "_" '{print "DISTRIB="$1}' >> ${GITHUB_ENV} | |
echo ${{ matrix.distribs }} | awk -F "_" '{print "RELEASE="$2}' >> ${GITHUB_ENV} | |
# read uname --machine to know the type of cpu amd64 or arm64 | |
# create env OS_PLATFORM=linux/amd64 and PLATFORM=amd64 | |
# create env OS_PLATFORM=linux/arm64 and PLATFORM=arm64 | |
MACHINE=$(uname --machine) | |
echo $MACHINE | |
if [ $MACHINE = 'x86_64' ]; then | |
echo 'OS_PLATFORM=linux/amd64' >> ${GITHUB_ENV} | |
echo 'PLATFORM=amd64' >> ${GITHUB_ENV} | |
fi | |
if [ $MACHINE = 'aarch64' ]; then | |
echo 'OS_PLATFORM=linux/arm64' >> ${GITHUB_ENV} | |
echo 'PLATFORM=arm64' >> ${GITHUB_ENV} | |
fi | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref_name }} | |
- name: create version | |
run: | | |
./mkversion.sh | |
cat version.json | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
registry: https://ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker image | |
id: build | |
uses: docker/build-push-action@v6 | |
with: | |
build-args: | | |
BASE_IMAGE=python | |
TAG=${{ env.DISTRIB }} | |
branch:${{ env.branch }} | |
file: Dockerfile.${{ env.DISTRIB }} | |
provenance: false | |
platforms: ${{ env.OS_PLATFORM }} | |
labels: ${{ steps.meta.outputs.labels }} | |
tags: ghcr.io/${{ env.REGISTRY_IMAGE }}_${{ env.DISTRIB }}_${{ env.RELEASE }}:${{ env.imagetag }}.${{ env.PLATFORM }} | |
outputs: type=image,name-canonical=true,push=true | |
# outputs: type=image,push-by-digest=true,name-canonical=true,push=true | |
merge: | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
strategy: | |
fail-fast: false | |
matrix: | |
distribs: [ debian_bookworm, alpine_latest ] | |
steps: | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
registry: https://ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: merge | |
uses: int128/docker-manifest-create-action@v2 | |
with: | |
# image format pyos:$distrib_$release | |
# amd64 and arm64 | |
# for amd64 and arm64 | |
# ghcr.io/abcdesktopio/pyos:debian_bookworm | |
# ghcr.io/abcdesktopio/pyos:alpine_latest | |
tags: ghcr.io/${{ env.REGISTRY_IMAGE }}:${{ env.imagetag }}.${{ matrix.distribs }} | |
sources: | | |
ghcr.io/${{ env.REGISTRY_IMAGE }}_${{ matrix.distribs }}:${{ env.imagetag }}.arm64 | |
ghcr.io/${{ env.REGISTRY_IMAGE }}_${{ matrix.distribs }}:${{ env.imagetag }}.amd64 |