Skip to content

Commit 223bc06

Browse files
authored
Add assertions document to binary build workflow (#8336)
1 parent 77691db commit 223bc06

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

.github/scripts/binary-json.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
5+
path=${1:-dist/}
6+
project=${2:-kubernetes-ingress}
7+
binary_name=${3:-nginx-ingress}
8+
9+
if [ -z "$path" ] || [ -z "$project" ]; then
10+
echo "Usage: $0 <path> <project>"
11+
exit 1
12+
fi
13+
14+
15+
json='[]'
16+
for bin in $(find "$path" -type f -name "$binary_name"); do
17+
dir=$(basename "$(dirname $bin)")
18+
if [[ "$dir" =~ ${project}_([a-zA-Z0-9]+)_([a-zA-Z0-9]+) ]]; then
19+
os="${BASH_REMATCH[1]}"
20+
arch="${BASH_REMATCH[2]}"
21+
digest=$(sha256sum "$bin" | cut -d' ' -f1)
22+
json=$(echo "$json" | jq -c --arg path "$bin" --arg os "$os" --arg arch "$arch" --arg digest "$digest" '. += [{"path": $path, "os": $os, "arch": $arch, "digest": $digest}]')
23+
fi
24+
done
25+
echo "$json"

.github/workflows/build-artifacts.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ jobs:
5858
permissions:
5959
contents: read
6060
id-token: write
61+
outputs:
62+
json: ${{ steps.nic_binaries.outputs.json }}
6163
steps:
6264
- name: Checkout Repository
6365
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
@@ -100,13 +102,94 @@ jobs:
100102
GORELEASER_CURRENT_TAG: "v${{ inputs.ic-version }}"
101103
if: ${{ inputs.force }}
102104

105+
- name: Extract NGINX Ingress Controller binary info
106+
id: nic_binaries
107+
run: |
108+
echo "json=$(.github/scripts/binary-json.sh ${{ github.workspace }}/dist ${{ github.event.repository.name }} "nginx-ingress")" >> $GITHUB_OUTPUT
109+
if: ${{ inputs.force }}
110+
103111
- name: Store Artifacts in Cache
104112
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
105113
with:
106114
path: ${{ github.workspace }}/dist
107115
key: nginx-ingress-${{ inputs.go-md5 }}
108116
if: ${{ inputs.force }}
109117

118+
generate-assertion-doc:
119+
if: ${{ inputs.force }}
120+
name: Assertion Doc ${{ matrix.nic.arch }}
121+
needs: [binaries]
122+
runs-on: ${{ inputs.runner }}
123+
permissions:
124+
contents: read
125+
id-token: write # for compliance-rules action to sign assertion doc
126+
strategy:
127+
fail-fast: false
128+
matrix:
129+
nic: ${{ fromJSON( needs.binaries.outputs.json ) }}
130+
steps:
131+
- name: Checkout Repository
132+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
133+
with:
134+
ref: ${{ inputs.branch }}
135+
136+
- name: Setup Golang Environment
137+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
138+
with:
139+
go-version-file: go.mod
140+
141+
- name: Setup netrc
142+
run: |
143+
cat <<EOF > $HOME/.netrc
144+
machine azr.artifactory.f5net.com
145+
login ${{ secrets.ARTIFACTORY_USER }}
146+
password ${{ secrets.ARTIFACTORY_TOKEN }}
147+
EOF
148+
chmod 600 $HOME/.netrc
149+
150+
- name: Fetch Cached Artifacts
151+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
152+
with:
153+
path: ${{ github.workspace }}/dist
154+
key: nginx-ingress-${{ inputs.go-md5 }}
155+
fail-on-cache-miss: true
156+
157+
- name: List packages in Go binary
158+
id: godeps
159+
env:
160+
GOPATH: ${{ inputs.go-path }}
161+
GOPROXY: ${{ inputs.go-proxy }}
162+
run: |
163+
go version -m ${{ matrix.nic.path }} > go_version_out_${{ github.run_id }}_${{ github.run_number }}.txt
164+
echo "go_version_out=$(find -type f -name "go_version_out*.txt" | head -n 1)" >> $GITHUB_OUTPUT
165+
echo "artifact_digest=$(openssl dgst -sha256 -r ${{ matrix.nic.path }} | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT
166+
cat $GITHUB_OUTPUT
167+
168+
- name: Generate Assertion Document
169+
id: assertiondoc
170+
uses: nginxinc/compliance-rules/.github/actions/assertion@83e452166aaf0ad8f07caf91a4f1f903b3dea1e6 # v0.3.0
171+
with:
172+
artifact-name: "${{ github.event.repository.name }}_${{ github.sha }}_${{ github.run_number }}_${{ matrix.nic.os }}_${{ matrix.nic.arch }}"
173+
artifact-digest: ${{ steps.godeps.outputs.artifact_digest }}
174+
build-type: "github.com"
175+
builder-id: "github"
176+
builder-version: v0.1.0
177+
started-on: ${{ github.event.head_commit.timestamp || github.event.created_at }}
178+
finished-on: ${{ github.event.head_commit.timestamp || github.event.created_at }}
179+
invocation-id: ${{ github.run_id }}.${{ github.run_number }}.${{ github.run_attempt }}
180+
artifactory-user: ${{ secrets.ARTIFACTORY_USER }}
181+
artifactory-api-token: ${{ secrets.ARTIFACTORY_TOKEN }}
182+
artifactory-url: ${{ secrets.ARTIFACTORY_URL }}
183+
artifactory-repo: 'f5-nginx-go-local-approved-dependency'
184+
assertion-doc-file: assertion_${{ github.event.repository.name }}_${{ github.sha }}_${{ github.run_id }}_${{ github.run_number }}_${{ matrix.nic.os }}_${{ matrix.nic.arch }}.json
185+
build-content-path: ${{ steps.godeps.outputs.go_version_out }}
186+
187+
- name: Sign and Store Assertion Document
188+
id: sign
189+
uses: nginxinc/compliance-rules/.github/actions/sign@83e452166aaf0ad8f07caf91a4f1f903b3dea1e6 # v0.3.0
190+
with:
191+
assertion-doc: ${{ steps.assertiondoc.outputs.assertion-document-path }}
192+
110193
build-docker:
111194
name: Build Docker OSS
112195
needs: [binaries]

0 commit comments

Comments
 (0)