9
9
image :
10
10
required : true
11
11
type : string
12
+ tag :
13
+ required : false
14
+ type : string
12
15
go-md5 :
13
16
required : true
14
17
type : string
15
18
base-image-md5 :
16
- required : false
19
+ required : true
17
20
type : string
18
- tag :
19
- required : false
21
+ branch :
22
+ required : true
20
23
type : string
21
- publish-image :
22
- required : false
24
+ authenticated :
25
+ required : true
23
26
type : boolean
24
- forked-workflow :
27
+ full-build :
28
+ description : Always build base image
25
29
required : false
26
30
type : boolean
31
+ default : false
32
+ ic-version :
33
+ required : false
34
+ type : string
27
35
28
36
defaults :
29
37
run :
@@ -38,85 +46,60 @@ jobs:
38
46
permissions :
39
47
contents : read # for docker/build-push-action to read repo content
40
48
security-events : write # for github/codeql-action/upload-sarif to upload SARIF results
41
- id-token : write # for OIDC login to AWS ECR
49
+ id-token : write # for OIDC login to GCR
42
50
packages : write # for docker/build-push-action to push to GHCR
43
- outputs :
44
- version : ${{ steps.meta.outputs.version }}
45
- image_digest : ${{ steps.build-push.outputs.digest }}
46
51
steps :
47
52
- name : Checkout Repository
48
53
uses : actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
49
54
with :
50
- ref : ${{ inputs.tag != '' && format('refs/tags/v{0}', inputs.tag) || github.ref }}
55
+ ref : ${{ inputs.branch }}
51
56
fetch-depth : 0
52
57
53
- - name : Fetch Cached Artifacts
54
- uses : actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
55
- with :
56
- path : ${{ github.workspace }}/dist
57
- key : nginx-ingress-${{ inputs.go-md5 }}
58
-
59
58
- name : Setup QEMU
60
59
uses : docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
61
60
with :
62
61
platforms : arm,arm64,ppc64le,s390x
63
- if : ${{ inputs.publish-image }}
64
62
65
63
- name : Docker Buildx
66
64
uses : docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
67
65
68
- - name : DockerHub Login
69
- uses : docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0
70
- with :
71
- username : ${{ secrets.DOCKER_USERNAME }}
72
- password : ${{ secrets.DOCKER_PASSWORD }}
73
- if : ${{ inputs.publish-image }}
74
-
75
- - name : Login to GitHub Container Registry
76
- uses : docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0
77
- with :
78
- registry : ghcr.io
79
- username : ${{ github.repository_owner }}
80
- password : ${{ secrets.GITHUB_TOKEN }}
81
- if : ${{ inputs.publish-image }}
82
-
83
- - name : Configure AWS Credentials
84
- uses : aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
85
- with :
86
- aws-region : us-east-1
87
- role-to-assume : ${{ secrets.AWS_ROLE_PUBLIC_ECR }}
88
- if : ${{ inputs.publish-image }}
89
-
90
- - name : Login to Public ECR
91
- uses : docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0
92
- with :
93
- registry : public.ecr.aws
94
- if : ${{ inputs.publish-image }}
95
-
96
- - name : Login to Quay.io
97
- uses : docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0
98
- with :
99
- registry : quay.io
100
- username : ${{ secrets.QUAY_USERNAME }}
101
- password : ${{ secrets.QUAY_ROBOT_TOKEN }}
102
- if : ${{ inputs.publish-image }}
103
-
104
66
- name : Authenticate to Google Cloud
105
67
id : auth
106
68
uses : google-github-actions/auth@71fee32a0bb7e97b4d33d548e7d957010649d8fa # v2.1.3
107
69
with :
108
70
token_format : access_token
109
71
workload_identity_provider : ${{ secrets.GCR_WORKLOAD_IDENTITY }}
110
72
service_account : ${{ secrets.GCR_SERVICE_ACCOUNT }}
111
- if : ${{ ! inputs.forked-workflow }}
73
+ if : ${{ inputs.authenticated }}
112
74
113
75
- name : Login to GCR
114
76
uses : docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0
115
77
with :
116
78
registry : gcr.io
117
79
username : oauth2accesstoken
118
80
password : ${{ steps.auth.outputs.access_token }}
119
- if : ${{ ! inputs.forked-workflow }}
81
+ if : ${{ inputs.authenticated }}
82
+
83
+ - name : Docker meta
84
+ id : meta
85
+ uses : docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
86
+ with :
87
+ context : workflow
88
+ images : |
89
+ name=gcr.io/f5-gcs-7899-ptg-ingrss-ctlr/dev/nginx-ic/nginx-ingress
90
+ flavor : |
91
+ suffix=${{ contains(inputs.image, 'ubi') && '-ubi' || '' }}${{ contains(inputs.image, 'alpine') && '-alpine' || '' }}
92
+ tags : |
93
+ type=raw,value=${{ inputs.tag }}
94
+ labels : |
95
+ org.opencontainers.image.description=NGINX Ingress Controller for Kubernetes
96
+ io.artifacthub.package.readme-url=https://raw.githubusercontent.com/nginxinc/kubernetes-ingress/main/README.md
97
+ io.artifacthub.package.logo-url=https://docs.nginx.com/nginx-ingress-controller/images/icons/NGINX-Ingress-Controller-product-icon.svg
98
+ io.artifacthub.package.maintainers=[{"name":"NGINX Inc","email":"[email protected] "}]
99
+ io.artifacthub.package.license=Apache-2.0
100
+ io.artifacthub.package.keywords=kubernetes,ingress,nginx,controller
101
+ env :
102
+ DOCKER_METADATA_ANNOTATIONS_LEVELS : manifest,index
120
103
121
104
- name : Check if base images exist
122
105
id : base_exists
@@ -126,64 +109,48 @@ jobs:
126
109
if docker manifest inspect ${base_image}; then
127
110
echo "exists=true" >> $GITHUB_OUTPUT
128
111
fi
129
- if : ${{ ! inputs.forked-workflow }}
112
+ if : ${{ inputs.authenticated && ! inputs.full-build }}
130
113
131
114
- name : Build Base Container
132
115
uses : docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
133
116
with :
134
117
file : build/Dockerfile
135
118
context : " ."
136
- cache-from : type=gha,scope=${{ inputs.image }}
137
119
cache-to : type=gha,scope=${{ inputs.image }},mode=max
138
120
target : common
139
121
tags : ${{ steps.base_exists.outputs.image }}
140
122
platforms : ${{ inputs.platforms }}
141
123
pull : true
142
124
push : true
125
+ no-cache : true
143
126
build-args : |
144
127
BUILD_OS=${{ inputs.image }}
145
- IC_VERSION=${{ inputs.tag }}
146
- if : ${{ ! inputs.forked-workflow && steps.base_exists.outputs.exists != 'true' }}
128
+ IC_VERSION=${{ inputs.ic-version && inputs.ic-version || steps.meta.outputs.version }}
129
+ if : ${{ inputs.authenticated && steps.base_exists.outputs.exists != 'true' }}
130
+
131
+ - name : Check if target image exists
132
+ id : target_exists
133
+ run : |
134
+ if docker pull ${{ steps.meta.outputs.tags }}; then
135
+ echo "exists=true" >> $GITHUB_OUTPUT
136
+ fi
137
+ if : ${{ inputs.authenticated && ! inputs.full-build }}
147
138
148
- - name : Get short tag
149
- id : tag
139
+ - name : Debug values
150
140
run : |
151
- version="${{ inputs.tag }}"
152
- short="${version%.*}"
153
- echo "short=$short" >> $GITHUB_OUTPUT
154
- if : ${{ inputs.tag != '' }}
141
+ echo "authenticated: ${{ inputs.authenticated }}"
142
+ echo "base_exists: ${{ steps.base_exists.outputs.exists }}"
143
+ echo "target_exists: ${{ steps.target_exists.outputs.exists }}"
144
+ echo "full-build: ${{ inputs.full-build }}"
145
+ echo "all: ${{ inputs.authenticated || steps.base_exists.outputs.exists != 'true' || steps.target_exists.outputs.exists != 'true' }}"
155
146
156
- - name : Docker meta
157
- id : meta
158
- uses : docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
147
+ - name : Fetch Cached Artifacts
148
+ uses : actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
159
149
with :
160
- context : ${{ inputs.tag != '' && 'git' || 'workflow' }}
161
- images : |
162
- name=nginx/nginx-ingress
163
- name=ghcr.io/nginxinc/kubernetes-ingress
164
- name=public.ecr.aws/nginx/nginx-ingress
165
- name=quay.io/nginx/nginx-ingress
166
- flavor : |
167
- latest=${{ (inputs.tag != '' && 'true') || 'auto' }}
168
- suffix=${{ contains(inputs.image, 'ubi') && '-ubi' || '' }}${{ contains(inputs.image, 'alpine') && '-alpine' || '' }},onlatest=true
169
- tags : |
170
- type=edge
171
- type=ref,event=pr
172
- type=ref,event=branch,enable=${{ startsWith(github.ref, 'refs/heads/release-') }}
173
- type=schedule,enable=${{ inputs.tag == '' }}
174
- type=semver,pattern={{version}}
175
- type=semver,pattern={{major}}.{{minor}}
176
- type=raw,value=${{ inputs.tag }},enable=${{ inputs.tag != '' }}
177
- type=raw,value=${{ steps.tag.outputs.short }},enable=${{ inputs.tag != '' }}
178
- labels : |
179
- org.opencontainers.image.description=NGINX Ingress Controller for Kubernetes
180
- io.artifacthub.package.readme-url=https://raw.githubusercontent.com/nginxinc/kubernetes-ingress/main/README.md
181
- io.artifacthub.package.logo-url=https://docs.nginx.com/nginx-ingress-controller/images/icons/NGINX-Ingress-Controller-product-icon.svg
182
- io.artifacthub.package.maintainers=[{"name":"NGINX Inc","email":"[email protected] "}]
183
- io.artifacthub.package.license=Apache-2.0
184
- io.artifacthub.package.keywords=kubernetes,ingress,nginx,controller
185
- env :
186
- DOCKER_METADATA_ANNOTATIONS_LEVELS : manifest,index
150
+ path : ${{ github.workspace }}/dist
151
+ key : nginx-ingress-${{ inputs.go-md5 }}
152
+ fail-on-cache-miss : true
153
+ if : ${{ inputs.authenticated || steps.base_exists.outputs.exists != 'true' || steps.target_exists.outputs.exists != 'true' }}
187
154
188
155
- name : Build Docker image
189
156
uses : docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
@@ -193,35 +160,21 @@ jobs:
193
160
context : " ."
194
161
cache-from : type=gha,scope=${{ inputs.image }}
195
162
cache-to : type=gha,scope=${{ inputs.image }},mode=max
196
- target : goreleaser${{ ! inputs.forked-workflow && '-prebuilt' || '' }}
163
+ target : goreleaser${{ inputs.authenticated && '-prebuilt' || '' }}
197
164
tags : ${{ steps.meta.outputs.tags }}
198
165
labels : ${{ steps.meta.outputs.labels }}
199
- annotations : ${{ github.event_name != 'pull_request' && steps.meta.outputs.annotations || '' }}
200
- platforms : ${{ github.event_name != 'pull_request' && ! startsWith(github.ref, 'refs/heads/release-') && inputs.platforms || '' }}
201
- load : ${{ github.event_name == 'pull_request' || startsWith(github.ref, 'refs/heads/release-') }}
202
- push : ${{ inputs.publish-image }}
166
+ annotations : ${{ steps.meta.outputs.annotations }}
167
+ platforms : ${{ inputs.platforms }}
168
+ load : false
169
+ push : ${{ inputs.authenticated }}
203
170
pull : true
204
- no-cache : ${{ inputs.publish-image }}
205
- sbom : ${{ inputs.publish-image }}
171
+ sbom : ${{ inputs.authenticated }}
206
172
provenance : false
207
173
build-args : |
208
174
BUILD_OS=${{ inputs.image }}
209
- ${{ ! inputs.forked-workflow && format('PREBUILT_BASE_IMG={0}', steps.base_exists.outputs.image) || '' }}
210
- IC_VERSION=${{ (github.event_name == 'pull_request' || startsWith(github.ref, 'refs/heads/release-')) && 'CI' || steps.meta.outputs.version }}
211
-
212
- - name : Certify Images
213
- continue-on-error : true
214
- run : |
215
- curl -fsSL https://github.com/redhat-openshift-ecosystem/openshift-preflight/releases/download/1.6.11/preflight-linux-amd64 --output preflight
216
- chmod +x preflight
217
-
218
- IFS=',' read -ra arch_list <<< "${{ inputs.platforms }}"
219
-
220
- for arch in "${arch_list[@]}"; do
221
- architecture=("${arch#*/}")
222
- ./preflight check container quay.io/nginx/nginx-ingress:${{ steps.meta.outputs.version }} --pyxis-api-token ${{ secrets.PYXIS_API_TOKEN }} --certification-project-id ${{ secrets.CERTIFICATION_PROJECT_ID }} --platform $architecture --submit
223
- done
224
- if : ${{ (github.ref_type == 'tag' && vars.OLD_RELEASE_FLOW == 'true') && contains(inputs.image, 'ubi') }}
175
+ ${{ inputs.authenticated && format('PREBUILT_BASE_IMG={0}', steps.base_exists.outputs.image) }}
176
+ IC_VERSION=${{ inputs.ic-version && inputs.ic-version || steps.meta.outputs.version }}
177
+ if : ${{ steps.base_exists.outputs.exists != 'true' || steps.target_exists.outputs.exists != 'true' }}
225
178
226
179
- name : Run Trivy vulnerability scanner
227
180
uses : aquasecurity/trivy-action@595be6a0f6560a0a8fc419ddf630567fc623531d # 0.22.0
@@ -231,12 +184,14 @@ jobs:
231
184
format : " sarif"
232
185
output : " trivy-results-${{ inputs.image }}.sarif"
233
186
ignore-unfixed : " true"
187
+ if : ${{ inputs.authenticated && steps.build-push.conclusion == 'success' }}
234
188
235
189
- name : Upload Trivy scan results to GitHub Security tab
236
190
uses : github/codeql-action/upload-sarif@530d4feaa9c62aaab2d250371e2061eb7a172363 # v3.25.9
237
191
continue-on-error : true
238
192
with :
239
193
sarif_file : " trivy-results-${{ inputs.image }}.sarif"
194
+ if : ${{ inputs.authenticated && steps.build-push.conclusion == 'success' }}
240
195
241
196
- name : Upload Scan Results
242
197
uses : actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
@@ -245,17 +200,3 @@ jobs:
245
200
name : " trivy-results-${{ inputs.image }}.sarif"
246
201
path : " trivy-results-${{ inputs.image }}.sarif"
247
202
if : always()
248
-
249
- send-notification :
250
- name : Send Notification
251
- needs : build
252
- uses : ./.github/workflows/updates-notification.yml
253
- with :
254
- tag : ${{ inputs.tag }}
255
- version : ${{ needs.build.outputs.version }}
256
- image_digest : ${{ needs.build.outputs.image_digest }}
257
- permissions :
258
- contents : read
259
- actions : read
260
- secrets : inherit
261
- if : ${{ inputs.tag != '' }}
0 commit comments