Skip to content

Commit 131e784

Browse files
authored
Workflow refactor (nginx#5766)
1 parent 7a278b9 commit 131e784

14 files changed

+846
-714
lines changed

.github/scripts/copy-images.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ SOURCE_NAP_WAF_DOS_IMAGE_PREFIX=${SOURCE_NAP_WAF_DOS_IMAGE_PREFIX:-"nginx-ic-dos
4242

4343
TARGET_PLUS_IMAGE_PREFIX=${TARGET_PLUS_IMAGE_PREFIX:-"nginx-ic/nginx-plus-ingress"}
4444
TARGET_NAP_WAF_IMAGE_PREFIX=${TARGET_NAP_WAF_IMAGE_PREFIX:-"nginx-ic-nap/nginx-plus-ingress"}
45-
TARGET_NAP_WAFV5_IMAGE_PREFIX=${TARGET_NAP_WAFV5_IMAGE_PREFIX:-"nginx-ic-nap/nginx-plus-ingress"}
45+
TARGET_NAP_WAFV5_IMAGE_PREFIX=${TARGET_NAP_WAFV5_IMAGE_PREFIX:-"nginx-ic-nap-v5/nginx-plus-ingress"}
4646
TARGET_NAP_DOS_IMAGE_PREFIX=${TARGET_NAP_DOS_IMAGE_PREFIX:-"nginx-ic-dos/nginx-plus-ingress"}
4747
TARGET_NAP_WAF_DOS_IMAGE_PREFIX=${TARGET_NAP_WAF_DOS_IMAGE_PREFIX:-"nginx-ic-dos-nap/nginx-plus-ingress"}
4848

.github/scripts/variables.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ get_chart_md5() {
3030
}
3131

3232
get_actions_md5() {
33-
find .github .github/data/version.txt -type f -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }'
33+
find .github -type f -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }'
3434
}
3535

3636
get_build_tag() {

.github/workflows/build-oss.yml

Lines changed: 74 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,29 @@ on:
99
image:
1010
required: true
1111
type: string
12+
tag:
13+
required: false
14+
type: string
1215
go-md5:
1316
required: true
1417
type: string
1518
base-image-md5:
16-
required: false
19+
required: true
1720
type: string
18-
tag:
19-
required: false
21+
branch:
22+
required: true
2023
type: string
21-
publish-image:
22-
required: false
24+
authenticated:
25+
required: true
2326
type: boolean
24-
forked-workflow:
27+
full-build:
28+
description: Always build base image
2529
required: false
2630
type: boolean
31+
default: false
32+
ic-version:
33+
required: false
34+
type: string
2735

2836
defaults:
2937
run:
@@ -38,85 +46,60 @@ jobs:
3846
permissions:
3947
contents: read # for docker/build-push-action to read repo content
4048
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
4250
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 }}
4651
steps:
4752
- name: Checkout Repository
4853
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
4954
with:
50-
ref: ${{ inputs.tag != '' && format('refs/tags/v{0}', inputs.tag) || github.ref }}
55+
ref: ${{ inputs.branch }}
5156
fetch-depth: 0
5257

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-
5958
- name: Setup QEMU
6059
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
6160
with:
6261
platforms: arm,arm64,ppc64le,s390x
63-
if: ${{ inputs.publish-image }}
6462

6563
- name: Docker Buildx
6664
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
6765

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-
10466
- name: Authenticate to Google Cloud
10567
id: auth
10668
uses: google-github-actions/auth@71fee32a0bb7e97b4d33d548e7d957010649d8fa # v2.1.3
10769
with:
10870
token_format: access_token
10971
workload_identity_provider: ${{ secrets.GCR_WORKLOAD_IDENTITY }}
11072
service_account: ${{ secrets.GCR_SERVICE_ACCOUNT }}
111-
if: ${{ ! inputs.forked-workflow }}
73+
if: ${{ inputs.authenticated }}
11274

11375
- name: Login to GCR
11476
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0
11577
with:
11678
registry: gcr.io
11779
username: oauth2accesstoken
11880
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
120103

121104
- name: Check if base images exist
122105
id: base_exists
@@ -126,64 +109,48 @@ jobs:
126109
if docker manifest inspect ${base_image}; then
127110
echo "exists=true" >> $GITHUB_OUTPUT
128111
fi
129-
if: ${{ ! inputs.forked-workflow }}
112+
if: ${{ inputs.authenticated && ! inputs.full-build }}
130113

131114
- name: Build Base Container
132115
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
133116
with:
134117
file: build/Dockerfile
135118
context: "."
136-
cache-from: type=gha,scope=${{ inputs.image }}
137119
cache-to: type=gha,scope=${{ inputs.image }},mode=max
138120
target: common
139121
tags: ${{ steps.base_exists.outputs.image }}
140122
platforms: ${{ inputs.platforms }}
141123
pull: true
142124
push: true
125+
no-cache: true
143126
build-args: |
144127
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 }}
147138

148-
- name: Get short tag
149-
id: tag
139+
- name: Debug values
150140
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' }}"
155146
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
159149
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' }}
187154

188155
- name: Build Docker image
189156
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
@@ -193,35 +160,21 @@ jobs:
193160
context: "."
194161
cache-from: type=gha,scope=${{ inputs.image }}
195162
cache-to: type=gha,scope=${{ inputs.image }},mode=max
196-
target: goreleaser${{ ! inputs.forked-workflow && '-prebuilt' || '' }}
163+
target: goreleaser${{ inputs.authenticated && '-prebuilt' || '' }}
197164
tags: ${{ steps.meta.outputs.tags }}
198165
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 }}
203170
pull: true
204-
no-cache: ${{ inputs.publish-image }}
205-
sbom: ${{ inputs.publish-image }}
171+
sbom: ${{ inputs.authenticated }}
206172
provenance: false
207173
build-args: |
208174
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' }}
225178

226179
- name: Run Trivy vulnerability scanner
227180
uses: aquasecurity/trivy-action@595be6a0f6560a0a8fc419ddf630567fc623531d # 0.22.0
@@ -231,12 +184,14 @@ jobs:
231184
format: "sarif"
232185
output: "trivy-results-${{ inputs.image }}.sarif"
233186
ignore-unfixed: "true"
187+
if: ${{ inputs.authenticated && steps.build-push.conclusion == 'success' }}
234188

235189
- name: Upload Trivy scan results to GitHub Security tab
236190
uses: github/codeql-action/upload-sarif@530d4feaa9c62aaab2d250371e2061eb7a172363 # v3.25.9
237191
continue-on-error: true
238192
with:
239193
sarif_file: "trivy-results-${{ inputs.image }}.sarif"
194+
if: ${{ inputs.authenticated && steps.build-push.conclusion == 'success' }}
240195

241196
- name: Upload Scan Results
242197
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
@@ -245,17 +200,3 @@ jobs:
245200
name: "trivy-results-${{ inputs.image }}.sarif"
246201
path: "trivy-results-${{ inputs.image }}.sarif"
247202
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

Comments
 (0)