Skip to content

Commit 2e04996

Browse files
authored
[CI/CD] Improve assertion doc generation (#1400)
* reduce packaging time by building only two binaries * use pushd * tidy up console output * perform string substitution when creating files for release packaging * remove docker build for FreeBSD packager * perform string sub on architecture var * update make target * [skip ci] clean up log output * add assertion step to release-branch, sha checksum and build times * archive the binaries for generating assertion doc * remove matrix from step * fix ref * use a relative path for reusable action * add package version to call * remove secrets * [skip ci] swap runner for test * [skip ci] fix flow * [skip ci] fix flow * update actions versions for artifacts * [skip ci] more log output when archiving binaries * [skip ci] run from this branch for test * [skip ci] run from this branch for test * [skip ci] run from this branch for test * [skip ci] add back gpg key gen * [skip ci] fix tarball path, use cd instead of popd * [skip ci] move assertion doc gen into release-branch.yml * [skip ci] install go for assertion doc job * [skip ci] use go mod download * [skip ci] * [skip ci] * [skip ci] add artifactory creds * make assertion optional * call reusable assertion workflow * [skip ci] fix perms * [skip ci] fix perms * [skip ci] allow run via dispatch, artifact id as input * [skip ci] add run id for downloading artifacts * [skip ci] list artifacts and download by name * make run id required * remove ref from checkout, use current commit or default branch * ensure checkout uses inputs.releaseBranch in release branch workflow * use self-hosted runner for build
1 parent 540ed2f commit 2e04996

File tree

3 files changed

+132
-55
lines changed

3 files changed

+132
-55
lines changed

.github/workflows/assertion.yml

Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,94 @@
1-
21
name: Generate and Sign Assertion Document
32

43
on:
54
workflow_dispatch:
65
inputs:
7-
branch:
6+
packageVersion:
7+
description: 'Agent version'
8+
type: string
9+
required: true
10+
runId:
11+
description: 'Run ID of the workflow that built the artifacts'
12+
type: string
13+
required: true
14+
signAssertion:
15+
description: 'Sign and store the assertion document'
16+
type: boolean
17+
required: false
18+
default: false
19+
workflow_call:
20+
inputs:
21+
packageVersion:
22+
description: 'Agent version'
823
type: string
9-
description: "The branch to run the assertion workflow on"
24+
required: true
25+
runId:
26+
description: 'Run ID of the workflow that built the artifacts'
27+
type: string
28+
required: false
29+
signAssertion:
30+
description: 'Sign and store the assertion document'
31+
type: boolean
1032
required: false
11-
default: main
33+
default: false
34+
secrets:
35+
ARTIFACTORY_USER:
36+
required: true
37+
ARTIFACTORY_TOKEN:
38+
required: true
39+
ARTIFACTORY_URL:
40+
required: true
1241

1342
jobs:
1443
build-assertion-document:
15-
name: Build and Generate Assertion Document
44+
name: Create Assertion Document
1645
runs-on: ubuntu-22.04
1746
if: ${{ !github.event.pull_request.head.repo.fork }}
1847
permissions:
1948
id-token: write
2049
contents: read
2150
env:
22-
GOPROXY: "https://${{ secrets.ARTIFACTORY_USER }}:${{ secrets.ARTIFACTORY_TOKEN }}@${{ secrets.ARTIFACTORY_URL_PROD }}"
23-
outputs:
24-
agent_binary: ${{ steps.check_binary.outputs.agent_binary }}
25-
goversionm: ${{ steps.godeps.outputs.goversionm }}
26-
assertion_document: ${{ steps.assertiondoc.outputs.assertion-document-path }}
51+
GOPROXY: "https://${{ secrets.ARTIFACTORY_USER }}:${{ secrets.ARTIFACTORY_TOKEN }}@${{ secrets.ARTIFACTORY_URL }}"
2752
strategy:
28-
matrix:
29-
osarch: [amd64, arm64]
53+
matrix:
54+
osarch: [amd64, arm64]
3055
steps:
31-
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
56+
- name: Checkout Repository
57+
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
3258

3359
- name: Set up Go
3460
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
3561
with:
36-
go-version-file: go.mod
62+
go-version-file: 'go.mod'
3763
cache: false
3864

65+
- name: Download nginx-agent binary artifacts
66+
if: ${{ inputs.runId != '' }}
67+
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # 6.0.0
68+
with:
69+
name: nginx-agent-binaries-${{ inputs.packageVersion }}-${{ matrix.osarch }}
70+
path: binaries
71+
run-id: ${{ inputs.runId }}
72+
github-token: ${{ github.token }}
73+
3974
- name: Gather build dependencies
4075
id: godeps
4176
run: |
42-
if [ -z ${{inputs.branch}} ]; then
43-
echo "No branch input provided, using current branch: $GITHUB_REF_NAME"
44-
else
45-
echo "Checking out branch: ${{inputs.branch}}"
46-
git checkout ${{inputs.branch}}
47-
fi
48-
echo "Current branch: $GITHUB_REF_NAME"
49-
echo "branch_name=$GITHUB_REF_NAME" >> $GITHUB_ENV
50-
GO_VERSION=$(go version | awk '{print $3}' | sed 's/go//')
51-
echo "GO_VERSION=$GO_VERSION" >> $GITHUB_ENV
52-
echo "GO_VERSION=$GO_VERSION"
53-
echo "time_start=$(date +%s)" >> $GITHUB_ENV
54-
OSARCH=${{matrix.osarch}} make build
55-
echo "time_end=$(date +%s)" >> $GITHUB_ENV
56-
echo "Build time: $((time_end - time_start)) seconds"
57-
58-
echo "Getting sha256sum of the built nginx-agent binary..."
59-
echo "agent-digest=$(sha256sum build/nginx-agent | awk '{print $1}')" >> $GITHUB_ENV
60-
77+
ls -la binaries
78+
echo "agent_digest=$(cat binaries/nginx-agent.sha256)" >> $GITHUB_ENV
79+
echo "agent_buildstart=$(cat binaries/nginx-agent.buildstart)" >> $GITHUB_ENV
80+
echo "agent_buildend=$(cat binaries/nginx-agent.buildend)" >> $GITHUB_ENV
81+
6182
echo "Checking dependencies..."
62-
go version -m build/nginx-agent > goversionm_${{ github.run_id }}_${{ github.run_number }}.txt
83+
go version -m binaries/nginx-agent > goversionm_${{ github.run_id }}_${{ github.run_number }}.txt
6384
ls -l goversionm_*.txt
6485
echo "goversionm=$(find -type f -name "goversionm*.txt" | head -n 1)" >> $GITHUB_ENV
6586
6687
- name: Generate Assertion Document
6788
id: assertiondoc
6889
uses: nginxinc/compliance-rules/.github/actions/assertion@0aab935582c35a00e2c671d8fe25b7fdd72a927b # v0.3.1
6990
with:
70-
artifact-name: nginx-agent_${{ env.branch_name }}_${{ matrix.osarch }}
91+
artifact-name: nginx-agent_${{ inputs.packageVersion }}_${{ matrix.osarch }}
7192
artifact-digest: ${{ env.agent-digest }}
7293
build-type: 'github'
7394
builder-id: 'github.com'
@@ -77,13 +98,14 @@ jobs:
7798
artifactory-api-token: ${{ secrets.ARTIFACTORY_TOKEN }}
7899
artifactory-url: ${{ secrets.ARTIFACTORY_URL }}
79100
artifactory-repo: 'f5-nginx-go-local-approved-dependency'
80-
assertion-doc-file: assertion_nginx-agent_${{env.branch_name}}_${{matrix.osarch}}.json
101+
assertion-doc-file: assertion_nginx-agent_${{ inputs.packageVersion }}_${{ matrix.osarch }}.json
81102
build-content-path: ${{ env.goversionm }}
82-
started-on: '${{ env.time_start }}'
83-
finished-on: '${{ env.time_end }}'
103+
started-on: '${{ env.agent_buildstart }}'
104+
finished-on: '${{ env.agent_buildend }}'
84105

85106
- name: Sign and Store Assertion Document
86107
id: sign
108+
if: ${{ inputs.signAssertion == true }}
87109
uses: nginxinc/compliance-rules/.github/actions/sign@0aab935582c35a00e2c671d8fe25b7fdd72a927b # v0.3.1
88110
with:
89111
assertion-doc: ${{ steps.assertiondoc.outputs.assertion-document-path }}

.github/workflows/release-branch.yml

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ on:
3737
description: 'Location to publish packages to'
3838
required: false
3939
default: "https://up-ap.nginx.com"
40+
type: string
41+
assertionDoc:
42+
description: 'Generate assertion document'
43+
default: false
44+
type: boolean
4045

4146
env:
4247
NFPM_VERSION: 'v2.35.3'
@@ -88,15 +93,13 @@ jobs:
8893
steps:
8994
- name: Checkout Repository
9095
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
96+
if: ${{ needs.vars.outputs.github_release == 'true' }}
9197
with:
9298
ref: ${{ inputs.releaseBranch }}
9399

94-
- name: Setup Node Environment
95-
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
96-
97100
- name: Create Draft Release
98-
if: ${{ needs.vars.outputs.github_release == 'true' }}
99101
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
102+
if: ${{ needs.vars.outputs.github_release == 'true' }}
100103
id: release
101104
env:
102105
version: ${{ inputs.packageVersion }}
@@ -172,6 +175,7 @@ jobs:
172175
173176
- name: Set Environment Variables
174177
id: vars
178+
if: ${{ needs.vars.outputs.github_release == 'true' }}
175179
run: |
176180
echo "RELEASE_ID=$(echo '${{steps.release.outputs.result}}' | jq -r '.release_id')" >> $GITHUB_OUTPUT
177181
cat $GITHUB_OUTPUT
@@ -185,6 +189,7 @@ jobs:
185189
steps:
186190
- name: Checkout Repository
187191
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
192+
if: ${{ needs.vars.outputs.tag_release == 'true' }}
188193
with:
189194
ref: ${{ inputs.releaseBranch }}
190195

@@ -193,16 +198,11 @@ jobs:
193198
run: |
194199
git config --global user.name 'github-actions'
195200
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
196-
197201
git tag -a "v${{ inputs.packageVersion }}" -m "CI Autogenerated"
198-
199-
- name: Push Tags
200-
if: ${{ needs.vars.outputs.tag_release == 'true' }}
201-
run: |
202202
git push origin "v${{ inputs.packageVersion }}"
203203
204-
upload-packages:
205-
name: Upload packages
204+
build-and-upload-packages:
205+
name: Build and upload release packages
206206
runs-on: ubuntu-22.04-amd64
207207
needs: [vars,release-draft,tag-release]
208208
permissions:
@@ -222,6 +222,7 @@ jobs:
222222

223223
- name: Setup package build environment
224224
run: |
225+
go mod download
225226
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@${{ env.NFPM_VERSION }}
226227
sudo apt-get update
227228
sudo apt-get install -y gpgv1 monkeysphere
@@ -242,6 +243,36 @@ jobs:
242243
export PATH=$PATH:~/go/bin
243244
echo "$GPG_KEY" | base64 --decode > ${NFPM_SIGNING_KEY_FILE}
244245
make package
246+
find build/ -type f -name "nginx-agent*"
247+
248+
- name: Archive AMD64 Binaries
249+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
250+
with:
251+
name: nginx-agent-binaries-${{ inputs.packageVersion }}-amd64
252+
path: |
253+
build/amd64/nginx-agent
254+
build/amd64/nginx-agent.sha256
255+
build/amd64/nginx-agent.buildstart
256+
build/amd64/nginx-agent.buildend
257+
258+
- name: Archive ARM64 Binaries
259+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
260+
with:
261+
name: nginx-agent-binaries-${{ inputs.packageVersion }}-arm64
262+
path: |
263+
build/arm64/nginx-agent
264+
build/arm64/nginx-agent.sha256
265+
build/arm64/nginx-agent.buildstart
266+
build/arm64/nginx-agent.buildend
267+
268+
- name: List artifacts
269+
run: |
270+
echo "Run ID: ${{ github.run_id }}"
271+
echo "Run Number: ${{ github.run_number }}"
272+
echo "nginx-agent-binaries-${{ inputs.packageVersion }}-arm64"
273+
find build/arm64 -type f -name "nginx-agent*"
274+
echo "nginx-agent-binaries-${{ inputs.packageVersion }}-amd64"
275+
find build/amd64 -type f -name "nginx-agent*"
245276
246277
- name: Get Id Token
247278
if: ${{ inputs.publishPackages == true }}
@@ -252,14 +283,31 @@ jobs:
252283
let id_token = await core.getIDToken()
253284
core.setOutput('id_token', id_token)
254285
255-
- name: Publish Release Packages
286+
- name: Upload Release Packages to NGINX repo
256287
if: ${{ inputs.publishPackages == true }}
257288
env:
258289
TOKEN: ${{ steps.idtoken.outputs.id_token }}
259290
UPLOAD_URL: ${{ inputs.uploadUrl }}
260291
run: |
261292
make release
262293
294+
assertion-document:
295+
name: Build and Generate Assertion Document
296+
needs: [build-and-upload-packages]
297+
if : ${{ inputs.assertionDoc == true }}
298+
uses: ./.github/workflows/assertion.yml
299+
permissions:
300+
id-token: write
301+
contents: read
302+
with:
303+
packageVersion: ${{ inputs.packageVersion }}
304+
runId: ${{ github.run_id }}
305+
secrets:
306+
ARTIFACTORY_USER: ${{ secrets.ARTIFACTORY_USER }}
307+
ARTIFACTORY_TOKEN: ${{ secrets.ARTIFACTORY_TOKEN }}
308+
ARTIFACTORY_URL: ${{ secrets.ARTIFACTORY_URL }}
309+
310+
263311
merge-release:
264312
if: ${{ needs.vars.outputs.create_pull_request == 'true' }}
265313
name: Merge release branch back into main branch
@@ -286,6 +334,6 @@ jobs:
286334
base: 'main',
287335
body: [
288336
'This PR was auto-generated by the release workflow.',
289-
'NOTE: DO NOT squash commits when merging!!',
337+
'NOTE: DO NOT squash commits when merging!',
290338
].join('\n')
291339
});

Makefile.packaging

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,27 @@ $(PACKAGES_DIR):
3636

3737
.PHONY: package
3838
package: gpg-key $(PACKAGES_DIR) #### Create final packages for all supported distros
39-
4039
# Build binaries for all supported architectures
4140
@for arch in $(DEB_ARCHS); do \
4241
mkdir -p $(BUILD_DIR)/$${arch}; \
4342
cp .nfpm.yaml .nfpm.$${arch}.yaml; \
4443
sed -i.bak "s/\^ARCH\^/$${arch}/g" ".nfpm.$${arch}.yaml"; \
4544
sed -i.bak "s/\^BUILD_PATH\^/\.\/build\/$${arch}/g" ".nfpm.$${arch}.yaml"; \
4645
echo "Building linux/$${arch}"; \
46+
start_time=$$(date +%s); \
4747
GOWORK=off CGO_ENABLED=0 GOARCH=$${arch} GOOS=linux \
4848
go build -pgo=auto -ldflags=${LDFLAGS} \
4949
-o $(BUILD_DIR)/$${arch}/$(BINARY_NAME) \
5050
$(PROJECT_DIR)/$(PROJECT_FILE); \
51-
rm -f .nfpm.$$arch.yaml.bak; \
51+
end_time=$$(date +%s); \
52+
rm -f .nfpm.$${arch}.yaml.bak; \
53+
sha256sum build/$${arch}/nginx-agent | awk '{print $$1}' > $(BUILD_DIR)/$${arch}/$(BINARY_NAME).sha256; \
54+
echo $${start_time} > $(BUILD_DIR)/$${arch}/$(BINARY_NAME).buildstart; \
55+
echo $${end_time} > $(BUILD_DIR)/$${arch}/$(BINARY_NAME).buildend; \
56+
echo "Built binary:"; \
5257
ls -la "$(BUILD_DIR)/$${arch}/$(BINARY_NAME)"; \
58+
cat $(BUILD_DIR)/$${arch}/$(BINARY_NAME).sha256; \
59+
echo "Built took "$$((end_time - start_time))" seconds"; \
5360
done; \
5461

5562
# Create deb packages
@@ -138,9 +145,9 @@ package: gpg-key $(PACKAGES_DIR) #### Create final packages for all supported di
138145
# Create tarball containing all packages
139146
@echo "Creating tarball: $(TARBALL_NAME)"; \
140147
rm -f $(PACKAGES_DIR)/$(TARBALL_NAME); \
141-
pushd $(PACKAGES_DIR) > /dev/null; \
148+
cd $(PACKAGES_DIR); \
142149
tar -czvf "./$(TARBALL_NAME)" *; \
143-
popd > /dev/null; \
150+
cd ../.. \
144151
ls -la $(PACKAGES_DIR)/$(TARBALL_NAME);
145152

146153
.PHONY: gpg-key

0 commit comments

Comments
 (0)