build multiarch images #38
This file contains 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
name: GitHub CI | |
on: | |
pull_request: | |
branches: | |
- master | |
push: | |
branches: | |
- master | |
workflow_dispatch: | |
inputs: | |
include_eol: | |
description: 'Build also EOL-ed suites' | |
type: boolean | |
default: false | |
schedule: | |
- cron: 0 0 * * 0 | |
defaults: | |
run: | |
shell: 'bash -Eeuo pipefail -x {0}' | |
concurrency: | |
group: ${{ github.ref }} | |
cancel-in-progress: true | |
permissions: | |
contents: read | |
env: | |
INCLUDE_EOL: ${{ inputs.include_eol && 'true' || '' }} | |
DRY_RUN: ${{ github.ref_name != 'master' && 'true' || '' }} | |
jobs: | |
generate-jobs: | |
name: Generate Jobs | |
runs-on: ubuntu-latest | |
outputs: | |
codenames: ${{ steps.generate-jobs.outputs.codenames }} | |
steps: | |
- name: Debian Releases Info | |
id: debian | |
uses: vicamo/actions-library/debian-releases@v1 | |
- name: Ubuntu Releases Info | |
id: ubuntu | |
uses: vicamo/actions-library/ubuntu-releases@v1 | |
- id: generate-jobs | |
name: Generate Jobs | |
env: | |
DEBIAN_JSON: ${{ steps.debian.outputs.json }} | |
UBUNTU_JSON: ${{ steps.ubuntu.outputs.json }} | |
run: | | |
platform_map='[ | |
["amd64", "linux/amd64"], | |
["arm", "linux/arm"], | |
["arm64", "linux/arm64/v8"], | |
["armel", "linux/arm/v5"], | |
["armhf", "linux/arm/v7"], | |
["i386", "linux/386"], | |
["loong64", "linux/loong64"], | |
["mips64el", "linux/mips64le"], | |
["ppc64el", "linux/ppc64le"], | |
["riscv64", "linux/riscv64"], | |
["s390x", "linux/s390x"], | |
["mips", "linux/mips"], | |
["mipsel", "linux/mipsle"], | |
["powerpc", "linux/ppc"], | |
["ppc64", "linux/ppc64"], | |
["s390", "linux/s390"], | |
["sparc", "linux/sparc"], | |
["sparc64", "linux/sparc64"], | |
["x32", "linux/amd64p32"], | |
["alpha", "linux/alpha"], | |
["hppa", "linux/hppa"], | |
["m68k", "linux/m68k"], | |
["sh4", "linux/sh4"] | |
]' | |
disabled_codename='["experimental"]' | |
disabled_arches='["hurd-amd64", "hurd-i386", "ia64", "kfreebsd-amd64", "kfreebsd-i386", "s390", "x32"]' | |
codenames="$(jq -n -c -M \ | |
--argjson debian "${DEBIAN_JSON}" \ | |
--argjson ubuntu "${UBUNTU_JSON}" \ | |
--argjson disabled_codename "${disabled_codename}" \ | |
--argjson disabled_arches "${disabled_arches}" \ | |
--argjson platform_map "${platform_map}" \ | |
'$debian + $ubuntu | | |
map(select(.codename as $c | $disabled_codename | | |
index($c) == null)) | | |
map({ | |
"distribution":.distribution, | |
"codename":.codename, | |
"suite":.suite, | |
"active":.active, | |
"platforms":( | |
.architectures - $disabled_arches | | |
map(. as $arch | | |
$platform_map | | |
map(select(.[0] == $arch))[0][1]) | | |
join(",") | |
), | |
"repository":"vicamo/buildpack-deps" | |
}) | |
')" | |
if [ -z "${INCLUDE_EOL}" ]; then | |
codenames="$(echo "${codenames}" | jq -c -M 'map(select(.active))')" | |
fi | |
echo "::group::Built JSON(codenames)" | |
echo "${codenames}" | jq | |
echo "::endgroup::" | |
echo "codenames=${codenames}" | tee -a "${GITHUB_OUTPUT}" | |
build: | |
needs: generate-jobs | |
strategy: | |
fail-fast: false | |
matrix: | |
include: ${{ fromJson(needs.generate-jobs.outputs.codenames) }} | |
name: ${{ format('{0}/{1}', matrix.distribution, matrix.codename) }} | |
runs-on: ubuntu-latest | |
env: | |
REPOSITORY: ${{ matrix.repository }} | |
DISTRO: ${{ matrix.distribution }} | |
CODENAME: ${{ matrix.codename }} | |
SUITE: ${{ matrix.suite }} | |
PLATFORMS: ${{ matrix.platforms }} | |
steps: | |
- name: Maximize build space | |
uses: easimon/maximize-build-space@master | |
with: | |
remove-dotnet: true | |
remove-android: true | |
remove-haskell: true | |
remove-codeql: true | |
remove-docker-images: true | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Apply templates | |
run: | | |
./versions.sh "${DISTRO}/${CODENAME}" | |
./apply-templates.sh --owner="${REPOSITORY%/*}" "${DISTRO}/${CODENAME}" | |
for flavor in curl scm ""; do | |
echo "::group::${REPOSITORY}:${CODENAME}${flavor:+-${flavor}}" | |
cat ${DISTRO}/${CODENAME}${flavor:+/${flavor}}/Dockerfile | |
echo "::endgroup::" | |
done | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
with: | |
image: vicamo/binfmt:master | |
- name: Setup containerd image store | |
run: | | |
echo "::group::docker daemon config" | |
cat /etc/docker/daemon.json | \ | |
jq '. | .+{"features": {"containerd-snapshotter": true}}' | \ | |
sudo tee /etc/docker/daemon.json.new | |
sudo mv /etc/docker/daemon.json.new /etc/docker/daemon.json | |
echo "::endgroup::" | |
sudo systemctl restart docker | |
echo "::group::docker driver status" | |
docker info -f '{{ .DriverStatus }}' | |
echo "::endgroup::" | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
platforms: ${{ matrix.platforms }} | |
- name: Login to Docker Hub | |
if: ${{ github.ref_name == 'master' }} | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.username }} | |
password: ${{ secrets.password }} | |
- name: Pull base images | |
id: available | |
run: | | |
available=() | |
for platform in $(echo "${PLATFORMS}" | tr ',' ' '); do | |
echo "::group::${DISTRO}:${CODENAME} (${platform})" | |
if docker pull --platform "${platform}" "vicamo/${DISTRO}:${CODENAME}"; then | |
available+=("${platform}") | |
fi | |
echo "::endgroup::" | |
done | |
echo "available=$(IFS=, ; echo "${available[*]}")" | tee -a "${GITHUB_OUTPUT}" | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ matrix.repository }} | |
env: | |
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index | |
- name: Build images | |
run: | | |
load_or_push='--push' | |
[ -z "${DRY_RUN}" ] || load_or_push='--load' | |
manifest_annotations=() | |
index_annotations=() | |
while read -r line; do | |
case "$line" in | |
manifest:*) manifest_annotations+=(--annotation "${line}") ;; | |
index:*) index_annotations+=(--annotation "${line}") ;; | |
esac | |
done <<<"${DOCKER_METADATA_OUTPUT_ANNOTATIONS}" | |
labels=() | |
while read -r line; do | |
labels+=(--label "${line}") | |
done <<<"${DOCKER_METADATA_OUTPUT_LABELS}" | |
for flavor in curl scm ""; do | |
context_dir="${DISTRO}/${CODENAME}${flavor:+/${flavor}}" | |
tags=(--tag "${REPOSITORY}:${CODENAME}${flavor:+-${flavor}}") | |
if [ -n "${SUITE}" ]; then | |
tags+=(--tag "${REPOSITORY}:${SUITE}${flavor:+-${flavor}}") | |
if [ "${SUITE}" = "stable" ]; then | |
tags+=(--tag "${REPOSITORY}:latest-${flavor:+-${flavor}}") | |
fi | |
fi | |
docker buildx build "${load_or_push}" \ | |
--platform ${{ steps.available.outputs.available }} \ | |
"${labels[@]}" "${tags[@]}" "${manifest_annotations[@]}" \ | |
--metadata-file "${context_dir}/docker.metadata" \ | |
"${context_dir}" | |
docker images | |
done |