-
Notifications
You must be signed in to change notification settings - Fork 15
209 lines (177 loc) · 6.68 KB
/
Copy pathdocker-publish.yml
File metadata and controls
209 lines (177 loc) · 6.68 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: Docker
on:
workflow_dispatch:
push:
# Publish `main` as Docker `edge` image.
branches:
- main
# Publish `v1.2.3` tags as releases.
tags:
- v*
# Run tests for any PRs.
pull_request:
env:
IMAGE_NAME: keepalived
IMAGE_TITLE: keepalived
IMAGE_DESCRIPTION: Docker container for keepalived
APP_VERSION: "2.3.4"
jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
submodules: recursive
- name: Set up Docker Buildx
id: buildx_test
uses: docker/setup-buildx-action@v4
- name: Cache Docker layers
uses: actions/cache@v5
with:
path: /tmp/.test-buildx-cache
key: ${{ runner.os }}-test-buildx-${{ env.APP_VERSION }}
restore-keys: |
${{ runner.os }}-test-buildx-${{ env.APP_VERSION }}
${{ runner.os }}-test-buildx-
- name: Test build
id: docker_build_test
uses: docker/build-push-action@v7
with:
builder: ${{ steps.buildx_test.outputs.name }}
context: .
platforms: linux/amd64
push: false
load: true
tags: keepalived:test-build
cache-from: type=local,src=/tmp/.test-buildx-cache
cache-to: type=local,dest=/tmp/.test-buildx-cache-new
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.test-buildx-cache
mv /tmp/.test-buildx-cache-new /tmp/.test-buildx-cache
- name: Run BATS tests
run: |
docker run --rm --name keepalived-test \
--cap-add=NET_ADMIN \
--entrypoint /test/bats/bin/bats \
-w /test \
-v "$PWD/test:/test" \
keepalived:test-build .
# Build images.
build:
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ github.ref }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v4
- name: Login to DockerHub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v6
with:
images: |
${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,enable=${{ github.ref == 'refs/heads/main' }},prefix=edge-,format=long
type=sha,enable=${{ github.ref == 'refs/heads/main' }},prefix=edge-,format=short
type=edge,branch=main
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
labels: |
org.opencontainers.image.title=${{ env.IMAGE_TITLE }}
org.opencontainers.image.description=${{ env.IMAGE_DESCRIPTION }}
org.opencontainers.image.vendor=${{ github.repository_owner }}
- name: Cache Docker layers
uses: actions/cache@v5
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ env.APP_VERSION }}
restore-keys: |
${{ runner.os }}-buildx-${{ env.APP_VERSION }}
${{ runner.os }}-buildx-
- name: Build and push
id: docker_build
uses: docker/build-push-action@v7
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Checkout main
uses: actions/checkout@v6
with:
ref: main
- name: Update README.md with latest tags
if: startsWith(github.ref, 'refs/tags')
run: |
# Build tags for README.md
echo '${{ steps.meta.outputs.json }}' | tee meta.json
README_TAGS="$(jq -r -e '.tags | map(. | sub(".+:(?<tag>.+)"; "`\(.tag)`")) | unique | reverse | join(", ")' meta.json)"
echo "Updating supported tags in readme with ${README_TAGS}"
# Replace supported latest tags in README.md
if [ -n "${README_TAGS:-}" ] && [ "${README_TAGS}" != "null" ]; then
sed -i '/- `latest`.*<!-- latest tag -->/c- '"${README_TAGS}"' <!-- latest tag -->' README.md
fi
rm -rf meta.json
- name: Update README.md with edge tags
if: startsWith(github.ref, 'refs/heads')
run: |
# Build tags for README.md
echo '${{ steps.meta.outputs.json }}' | tee meta.json
README_TAGS="$(jq -r -e '.tags | map(. | sub(".+:(?<tag>.+)"; "`\(.tag)`")) | unique | reverse | join(", ")' meta.json)"
echo "Updating supported tags in readme with ${README_TAGS}"
# Replace supported latest tags in README.md
if [ -n "${README_TAGS:-}" ] && [ "${README_TAGS}" != "null" ]; then
sed -i '/- `edge`.*<!-- edge tag -->/c- '"${README_TAGS}"' <!-- edge tag -->' README.md
fi
rm -rf meta.json
- name: Check for modified files
id: git-check
run: echo modified=$([ -z "`git status --porcelain`" ] && echo "false" || echo "true") >> $GITHUB_OUTPUT
- name: Commit updated README.md
if: steps.git-check.outputs.modified == 'true'
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add README.md
git commit -m "docs(README): update supported tags [skip ci]"
git push