Update Alpine image and system packages #35
Workflow file for this run
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: Build the container image and push it to Docker Hub | |
on: | |
push: | |
tags: | |
- 'v[0-9]+.' | |
- 'v[0-9]+.[0-9]+' | |
- 'v[0-9]+.[0-9]+.[0-9]+' | |
env: | |
IMAGE_NAME: ${{ secrets.DOCKER_HUB_USERNAME }}/caddy | |
CWD: ${{ github.workspace }} | |
UBUNTU_VERSION: 22.04 | |
jobs: | |
setup: | |
name: Download the code and QEMU bineries | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Download code from GitHub | |
uses: actions/checkout@v4 | |
- name: Save the tag that triggered the workflow to an env file | |
run: | | |
echo "GH_TAG=${GITHUB_REF/refs\/tags\//}" >> ${CWD}/GH_TAG.env && cat ${CWD}/GH_TAG.env | |
- name: Install QEMU static binaries | |
run: | | |
sudo apt-get update && sudo apt-get install -y qemu-user-static | |
- name: Copy QEMU binaries into workspace folder | |
run: | | |
cp /usr/bin/qemu-aarch64-static /usr/bin/qemu-arm-static ${CWD} | |
- name: Upload repo folder artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: repo-folder | |
path: ${{ env.CWD }} | |
retention-days: 1 | |
build-push: | |
name: Build the container image and push to Docker Hub | |
strategy: | |
fail-fast: false | |
matrix: | |
container_arch: [aarch64, amd64, armv7] | |
runs-on: ubuntu-22.04 | |
needs: setup | |
steps: | |
- name: Download repo folder artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: repo-folder | |
path: ${{ env.CWD }} | |
- name: Load version tag into env var | |
run: | | |
cat ${CWD}/GH_TAG.env >> $GITHUB_ENV | |
- name: Run QEMU registration if target arch differs from host | |
if: ${{ matrix.container_arch != 'amd64' }} | |
run: | | |
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes | |
- name: Build and tag the container image | |
run: | | |
docker build -f ${CWD}/Containerfile.${{ matrix.container_arch }} -t ${IMAGE_NAME}:${{ env.GH_TAG }}-${{ matrix.container_arch }} --build-arg ARCH=${{ matrix.container_arch }} ${CWD} | |
- name: Login to Docker Hub | |
run: | | |
echo ${{ secrets.DOCKER_HUB_TOKEN }} | docker login --username ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin | |
- name: Push the container image | |
run: | | |
docker push ${IMAGE_NAME}:${{ env.GH_TAG }}-${{ matrix.container_arch }} | |
- name: Logout from Docker Hub | |
run: | | |
docker logout | |
manifest-tag: | |
name: Create a container manifest to merge architecture tags and apply latest tag | |
runs-on: ubuntu-22.04 | |
needs: build-push | |
steps: | |
- name: Download repo folder artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: repo-folder | |
path: ${{ env.CWD }} | |
- name: Load version tag into env var | |
run: | | |
cat ${CWD}/GH_TAG.env >> $GITHUB_ENV | |
- name: Set up Kubic repo and install Podman | |
run: | | |
export KEY_URL='https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_${{ env.UBUNTU_VERSION }}/Release.key' && \ | |
export SOURCES_URL='https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_${{ env.UBUNTU_VERSION }}/' && \ | |
sudo echo "deb $SOURCES_URL /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:unstable.list && \ | |
sudo curl -fsSL $KEY_URL | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/devel_kubic_libcontainers_unstable.gpg > /dev/null && \ | |
sudo apt update && sudo apt install podman | |
- name: Create the image manifest and apply latest tag | |
run: | | |
podman manifest create ${IMAGE_NAME}:${{ env.GH_TAG }} \ | |
--amend ${IMAGE_NAME}:${{ env.GH_TAG }}-amd64 \ | |
--amend ${IMAGE_NAME}:${{ env.GH_TAG }}-armv7 \ | |
--amend ${IMAGE_NAME}:${{ env.GH_TAG }}-aarch64 && \ | |
podman tag ${IMAGE_NAME}:${{ env.GH_TAG }} ${IMAGE_NAME}:latest | |
- name: Login to Docker Hub | |
run: | | |
echo ${{ secrets.DOCKER_HUB_TOKEN }} | podman login docker.io --username ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin | |
- name: Push the manifest and the latest tag | |
run: | | |
podman manifest push localhost/${IMAGE_NAME}:${{ env.GH_TAG }} docker://docker.io/${IMAGE_NAME}:${{ env.GH_TAG }} && \ | |
podman manifest push localhost/${IMAGE_NAME}:latest docker://docker.io/${IMAGE_NAME}:latest | |
- name: Logout from Docker Hub | |
run: | | |
podman logout |