-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (103 loc) · 4.42 KB
/
build-container-publish-dockerhub.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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