-
Notifications
You must be signed in to change notification settings - Fork 75
251 lines (234 loc) · 11.5 KB
/
build-docker-image.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 and Publish Releases to Hub
on:
schedule:
- cron: "0 23 * * *"
push:
tags:
- "*"
branches:
- main
paths:
- "docker-jans-**/**"
- "!**.md"
pull_request:
branches:
- main
paths:
- "docker-jans-**/**"
- "!docker-jans-**/CHANGELOG.md"
- "!docker-jans-**/version.txt"
- "!**.md"
workflow_dispatch:
inputs:
services:
description: 'One or set of the docker images. Format as following: "docker-jans-auth-server docker-jans-certmanager docker-jans-config-api docker-jans-configurator docker-jans-fido2 docker-jans-persistence-loader docker-jans-scim docker-jans-monolith docker-jans-loadtesting-jmeter docker-jans-link docker-jans-casa docker-jans-all-in-one docker-jans-saml docker-jans-keycloak-link docker-jans-kc-scheduler cedarling-flask-sidecar"'
required: true
default: 'docker-jans-auth-server docker-jans-certmanager docker-jans-config-api docker-jans-configurator docker-jans-fido2 docker-jans-persistence-loader docker-jans-scim docker-jans-monolith docker-jans-loadtesting-jmeter docker-jans-link docker-jans-casa docker-jans-all-in-one docker-jans-saml docker-jans-keycloak-link docker-jans-kc-scheduler cedarling-flask-sidecar'
cn_version:
description: 'The war version to build the image off'
required: false
default: ''
image_tag:
description: 'The manual image tag to post'
required: false
default: ''
tags:
description: 'Tags'
required: false
permissions:
contents: read
jobs:
docker:
permissions:
packages: write
id-token: write
runs-on: ubuntu-latest
strategy:
max-parallel: 8
matrix:
docker-images: ["auth-server", "certmanager", "config-api", "configurator", "fido2", "persistence-loader", "scim", "monolith", "loadtesting-jmeter", "link", "casa", "all-in-one", "saml", "keycloak-link", "kc-scheduler", "cedarling-flask-sidecar"]
steps:
- name: Harden Runner
uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1
with:
egress-policy: audit
- name: Install Cosign
uses: sigstore/[email protected]
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0
sparse-checkout: |
docker-jans-${{ matrix.docker-images }}
automation
demos
jans-cedarling
- name: Check docker directories that changed
id: build_docker_image
run: |
BUILD=true
DEFAULT_ALL=${{ github.event.inputs.services }}
if [ -z "$DEFAULT_ALL" ]
then
DEFAULT_ALL="docker-jans-auth-server docker-jans-certmanager docker-jans-config-api docker-jans-configurator docker-jans-fido2 docker-jans-persistence-loader docker-jans-scim docker-jans-monolith docker-jans-loadtesting-jmeter docker-jans-link docker-jans-casa docker-jans-all-in-one docker-jans-saml docker-jans-keycloak-link docker-jans-kc-scheduler cedarling-flask-sidecar"
else
echo "$DEFAULT_ALL"
fi
# Detect actual docker folders that changed if error arises default to all images
pull_number=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
DIRECTORIES_CHANGED=$(gh pr view $pull_number --json files --jq '.files.[].path' | cut -d/ -f1 | sort -u | grep "docker-jans" || echo "$DEFAULT_ALL")
if [[ "$DIRECTORIES_CHANGED" =~ "${{ matrix.docker-images }}" ]]; then
echo "A change in this images directory has occurred"
echo "build=${BUILD}" >> $GITHUB_OUTPUT
fi
- name: Install dependencies
if: steps.build_docker_image.outputs.build || github.event_name == 'tags'
run: |
sudo apt-get update
sudo python3 -m pip install --upgrade pip
sudo pip3 install setuptools --upgrade
sudo pip3 install -r ./automation/requirements.txt
sudo apt-get update
#- uses: actions/delete-package-versions@v5
# continue-on-error: true
# with:
# package-name: jans/${{ matrix.docker-images }}
# package-type: container
# min-versions-to-keep: 1000
# token: ${{ secrets.GITHUB_TOKEN }}
# delete-only-untagged-versions: true
- name: Prepare
if: steps.build_docker_image.outputs.build || github.event_name == 'tags'
id: prep
run: |
REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
DOCKER_FILE_LOCATION=./docker-jans-${{ matrix.docker-images }}
if [[ "loadtesting-jmeter" =~ "${{ matrix.docker-images }}" ]]; then
DOCKER_FILE_LOCATION=./demos/benchmarking/docker-jans-loadtesting-jmeter
fi
if [[ "cedarling-flask-sidecar" =~ "${{ matrix.docker-images }}" ]]; then
DOCKER_FILE_LOCATION=./jans-cedarling/flask-sidecar
fi
MAIN_VERSION=$(python3 -c "from dockerfile_parse import DockerfileParser ; dfparser = DockerfileParser('$DOCKER_FILE_LOCATION') ; print(dfparser.labels['org.opencontainers.image.version'])")
DOCKER_IMAGE=ghcr.io/$REPOSITORY/${{ matrix.docker-images }}
VERSION=${MAIN_VERSION}
BUILD=true
if [[ $GITHUB_REF == refs/tags/docker-jans-${{ matrix.docker-images }}-* ]]; then
VERSION=${GITHUB_REF#refs/tags/docker-jans-${{ matrix.docker-images }}-v}
elif [[ $GITHUB_REF == refs/tags/* ]]; then
echo "A tag not matching the image triggered the build. I will not continue."
BUILD=""
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\_[a-b]{1}[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:${MAIN_VERSION}"
fi
# If the user passed a manual image tag to build a custom manual image
MANUAL_IMAGE_TAG=${{ github.event.inputs.image_tag }}
if [ ! -z "$MANUAL_IMAGE_TAG" ]
then
TAGS="$TAGS,${DOCKER_IMAGE}:${MANUAL_IMAGE_TAG}"
VERSION=$MANUAL_IMAGE_TAG
echo "Manual image tag has been inputted by the user"
else
echo "$TAGS"
fi
# If the user passed a war version to build off ,change this war version.
CN_VERSION=${{ github.event.inputs.cn_version }}
if [ ! -z "$CN_VERSION" ]
then
python3 -c "from dockerfile_parse import DockerfileParser ; dfparser = DockerfileParser('./docker-jans-${{ matrix.docker-images }}') ; dfparser.envs['CN_VERSION'] = '${{ github.event.inputs.cn_version }}'"
echo "War version has been modified."
else
echo "$CN_VERSION"
fi
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "build=${BUILD}" >> $GITHUB_OUTPUT
echo "dockerfilelocation=${DOCKER_FILE_LOCATION}" >> $GITHUB_OUTPUT
# wait for all images in DEFAULT_ALL to be built before building the all-in-one image as it depends on all other images
if [[ "docker-jans-all-in-one" =~ "${{ matrix.docker-images }}" ]]; then
if [[ ${{ github.event_name != 'pull_request' }} ]]; then
TEMP_IMG="auth-server certmanager config-api configurator fido2 persistence-loader scim monolith loadtesting-jmeter link casa saml keycloak-link kc-scheduler"
for i in $TEMP_IMG; do
echo "Waiting for $i to be built"
sleep 30
done
fi
fi
# UPDATE BUILD DATES INSIDE THE DOCKERFILE BEFORE BUILDING THE DEV IMAGES TRIGGERED BY JENKINS
- name: Setup Python 3.7
if: github.event_name == 'workflow_dispatch' && ${{ matrix.docker-images }} != 'loadtesting-jmeter'
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: 3.7
- name: Install Python dependencies
if: github.event_name == 'workflow_dispatch' && ${{ matrix.docker-images }} != 'loadtesting-jmeter'
run: |
sudo apt-get update
sudo python3 -m pip install --upgrade pip
sudo pip3 install setuptools --upgrade
sudo pip3 install -r ./automation/requirements.txt
sudo apt-get update
sudo apt-get install jq
- name: Update Build date in Dockerfile
if: github.event_name == 'workflow_dispatch' && ${{ matrix.docker-images }} != 'loadtesting-jmeter'
id: update_build_date_in_dockerfile
run: |
sudo python3 ./automation/auto_update_build_date.py
#END UPDATE BUILD DATES INSIDE THE DOCKERFILE BEFORE BUILDING THE DEV IMAGES TRIGGERED BY JENKINS
- name: Set up QEMU
if: steps.build_docker_image.outputs.build && steps.prep.outputs.build
uses: docker/setup-qemu-action@5306bad0baa6b616b9934712d4eba8da2112606d # master
with:
image: tonistiigi/binfmt:master
platforms: all
- name: Set up Docker Buildx
if: steps.build_docker_image.outputs.build && steps.prep.outputs.build
id: buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
- name: Login to ghcr
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
if: steps.build_docker_image.outputs.build && steps.prep.outputs.build
id: docker_build
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
with:
builder: ${{ steps.buildx.outputs.name }}
context: ${{ steps.prep.outputs.dockerfilelocation }}
file: ${{ steps.prep.outputs.dockerfilelocation }}/Dockerfile
sbom: true
provenance: true
#target: prod
# add to platforms comma seperated linux/ppc64leL Issue: py3-grpcio
# add to platforms comma seperated linux/386 : Issue: openjdk11-jre-headless alpine package not
# add to platforms comma seperated ,linux/arm/v6 : Issue: openjdk11-jre-headless alpine package not found
# add to platforms comma seperated ,linux/arm/v7 : Issue: openjdk11-jre-headless alpine package not found
# add to platforms comma seperated ,linux/s390x: All images with openjdk hav an issue with linux/s390x Problematic frame: J 6 c1 java.lang.String.hashCode()I [email protected] (49 bytes) : Issue: openjdk11-jre-headles
# add to platforms comma seperated ,linux/arm64: : PyDev issue only
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
- name: Image digest
if: steps.build_docker_image.outputs.build && steps.prep.outputs.build
run: echo ${{ steps.docker_build.outputs.digest }}
- name: Sign the images with GitHub OIDC Token
if: steps.build_docker_image.outputs.build && steps.prep.outputs.build
env:
DIGEST: ${{ steps.docker_build.outputs.digest }}
TAGS: ${{ steps.prep.outputs.tags }}
run: |
images=""
for tag in ${TAGS//,/ }; do
if [[ $tag == *"_dev"* && $TAGS == *","* ]]; then
continue
fi
images+="${tag}@${DIGEST} "
done
if [[ -n $images ]]; then
cosign sign --yes -a author=JanssenProject ${images}
fi