Skip to content

Commit

Permalink
Build multiarch images
Browse files Browse the repository at this point in the history
Signed-off-by: You-Sheng Yang <[email protected]>
  • Loading branch information
vicamo committed Jun 12, 2024
1 parent e70bc99 commit 64a3809
Showing 1 changed file with 194 additions and 25 deletions.
219 changes: 194 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ on:
branches:
- master
workflow_dispatch:
inputs:
include_eol:
description: 'Build also EOL-ed suites'
type: boolean
default: false
schedule:
- cron: 0 0 * * 0

Expand All @@ -22,42 +27,206 @@ concurrency:
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:
strategy: ${{ steps.generate-jobs.outputs.strategy }}
codenames: ${{ steps.generate-jobs.outputs.codenames }}
steps:
- uses: actions/checkout@v3
- uses: docker-library/bashbrew@HEAD
- 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: |
strategy="$("$BASHBREW_SCRIPTS/github-actions/generate.sh")"
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({
"repository":"vicamo/buildpack-deps",
"distribution":.distribution,
"codename":.codename,
"suite":.suite,
"active":.active,
"platforms":(
.architectures - $disabled_arches |
map(. as $arch |
$platform_map |
map(select(.[0] == $arch))[0][1]) |
join(",")
)
})
')"
EOF="EOF-$RANDOM-$RANDOM-$RANDOM"
echo "strategy<<$EOF" >> "$GITHUB_OUTPUT"
jq <<<"$strategy" . | tee -a "$GITHUB_OUTPUT"
echo "$EOF" >> "$GITHUB_OUTPUT"
if [ -z "${INCLUDE_EOL}" ]; then
codenames="$(echo "${codenames}" | jq -c -M 'map(select(.active))')"
fi
test:
echo "::group::Built JSON(codenames)"
echo "${codenames}" | jq
echo "::endgroup::"
echo "codenames=${codenames}" | tee -a "${GITHUB_OUTPUT}"
build:
needs: generate-jobs
strategy: ${{ fromJson(needs.generate-jobs.outputs.strategy) }}
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.generate-jobs.outputs.codenames) }}
runs-on: ubuntu-latest
env:
REPOSITORY: ${{ matrix.repository }}
DISTRO: ${{ matrix.distribution }}
CODENAME: ${{ matrix.codename }}
SUITE: ${{ matrix.suite }}
PLATFORMS: ${{ matrix.platforms }}
steps:
- uses: actions/checkout@v3
- name: Prepare Environment
run: ${{ matrix.runs.prepare }}
- name: Pull Dependencies
run: ${{ matrix.runs.pull }}
- name: Build ${{ matrix.name }}
run: ${{ matrix.runs.build }}
- name: History ${{ matrix.name }}
run: ${{ matrix.runs.history }}
- name: Test ${{ matrix.name }}
run: ${{ matrix.runs.test }}
- name: '"docker images"'
run: ${{ matrix.runs.images }}
- name: Set up QEMU
run: |
echo "deb http://archive.ubuntu.com/ubuntu/ devel main universe" | \
sudo tee /etc/apt/sources.list.d/devel.list
sudo apt-get update -q
sudo apt-get install -yq binfmt-support qemu-user-static systemd
ls -al /proc/sys/fs/binfmt_misc
- name: Setup containerd image store
run: |
echo "::group::docker image prune"
docker image prune --all --force
echo "::endgroup::"
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::vicamo/${DISTRO}:${CODENAME}"
docker pull --platform "${platform}" "vicamo/${DISTRO}:${CODENAME}" || continue
echo "::endgroup::"
available+=("${platform}")
./versions.sh "${DISTRO}:${CODENAME}"
./apply-templates.sh "${DISTRO}:${CODENAME}"
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}")
done

0 comments on commit 64a3809

Please sign in to comment.