forked from JasonRivers/Docker-Nagios
-
-
Notifications
You must be signed in to change notification settings - Fork 0
156 lines (142 loc) · 6.1 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
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]
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
- name: Set up QEMU
if: "contains(steps.arch_check.outputs.check, 'passed')"
uses: docker/[email protected]
- name: Set up Docker Buildx
if: "contains(steps.arch_check.outputs.check, 'passed')"
uses: docker/[email protected]
with:
install: true
version: latest
driver-opts: image=moby/buildkit:master
- name: Login to docker.io
if: "contains(steps.arch_check.outputs.check, 'passed')"
uses: docker/[email protected]
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/[email protected]
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
continue-on-error: true
if: "contains(steps.arch_check.outputs.check, 'passed')"
id: build_attempt1
uses: docker/[email protected]
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/[email protected]
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to ghcr.io
if: matrix.registry == 'ghcr.io'
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}
- 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 }}
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\//} == master ]]; then
docker buildx imagetools create -t ${IMAGE}:latest ${SOURCE}-linux-amd64 ${SOURCE}-linux-arm64
fi