forked from JasonRivers/Docker-Nagios
-
-
Notifications
You must be signed in to change notification settings - Fork 0
251 lines (235 loc) · 10.7 KB
/
build.yml
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
name: build
on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop
jobs:
build:
if: "!contains(github.event.head_commit.message, 'skip ci')"
runs-on: ubuntu-24.04
strategy:
matrix:
#architecture: [linux-amd64, linux-arm64, linux-arm-v7]
architecture: [linux-amd64, linux-arm64]
outputs:
version: ${{ steps.prep.outputs.version }}
branch: ${{ steps.prep.outputs.branch }}
time: ${{ steps.vars.outputs.time }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check if architecture exists
id: arch_check
run: |
(test -f Dockerfile.${{ matrix.architecture }} && echo "check=passed" >> $GITHUB_OUTPUT) || echo "check=failed" >> $GITHUB_OUTPUT
# Workaround for Cargo issue: https://github.com/rust-lang/cargo/issues/8719
#- name: Set Swap Space
# uses: pierotofy/set-swap-space@v1.0
# with:
# swap-size-gb: 10
#- run: |
# sudo mkdir -p /var/lib/docker
# sudo mount -t tmpfs -o size=10G none /var/lib/docker
# sudo systemctl restart docker
- name: Set up QEMU
if: "contains(steps.arch_check.outputs.check, 'passed')"
uses: docker/setup-qemu-action@v3.0.0
- name: Set up Docker Buildx
if: "contains(steps.arch_check.outputs.check, 'passed')"
uses: docker/setup-buildx-action@v3.3.0
with:
install: true
version: latest
# Fix for https://github.com/docker/buildx/issues/1509
#driver-opts: image=moby/buildkit:v0.10.5
driver-opts: image=moby/buildkit:master
- name: Login to docker.io
if: "contains(steps.arch_check.outputs.check, 'passed')"
uses: docker/login-action@v3.2.0
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to ghcr.io
if: "contains(steps.arch_check.outputs.check, 'passed')"
uses: docker/login-action@v3.2.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Prepare
if: "contains(steps.arch_check.outputs.check, 'passed')"
id: prep
run: |
{
ARCHITECTURE=${{ matrix.architecture }}
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
echo "title=$(echo ${GITHUB_REPOSITORY}:${GITHUB_REF//refs\/heads\//} | tr '[:upper:]' '[:lower:]')"
echo "revision=${GITHUB_SHA}"
echo "source=$(echo ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/tree/${GITHUB_REF//refs\/heads\//} | tr '[:upper:]' '[:lower:]')"
echo "vendor=${{ github.repository_owner }}"
echo "url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/blob/master/README.md"
echo "platform=${ARCHITECTURE//-/\/}"
echo "cache=$(echo ${GITHUB_REPOSITORY}:${GITHUB_REF//refs\/heads\//}-cache-${{ matrix.architecture }} | tr '[:upper:]' '[:lower:]')"
echo "tag=$(echo ${GITHUB_REPOSITORY}:${GITHUB_REF//refs\/heads\//}-${GITHUB_SHA:0:7}-${GITHUB_RUN_NUMBER}-${{ matrix.architecture }} | tr '[:upper:]' '[:lower:]' | sed s/docker-//)"
} >> $GITHUB_OUTPUT
VERSION=$(grep nagiosVersion Dockerfile.${{ matrix.architecture }} | awk -F= '{print $2}' | tr -d '" \\')
if [[ -z ${VERSION} ]]; then
VERSION=$(date --utc --date=@$(git show -s --format=%ct $(git rev-parse --short HEAD)) +'%Y%m%d%H%M%S')
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
BRANCH="${GITHUB_REF//refs\/heads\//}"
if [[ -n ${BRANCH} ]]; then
echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
fi
echo $GITHUB_OUTPUT
#- name: Build and push - Attempt 1
- name: Build and push
continue-on-error: true
if: "contains(steps.arch_check.outputs.check, 'passed')"
id: build_attempt1
uses: docker/build-push-action@v5.4.0
with:
push: true
platforms: ${{ steps.prep.outputs.platform }}
file: ./Dockerfile.${{ matrix.architecture }}
cache-from: docker.io/${{ steps.prep.outputs.cache }}
cache-to: docker.io/${{ steps.prep.outputs.cache }}
tags: |
docker.io/${{ steps.prep.outputs.tag }}
ghcr.io/${{ steps.prep.outputs.tag }}
labels: |
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.title=${{ steps.prep.outputs.title }}
org.opencontainers.image.revision=${{ steps.prep.outputs.revision }}
org.opencontainers.image.source=${{ steps.prep.outputs.source }}
org.opencontainers.image.vendor=${{ steps.prep.outputs.vendor }}
org.opencontainers.image.url=${{ steps.prep.outputs.url }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
build-args: |
GITHUB_TOKEN=${{ secrets.GHCR_TOKEN }}
BUILD_ARCHITECTURE=${{ matrix.architecture }}
${{ steps.prep.outputs.build-args }}
# - name: Sleep
# if: (steps.build_attempt1.outcome == 'failure')
# run: |
# sleep 30
#
# - name: Build and push - Attempt 2
# if: (steps.build_attempt1.outcome == 'failure')
# uses: docker/build-push-action@v5.4.0
# with:
# push: true
# platforms: ${{ steps.prep.outputs.platform }}
# file: ./Dockerfile.${{ matrix.architecture }}
# cache-from: docker.io/${{ steps.prep.outputs.cache }}
# cache-to: docker.io/${{ steps.prep.outputs.cache }}
# tags: |
# docker.io/${{ steps.prep.outputs.tag }}
# ghcr.io/${{ steps.prep.outputs.tag }}
# labels: |
# org.opencontainers.image.created=${{ steps.prep.outputs.created }}
# org.opencontainers.image.title=${{ steps.prep.outputs.title }}
# org.opencontainers.image.revision=${{ steps.prep.outputs.revision }}
# org.opencontainers.image.source=${{ steps.prep.outputs.source }}
# org.opencontainers.image.vendor=${{ steps.prep.outputs.vendor }}
# org.opencontainers.image.url=${{ steps.prep.outputs.url }}
# org.opencontainers.image.version=${{ steps.prep.outputs.version }}
# build-args: |
# GITHUB_TOKEN=${{ secrets.GHCR_TOKEN }}
# BUILD_ARCHITECTURE=${{ matrix.architecture }}
# ${{ steps.prep.outputs.build-args }}
publish:
runs-on: ubuntu-24.04
strategy:
matrix:
registry: [docker.io, ghcr.io]
needs: [build]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to docker.io
if: matrix.registry == 'docker.io'
uses: docker/login-action@v3.2.0
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to ghcr.io
if: matrix.registry == 'ghcr.io'
uses: docker/login-action@v3.2.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}
#- name: Create manifests - Attempt 1
- name: Create manifests
continue-on-error: true
id: manifest_attempt1
env:
DOCKER_CLI_EXPERIMENTAL: enabled
#run: |
# IMAGE=${{ matrix.registry }}/$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]' | sed s/docker-//)
# TAG=${{ needs.build.outputs.branch }}
# SOURCE=${IMAGE}:${TAG}-${GITHUB_SHA:0:7}-${GITHUB_RUN_NUMBER}
# VERSION=${{ needs.build.outputs.version }}
# BRANCH=${{ needs.build.outputs.branch }}
# [[ -f Dockerfile.linux-amd64 ]] && AMD64=${SOURCE}-linux-amd64
# [[ -f Dockerfile.linux-arm64 ]] && ARM64=${SOURCE}-linux-arm64
# docker manifest create ${IMAGE}:${TAG} ${AMD64} ${ARM64}
# docker manifest push ${IMAGE}:${TAG}
# docker manifest create ${IMAGE}:${TAG}-${VERSION} ${AMD64} ${ARM64}
# docker manifest push ${IMAGE}:${TAG}-${VERSION}
# docker manifest create ${IMAGE}:${TAG}-${VERSION} ${AMD64} ${ARM64}
# docker manifest push ${IMAGE}:${TAG}-${VERSION}
# if [[ ${BRANCH} == master ]]; then
# docker manifest create ${IMAGE}:latest ${AMD64} ${ARM64}
# docker manifest push ${IMAGE}:latest
# fi
run: |
IMAGE=${{ matrix.registry }}/$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]' | sed s/docker-//)
TAG=${{ needs.build.outputs.branch }}
SOURCE=${IMAGE}:${TAG}
VERSION=${{ needs.build.outputs.version }}
docker buildx imagetools create -t ${IMAGE}:${TAG} ${SOURCE}-linux-amd64 ${SOURCE}-linux-arm64
docker buildx imagetools create -t ${IMAGE}:${TAG}-${VERSION} ${SOURCE}-linux-amd64 ${SOURCE}-linux-arm64
if [[ ${GITHUB_REF//refs\/heads\//} == main ]]; then
docker buildx imagetools create -t ${IMAGE}:latest ${SOURCE}-linux-amd64 ${SOURCE}-linux-arm64
fi
#
#- name: Sleep
# if: (steps.manifest_attempt1.outcome == 'failure')
# run: |
# sleep 30
#
#- name: Create manifests - Attempt 2
# if: (steps.manifest_attempt1.outcome == 'failure')
# env:
# DOCKER_CLI_EXPERIMENTAL: enabled
# run: |
# IMAGE=${{ matrix.registry }}/$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]' | sed s/docker-//)
# TAG=${{ needs.build.outputs.branch }}
# SOURCE=${IMAGE}:${TAG}-${GITHUB_SHA:0:7}-${GITHUB_RUN_NUMBER}
# VERSION=${{ needs.build.outputs.version }}
# BRANCH=${{ needs.build.outputs.branch }}
# [[ -f Dockerfile.linux-amd64 ]] && AMD64=${SOURCE}-linux-amd64
# [[ -f Dockerfile.linux-arm64 ]] && ARM64=${SOURCE}-linux-arm64
# docker manifest rm ${IMAGE}:${TAG} || true
# docker manifest create ${IMAGE}:${TAG} ${AMD64} ${ARM64}
# docker manifest push ${IMAGE}:${TAG}
# docker manifest rm ${IMAGE}:${TAG}-${VERSION} || true
# docker manifest create ${IMAGE}:${TAG}-${VERSION} ${AMD64} ${ARM64}
# docker manifest push ${IMAGE}:${TAG}-${VERSION}
# docker manifest rm ${IMAGE}:${TAG}-${VERSION} || true
# docker manifest create ${IMAGE}:${TAG}-${VERSION} ${AMD64} ${ARM64}
# docker manifest push ${IMAGE}:${TAG}-${VERSION}
# if [[ ${BRANCH} == master ]]; then
# docker manifest rm ${IMAGE}:latest || true
# docker manifest create ${IMAGE}:latest ${AMD64} ${ARM64}
# docker manifest push ${IMAGE}:latest
# fi