-
Notifications
You must be signed in to change notification settings - Fork 14
206 lines (191 loc) · 8.46 KB
/
docker_build_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
name: Build and Publish Releases to Hub
on:
schedule:
- cron: "0 23 * * *"
push:
tags:
- "*"
branches:
- main
paths:
- "docker-**/**"
- "!**.md"
workflow_dispatch:
inputs:
services:
description: 'One or set of the docker images. Format as following: "docker-admin-ui docker-flex-monolith docker-flex-all-in-one"'
required: true
default: 'docker-admin-ui docker-flex-monolith docker-flex-all-in-one'
gluu_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
runs-on: ubuntu-latest
strategy:
max-parallel: 8
matrix:
docker-images: ["admin-ui", "flex-monolith", "flex-all-in-one"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
sparse-checkout: |
automation
docker-admin-ui
docker-flex-monolith
docker-flex-all-in-one
- 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-admin-ui docker-flex-monolith docker-flex-all-in-one"
else
echo "$DEFAULT_ALL"
fi
# Detect actual docker folders that changed if error arises default to all images
DIRECTORIES_CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | cut -d/ -f1 | sort -u | grep "docker" || echo "$DEFAULT_ALL")
if [[ "$DIRECTORIES_CHANGED" =~ "${{ matrix.docker-images }}" ]]; then
echo "A change in this images directory has occured"
echo ::set-output name=build::${BUILD}
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
- name: Prepare
if: steps.build_docker_image.outputs.build || github.event_name == 'tags'
id: prep
run: |
REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
MAIN_VERSION=$(python3 -c "from dockerfile_parse import DockerfileParser ; dfparser = DockerfileParser('./docker-${{ matrix.docker-images }}') ; print(dfparser.labels['org.opencontainers.image.version'])")
DOCKER_IMAGE=ghcr.io/$REPOSITORY/${{ matrix.docker-images }}
VERSION=${MAIN_VERSION}_dev
if [[ ${{ matrix.docker-images }} == "flex-monolith" ]]; then
VERSION=5.1.6_dev
DOCKER_IMAGE=ghcr.io/$REPOSITORY/monolith
fi
BUILD=true
if [[ $GITHUB_REF == refs/tags/docker-${{ matrix.docker-images }}-* ]]; then
VERSION=${GITHUB_REF#refs/tags/docker-${{ 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}_dev"
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.
GLUU_VERSION=${{ github.event.inputs.gluu_version }}
if [ ! -z "$GLUU_VERSION" ]
then
python3 -c "from dockerfile_parse import DockerfileParser ; dfparser = DockerfileParser('./docker-${{ matrix.docker-images }}') ; dfparser.envs['CN_VERSION'] = '${{ github.event.inputs.gluu_version }}'"
echo "War version has been modified."
else
echo "$GLUU_VERSION"
fi
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "build=${BUILD}" >> $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 [[ "flex-all-in-one" =~ "${{ matrix.docker-images }}" ]]; then
if [[ ${{ github.event_name != 'pull_request' }} ]]; then
TEMP_IMG="admin-ui"
for i in $TEMP_IMG; do
TEMP_TOKEN=$(curl https://ghcr.io/token\?scope\="repository:gluufederation/flex/$i:pull" | jq -r '.token')
while [[ $(curl -s -H "Authorization: Bearer ${TEMP_TOKEN}" https://ghcr.io/v2/gluufederation/flex/$i/tags/list | jq -r '.tags' | grep "$VERSION" | tr -d '[:space:]"') != "$VERSION" ]]; do
echo "Waiting for $i to be built"
sleep 30
done
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'
uses: actions/setup-python@v4
with:
python-version: 3.7
- name: Install Python dependencies
if: github.event_name == 'workflow_dispatch'
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'
id: update_build_date_in_dockerfile
run: |
sudo python3 ./automation/auto_update_image_pr.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@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@v3
- name: Login to ghcr
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
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@v5
with:
builder: ${{ steps.buildx.outputs.name }}
context: ./docker-${{ matrix.docker-images }}
file: ./docker-${{ matrix.docker-images }}/Dockerfile
#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 }}