Skip to content

Make base images multiarch #47

Make base images multiarch

Make base images multiarch #47

name: 'Build & Push: base-glibc-busybox-bash'
on:
push:
branches:
- main
paths:
- images/base-glibc-busybox-bash/*
- .github/workflows/base-glibc-busybox-bash.yaml
pull_request:
paths:
- images/base-glibc-busybox-bash/*
- .github/workflows/base-glibc-busybox-bash.yaml
jobs:
build:
name: Build & Push
runs-on: ubuntu-22.04
env:
# The base image is not intended to change often and should be used with
# version tags or checksum IDs, but not via "latest".
IMAGE_VERSION: '3.0.0'
IMAGE_NAME: base-glibc-busybox-bash
BUSYBOX_VERSION: '1.32.1'
DEBIAN_VERSION: '10.9'
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: arm64
- name: Calculate tags and labels
id: calculate
run: |
set -xeu
cd 'images/${{ env.IMAGE_NAME }}'
iidfile="$( mktemp )"
buildah bud --layers \
--iidfile="${iidfile}" \
--build-arg=busybox_version="${{ env.BUSYBOX_VERSION }}" \
--build-arg=debian_version="${{ env.DEBIAN_VERSION }}"
image_id="$( cat "${iidfile}" )"
rm "${iidfile}"
container="$( buildah from "${image_id}" )"
run() { buildah run "${container}" "${@}" ; }
deb_list="$( run cat /.deb.lst )"
pkg_list="$( run cat /.pkg.lst )"
glibc="$( run sh -c 'exec "$( find /lib -name libc.so.6 -print -quit )"' | sed '1!d' )"
busybox="$( run busybox | sed '1!d' )"
bash="$( run bash --version | sed '1!d' )"
buildah rm "${container}"
labels="
glibc="${glibc}"
busybox="${busybox}"
deb-list="${deb_list}"
pkg-list="${pkg_list}"
"
glibc_version="$( printf %s "${glibc}" | sed -E 's/.*version ([0-9.]*[0-9]).*/\1/' )"
busybox_version="$( printf %s "${busybox}" | sed -E '1 s/.*v([0-9.]*[0-9]).*/\1/' )"
bash_version="$( printf %s "${bash}" | sed -E 's/.*version ([0-9.]*[0-9]).*/\1/' )"
tags="
${{ env.IMAGE_VERSION }}
${{ env.IMAGE_VERSION }}_${glibc_version}_${busybox_version}_${bash_version}
latest
"
echo "tags=$( echo ${tags} )" >> $GITHUB_OUTPUT
echo "labels=$( echo ${labels} )" >> $GITHUB_OUTPUT
- name: Build multiarch image
id: build
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.IMAGE_NAME }}
tags: ${{ steps.calculate.outputs.tags }}
labels: ${{ steps.calculate.outputs.labels }}
archs: amd64,arm64
build-args: |
busybox_version=${{ env.BUSYBOX_VERSION }}
debian_version=${{ env.DEBIAN_VERSION }}
context: ./images/${{ env.IMAGE_NAME }}
containerfiles: |
./images/${{ env.IMAGE_NAME }}/Dockerfile
- name: Test
run: |
image='${{ steps.build.outputs.image }}'
ids="$(
for tag in ${{ steps.calculate.outputs.tags }} ; do
buildah images --quiet --no-trunc "${image}:${tag}"
done
)"
ids="$( printf %s "${ids}" | sort -u )"
for id in ${ids} ; do
podman history "${id}"
buildah bud \
--build-arg=base="${id}" \
--file=Dockerfile.test \
"images/${image}"
done
buildah rmi --prune || true
- name: Check Tags
run: |
# FIX upstream: Quay.io does not support immutable images currently.
# => Try to use the REST API to check for duplicate tags.
respone="$(
curl -sL -H "Authorization: Bearer ${{ secrets.QUAY_BIOCONDA_TOKEN }}" \
'https://quay.io/api/v1/repository/bioconda/${{ steps.build.outputs.image }}/image'
)"
existing_tags="$(
printf %s "${respone}" \
| jq -r '.images[].tags[]'
)" \
|| {
printf %s\\n \
'Could not get list of image tags.' \
'Does the repository exist on Quay.io?' \
'Quay.io REST API response was:' \
"${respone}"
exit 1
}
for tag in ${{ steps.calculate.outputs.tags }} ; do
if [ \! "${tag}" = latest ] ; then
if printf %s "${existing_tags}" | grep -qxF "${tag}" ; then
printf 'Tag %s already exists!\n' "${tag}"
exit 1
fi
fi
done
- if: ${{ github.ref == 'refs/heads/main' }}
name: Push
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build.outputs.image }}
tags: ${{ steps.calculate.outputs.tags }}
registry: ${{ secrets.QUAY_BIOCONDA_REPO }}
username: ${{ secrets.QUAY_BIOCONDA_USERNAME }}
password: ${{ secrets.QUAY_BIOCONDA_TOKEN }}
- if: ${{ github.ref == 'refs/heads/main' }}
name: Test Pushed
run: |
image='${{ env.IMAGE_NAME }}'
ids="$(
for tag in ${{ steps.calculate.outputs.tags }} ; do
buildah images --quiet --no-trunc "${image}:${tag}"
done
)"
ids="$( printf %s "${ids}" | sort -u )"
for id in ${ids} ; do
podman history "${id}"
buildah bud \
--build-arg=base="${id}" \
--file=Dockerfile.test \
"images/${image}"
done
buildah rmi --prune || true