-
Notifications
You must be signed in to change notification settings - Fork 62
184 lines (178 loc) · 8.68 KB
/
101_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
name: build
permissions: {}
on:
workflow_call:
inputs:
jobs_to_run:
description: "Which build jobs should be run: 'all', 'only-required', 'skip-all'?"
type: string
default: "all"
outputs:
chart_version:
description: "Connaisseur Helm chart version"
value: ${{ jobs.context.outputs.chart_version }}
original_registry:
description: "Public Connaisseur registry"
value: ${{ jobs.context.outputs.original_registry }}
original_repo:
description: "Public Connaisseur repo"
value: ${{ jobs.context.outputs.original_repo }}
original_tag:
description: "Current Connaisseur tag, i.e. version"
value: ${{ jobs.context.outputs.original_tag }}
original_image:
description: "Full Connaisseur image reference, i.e. registry + repository + tag"
value: ${{ jobs.context.outputs.original_image }}
build_registry:
description: "Workflow build registry used for testing"
value: ${{ jobs.context.outputs.build_registry }}
build_repo:
description: "Workflow build repository used for testing"
value: ${{ jobs.context.outputs.build_repo }}
build_tag:
description: "Workflow build tag used for testing (unique for each run)"
value: ${{ jobs.context.outputs.build_tag }}
build_image:
description: "Workflow build image used for testing, i.e. registry + repository + tag"
value: ${{ jobs.context.outputs.build_image }}
build_labels:
description: "Repository- and workflow-specific build labels"
value: ${{ jobs.context.outputs.build_labels }}
jobs:
context:
runs-on: ubuntu-latest
if: inputs.jobs_to_run != 'skip-all'
permissions: {}
outputs:
chart_version: ${{ steps.output_context.outputs.CHART_VERSION }}
original_registry: ${{ steps.output_context.outputs.ORIGINAL_REGISTRY }}
original_repo: ${{ steps.output_context.outputs.ORIGINAL_REPO }}
original_image: ${{ steps.output_context.outputs.ORIGINAL_IMAGE }}
original_tag: ${{ steps.output_context.outputs.ORIGINAL_TAG }}
build_registry: ${{ steps.output_context.outputs.BUILD_REGISTRY }}
build_repo: ${{ steps.output_context.outputs.BUILD_REPO }}
build_tag: ${{ steps.output_context.outputs.BUILD_TAG }}
build_image: ${{ steps.output_context.outputs.BUILD_IMAGE }}
build_labels: ${{ steps.meta.outputs.labels }}
ref_tags: ${{ steps.output_context.outputs.REF_TAGS }}
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Get chart version
id: get_chart_version
uses: mikefarah/yq@4839dbbf80445070a31c7a9c1055da527db2d5ee # v4.44.6
with:
cmd: yq '.version' charts/connaisseur/Chart.yaml
- name: Get app version
id: get_app_version
uses: mikefarah/yq@4839dbbf80445070a31c7a9c1055da527db2d5ee # v4.44.6
with:
cmd: yq '.appVersion' charts/connaisseur/Chart.yaml
- name: Get original image
id: get_original_image_repository
uses: mikefarah/yq@4839dbbf80445070a31c7a9c1055da527db2d5ee # v4.44.6
with:
cmd: yq '.kubernetes.deployment.image.repository' charts/connaisseur/values.yaml
- name: Get repo name
id: get_repo_name
run: |
GHREF=${{ github.ref }}
BUILD_REPO=${{ github.repository }}
if [[ "${GHREF}" != "refs/heads/master" &&
"${GHREF}" != "refs/tags/v"* &&
"${GHREF}" != "refs/heads/develop"
]]; then
BUILD_REPO="${BUILD_REPO}-test"
fi
echo BUILD_REPO=${BUILD_REPO} >> ${GITHUB_OUTPUT}
shell: bash
- name: Generate metadata
id: meta
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
with:
images: ghcr.io/${{ steps.get_repo_name.outputs.BUILD_REPO }}
flavor: |
latest=true
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=sha
- name: Output context
id: output_context
run: |
CHART_VERSION=${{ steps.get_chart_version.outputs.result }}
CONFIGURED_IMAGE_REPO=${{ steps.get_original_image_repository.outputs.result }}
ORIGINAL_REGISTRY=$(echo "${CONFIGURED_IMAGE_REPO}" | cut -d "/" -f 1)
ORIGINAL_REPO=$(echo "${CONFIGURED_IMAGE_REPO}" | cut -d "/" -f 2- | cut -d ":" -f 1)
ORIGINAL_TAG=v${{ steps.get_app_version.outputs.result }}
BUILD_REGISTRY="ghcr.io"
BUILD_REPO=${{ steps.get_repo_name.outputs.BUILD_REPO }}
PREFIX=$(echo "${BUILD_REGISTRY}/${BUILD_REPO}:" | sed 's%/%\/%g')
TAGS="${{ steps.meta.outputs.tags }}"
REF_TAGS="${TAGS//${PREFIX}/}"
BUILD_IMAGE=$(echo "${TAGS}" | tail -2 | head -1)
BUILD_TAG="${BUILD_IMAGE//${PREFIX}/}"
[[ ${BUILD_TAG} == "sha-"* ]] || exit 1 # check as parsing of the BUILD_TAG maybe fragile and dependent on docker/metadata-action priorities
REF_TAGS="${REF_TAGS//${BUILD_TAG}/}"
echo CHART_VERSION=${CHART_VERSION} >> ${GITHUB_OUTPUT}
echo ORIGINAL_REGISTRY=${ORIGINAL_REGISTRY} >> ${GITHUB_OUTPUT}
echo ORIGINAL_REPO=${ORIGINAL_REPO} >> ${GITHUB_OUTPUT}
echo ORIGINAL_TAG=${ORIGINAL_TAG} >> ${GITHUB_OUTPUT}
echo ORIGINAL_IMAGE=${CONFIGURED_IMAGE_REPO}:${ORIGINAL_TAG} >> ${GITHUB_OUTPUT}
echo BUILD_REGISTRY=${BUILD_REGISTRY} >> ${GITHUB_OUTPUT}
echo BUILD_REPO=${BUILD_REPO} >> ${GITHUB_OUTPUT}
echo BUILD_TAG=${BUILD_TAG} >> ${GITHUB_OUTPUT}
echo BUILD_IMAGE=${BUILD_IMAGE} >> ${GITHUB_OUTPUT}
echo REF_TAGS=${REF_TAGS} >> ${GITHUB_OUTPUT}
shell: bash
build:
runs-on: ubuntu-latest
if: inputs.jobs_to_run != 'skip-all'
needs: [context]
permissions:
packages: write
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up Docker buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
- name: Login with registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ${{ needs.context.outputs.build_registry }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate tags
id: tags
run: |
echo "${{ needs.context.outputs.ref_tags }}"
export PREFIX="${{ needs.context.outputs.build_registry }}/${{ needs.context.outputs.build_repo }}:"
TAGS="${PREFIX}${{ needs.context.outputs.build_tag }},$(echo ${{ needs.context.outputs.ref_tags }} | tr ' ' '\n' | awk '{print "${PREFIX}"$1}' | envsubst | tr '\n' ',')"
echo tags=${TAGS} >> ${GITHUB_OUTPUT}
shell: bash
- name: Build and push image
id: build
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v6.10.0
with:
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
file: build/Dockerfile
labels: ${{ needs.context.outputs.build_labels }}
tags: ${{ steps.tags.outputs.tags }}
sbom: false
provenance: false #TODO: Set to false, as resulting format is not OCI (GHCR) compliant (https://github.com/docker/build-push-action/issues/820) and causes problems with GHCR and e.g. image deletion (https://github.com/snok/container-retention-policy/issues/63)
- name: Show build information
run: |
echo "# :building_construction: Build Information" >> ${GITHUB_STEP_SUMMARY}
echo "<table>" >> ${GITHUB_STEP_SUMMARY}
echo "<tr><td>Helm chart version</td><td><code>${{ needs.context.outputs.chart_version }}</code></td></tr>" >> ${GITHUB_STEP_SUMMARY}
echo "<tr><td>Original image</td><td><code>${{ needs.context.outputs.original_image }}</code></td></tr>" >> ${GITHUB_STEP_SUMMARY}
echo "<tr><td>Workflow image</td><td><code>${{ needs.context.outputs.build_registry }}/${{ needs.context.outputs.build_repo }}:${{ needs.context.outputs.build_tag }}</code></td></tr>" >> ${GITHUB_STEP_SUMMARY}
echo "<tr><td>All images</td><td><code>$(echo ${{ steps.tags.outputs.tags }} | tr ',' '\n')</code></td></tr>" >> ${GITHUB_STEP_SUMMARY}
echo "<tr><td>Digest</td><td><code>${{ steps.build.outputs.digest }}</code></td></tr>" >> ${GITHUB_STEP_SUMMARY}
echo "</table>" >> ${GITHUB_STEP_SUMMARY}
echo "" >> ${GITHUB_STEP_SUMMARY}
shell: bash