-
Notifications
You must be signed in to change notification settings - Fork 3
188 lines (181 loc) · 9.88 KB
/
publish.yml
File metadata and controls
188 lines (181 loc) · 9.88 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
name: Publish Docker image
permissions:
contents: read
on:
workflow_dispatch:
release:
types: [published]
jobs:
push_to_registry:
environment:
name: "docker-hub"
url: https://hub.docker.com/r/hickorydns/hickory-dns
name: Push Docker image to Docker hub
runs-on: ${{ matrix.run-on }}
strategy:
fail-fast: false
max-parallel: 4
matrix:
include:
# All non supported by base image are commented
- { platform: "linux/amd64", platform-tag: "amd64", run-on: "ubuntu-22.04", use-qemu: false }
- { platform: "linux/arm64", platform-tag: "arm64", run-on: "ubuntu-22.04-arm", use-qemu: false }
- { platform: "linux/arm/v7", platform-tag: "armv7", run-on: "ubuntu-22.04-arm", use-qemu: true }
- { platform: "linux/arm/v6", platform-tag: "armv6", run-on: "ubuntu-22.04", use-qemu: true }
- { platform: "linux/ppc64le", platform-tag: "ppc64le", run-on: "ubuntu-22.04", use-qemu: true }
- { platform: "linux/s390x", platform-tag: "s390x", run-on: "ubuntu-22.04", use-qemu: true }
- { platform: "linux/riscv64", platform-tag: "riscv64", run-on: "ubuntu-22.04", use-qemu: true }
- { platform: "linux/386", platform-tag: "386", run-on: "ubuntu-22.04", use-qemu: true }
#- { platform: "linux/mips64le", platform-tag: "mips64le", run-on: "ubuntu-22.04", use-qemu: true }
#- { platform: "linux/mips64", platform-tag: "mips64", run-on: "ubuntu-22.04", use-qemu: true }
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to DockerHub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
if: ${{ matrix.use-qemu }}
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push image
run: make build-alpine
env:
DOCKER_BUILDKIT: 1
ACTION: push
PLATFORM: "${{ matrix.platform }}"
IMAGE_TAG: "docker.io/hickorydns/hickory-dns:${{ matrix.platform-tag }}-latest"
# Disable provenance to remove the attestation from the pushed image
# See: https://github.com/docker/buildx/issues/1509
# It makes: docker.io/botsudo/docker-rustpython:<arch>-latest a manifest list
# And docker manifest create does not like that
EXTRA_ARGS: "--provenance=false"
build-and-push-manifest:
name: Build and push the docker hub manifest
runs-on: ubuntu-latest
needs: push_to_registry
environment:
name: "docker-hub"
url: https://hub.docker.com/r/hickorydns/hickory-dns
steps:
- name: Login to DockerHub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Create the manifest
env:
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
docker manifest create docker.io/hickorydns/hickory-dns:latest \
docker.io/hickorydns/hickory-dns:arm64-latest \
docker.io/hickorydns/hickory-dns:amd64-latest \
docker.io/hickorydns/hickory-dns:armv7-latest \
docker.io/hickorydns/hickory-dns:armv6-latest \
docker.io/hickorydns/hickory-dns:ppc64le-latest \
docker.io/hickorydns/hickory-dns:s390x-latest \
docker.io/hickorydns/hickory-dns:riscv64-latest \
docker.io/hickorydns/hickory-dns:386-latest
- name: Push the manifest
env:
DOCKER_CLI_EXPERIMENTAL: enabled
run: docker manifest push docker.io/hickorydns/hickory-dns:latest
- name: Inspect the manifest
run: docker manifest inspect docker.io/hickorydns/hickory-dns:latest >> $GITHUB_STEP_SUMMARY
- name: Checkout repository
uses: actions/checkout@v4
- name: Test docker image
run: make test-alpine
build-and-push-version-manifest:
name: Build and push the docker hub manifest for the version
runs-on: ubuntu-latest
needs:
- push_to_registry
# To ensure the lastest tag exists
- build-and-push-manifest
environment:
name: "docker-hub"
url: https://hub.docker.com/r/hickorydns/hickory-dns
steps:
- name: Login to DockerHub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Pull the image
run: docker pull docker.io/hickorydns/hickory-dns:latest
- name: Get the version
run: echo "buildVersion=$(docker image inspect docker.io/hickorydns/hickory-dns:latest -f '{{ (index .Config.Labels "org.opencontainers.image.version")}}')" >> "$GITHUB_ENV"
- name: Create the manifest for the version ${{ env.buildVersion }}
env:
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
docker manifest create docker.io/hickorydns/hickory-dns:${{ env.buildVersion }} \
docker.io/hickorydns/hickory-dns:arm64-latest \
docker.io/hickorydns/hickory-dns:amd64-latest \
docker.io/hickorydns/hickory-dns:armv7-latest \
docker.io/hickorydns/hickory-dns:armv6-latest \
docker.io/hickorydns/hickory-dns:ppc64le-latest \
docker.io/hickorydns/hickory-dns:s390x-latest \
docker.io/hickorydns/hickory-dns:riscv64-latest \
docker.io/hickorydns/hickory-dns:386-latest
- name: Push the manifest for the version ${{ env.buildVersion }}
env:
DOCKER_CLI_EXPERIMENTAL: enabled
run: docker manifest push docker.io/hickorydns/hickory-dns:${{ env.buildVersion }}
- name: Inspect the manifest for the version ${{ env.buildVersion }}
run: docker manifest inspect docker.io/hickorydns/hickory-dns:${{ env.buildVersion }} >> $GITHUB_STEP_SUMMARY
tags-cleanup:
runs-on: ubuntu-latest
needs:
- build-and-push-manifest
- build-and-push-version-manifest
environment:
name: "docker-hub"
url: https://hub.docker.com/r/hickorydns/hickory-dns
name: Cleanup DockerHub build tags
steps:
- name: Install Docker hub-tool
run: |
curl -sL https://github.com/docker/hub-tool/releases/download/v0.4.5/hub-tool-linux-amd64.tar.gz -o hub-tool-linux.tar.gz
tar --strip-components=1 -xzf ./hub-tool-linux.tar.gz
./hub-tool --version
- name: Login to DockerHub using hub-tool
run: |
set -eu
# Fool the login command (https://github.com/docker/hub-tool/pull/198)
# ./hub-tool login
# Token commands thank to https://stackoverflow.com/a/59334315/5155484
HUB_TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d "{\"username\": \"$DOCKER_USERNAME\", \"password\": \"$DOCKER_PASSWORD\"}" https://hub.docker.com/v2/users/login/ | jq -r .token)
USERNAME="$(printf '%s:' "$DOCKER_USERNAME" | base64 -w0)"
USER_PASS="$(printf '%s:%s' "$DOCKER_USERNAME" "$DOCKER_PASSWORD" | base64 -w0)"
mkdir -p ~/.docker/
printf '{"auths": {"hub-tool": {"auth": "%s"}, "hub-tool-refresh-token": {"auth": "%s"}, "hub-tool-token": { "auth": "%s", "identitytoken": "%s"}}}' \
"$USER_PASS" "$USERNAME" \
"$USERNAME" "$HUB_TOKEN" \
> ~/.docker/config.json
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_HUB_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Remove DockerHub tags via hub-tool
run: |
./hub-tool tag rm --verbose --force docker.io/hickorydns/hickory-dns:arm64-latest || true
./hub-tool tag rm --verbose --force docker.io/hickorydns/hickory-dns:amd64-latest || true
./hub-tool tag rm --verbose --force docker.io/hickorydns/hickory-dns:armv7-latest || true
./hub-tool tag rm --verbose --force docker.io/hickorydns/hickory-dns:armv6-latest || true
./hub-tool tag rm --verbose --force docker.io/hickorydns/hickory-dns:ppc64le-latest || true
./hub-tool tag rm --verbose --force docker.io/hickorydns/hickory-dns:s390x-latest || true
./hub-tool tag rm --verbose --force docker.io/hickorydns/hickory-dns:riscv64-latest || true
./hub-tool tag rm --verbose --force docker.io/hickorydns/hickory-dns:386-latest || true
./hub-tool tag ls --verbose docker.io/hickorydns/hickory-dns
- name: Logout hub-tool
if: always()
run: rm ~/.docker/config.json