Skip to content

Commit 8aee103

Browse files
authored
Add GoReleaser, create SBOMs and upload artifacts to Azure (#171)
1 parent ccfc8b9 commit 8aee103

File tree

4 files changed

+88
-12
lines changed

4 files changed

+88
-12
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ concurrency:
2727
group: ${{ github.ref_name }}-ci
2828
cancel-in-progress: true
2929

30+
env:
31+
platforms: "linux/arm64, linux/amd64"
32+
3033
jobs:
3134

3235
vars:
@@ -36,19 +39,22 @@ jobs:
3639
sha: ${{ steps.vars.outputs.sha }}
3740
version: ${{ steps.vars.outputs.version }}
3841
date: ${{ steps.vars.outputs.date }}
42+
go_path: ${{ steps.vars.outputs.go_path }}
3943
steps:
4044
- name: Checkout Repository
4145
uses: actions/checkout@v3
46+
- name: Setup Golang Environment
47+
uses: actions/setup-go@v3
48+
with:
49+
go-version-file: go.mod
50+
cache: true
4251
- name: Output Variables
4352
id: vars
4453
run: |
4554
echo "::set-output name=sha::$(echo ${GITHUB_SHA} | cut -c1-7)"
4655
echo "::set-output name=version::$(grep "VERSION = " Makefile | cut -d " " -f 3)"
4756
echo "::set-output name=date::$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
48-
- name: Setup Golang Environment
49-
uses: actions/setup-go@v3
50-
with:
51-
go-version-file: go.mod
57+
echo "::set-output name=go_path::$(go env GOPATH)"
5258
- name: Check if CRDs changed
5359
run: |
5460
make update-crds && git diff --name-only --exit-code deploy/manifests/crds/*
@@ -64,6 +70,7 @@ jobs:
6470
uses: actions/setup-go@v3
6571
with:
6672
go-version-file: go.mod
73+
cache: true
6774
- name: Run Tests
6875
run: make unit-test
6976
- name: Upload Coverage Report
@@ -94,16 +101,33 @@ jobs:
94101
steps:
95102
- name: Checkout Repository
96103
uses: actions/checkout@v3
104+
with:
105+
fetch-depth: 0
97106
- name: Setup Golang Environment
98107
uses: actions/setup-go@v3
99108
with:
100109
go-version-file: go.mod
101-
- name: Build Binary
102-
run: make build
110+
cache: true
111+
112+
- name: Download Syft
113+
uses: anchore/sbom-action/download-syft@v0.11.0
114+
115+
- name: Build binary
116+
uses: goreleaser/goreleaser-action@v3
117+
with:
118+
version: latest
119+
args: ${{ startsWith(github.ref, 'refs/tags/') && 'release' || 'build --snapshot' }} --rm-dist
120+
env:
121+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
122+
GOPATH: ${{ needs.vars.outputs.go_path }}
123+
AZURE_STORAGE_ACCOUNT: ${{ secrets.AZURE_STORAGE_ACCOUNT }}
124+
AZURE_STORAGE_KEY: ${{ secrets.AZURE_STORAGE_KEY }}
125+
AZURE_BUCKET_NAME: ${{ secrets.AZURE_BUCKET_NAME }}
126+
103127
- name: Cache Artifacts
104128
uses: actions/cache@v3
105129
with:
106-
path: ${{ github.workspace }}/build/.out/gateway
130+
path: ${{ github.workspace }}/dist
107131
key: nginx-kubernetes-gateway-${{ github.run_id }}-${{ github.run_number }}
108132

109133
build:
@@ -116,10 +140,14 @@ jobs:
116140
- name: Fetch Cached Artifacts
117141
uses: actions/cache@v3
118142
with:
119-
path: ${{ github.workspace }}/build/.out/gateway
143+
path: ${{ github.workspace }}/dist
120144
key: nginx-kubernetes-gateway-${{ github.run_id }}-${{ github.run_number }}
121145
- name: Docker Buildx
122146
uses: docker/setup-buildx-action@v2
147+
- name: Setup QEMU
148+
uses: docker/setup-qemu-action@v2
149+
with:
150+
platforms: arm64
123151
- name: Login to GitHub Container Registry
124152
uses: docker/login-action@v2
125153
if: ${{ startsWith(github.ref, 'refs/tags') }}
@@ -138,17 +166,16 @@ jobs:
138166
type=edge
139167
type=ref,event=pr
140168
type=ref,event=branch,enable=${{ startsWith(github.ref, 'refs/heads/release') }}
141-
flavor: |
142-
latest=true
143-
- name: Build Image Debian
169+
- name: Build Docker Image
144170
uses: docker/build-push-action@v3
145171
with:
146172
file: build/Dockerfile
147173
context: '.'
148-
target: local
174+
target: goreleaser
149175
tags: ${{ steps.meta.outputs.tags }}
150176
load: ${{ !startsWith(github.ref, 'refs/tags') }}
151177
push: ${{ startsWith(github.ref, 'refs/tags') }}
178+
platforms: ${{ startsWith(github.ref, 'refs/tags') && env.platforms || '' }}
152179
cache-from: type=gha
153180
cache-to: type=gha,mode=max
154181
build-args: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ cover.html
2525

2626
# Binary and Artifacts
2727
build/.out
28+
dist/
2829

2930
# Node modules
3031
node_modules/

.goreleaser.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
env:
2+
- CGO_ENABLED=0
3+
4+
builds:
5+
- id: gateway
6+
goos:
7+
- linux
8+
goarch:
9+
- amd64
10+
- arm64
11+
flags:
12+
- -trimpath
13+
gcflags:
14+
- all=-trimpath={{.Env.GOPATH}}
15+
asmflags:
16+
- all=-trimpath={{.Env.GOPATH}}
17+
main: ./cmd/gateway/
18+
binary: gateway
19+
20+
changelog:
21+
skip: true
22+
23+
checksum:
24+
name_template: 'checksums.txt'
25+
26+
archives:
27+
- id: gateway
28+
29+
sboms:
30+
- artifacts: archive
31+
32+
release:
33+
ids: [gateway]
34+
35+
blobs:
36+
- provider: azblob
37+
bucket: '{{.Env.AZURE_BUCKET_NAME}}'
38+
extra_files:
39+
- glob: ./dist/**.sbom

build/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1.4
12
FROM golang:1.19 as builder
23
ARG VERSION
34
ARG GIT_COMMIT
@@ -24,6 +25,11 @@ FROM capabilizer as container-capabilizer
2425
COPY --from=builder /go/src/github.com/nginxinc/nginx-kubernetes-gateway/cmd/gateway/gateway /usr/bin/
2526
RUN setcap 'cap_kill=+ep' /usr/bin/gateway
2627

28+
FROM capabilizer as goreleaser-capabilizer
29+
ARG TARGETARCH
30+
COPY dist/gateway_linux_$TARGETARCH*/gateway /usr/bin/
31+
RUN setcap 'cap_kill=+ep' /usr/bin/gateway
32+
2733
FROM scratch as common
2834
USER 1001:1001
2935
ENTRYPOINT [ "/usr/bin/gateway" ]
@@ -33,3 +39,6 @@ COPY --from=container-capabilizer /usr/bin/gateway /usr/bin/
3339

3440
FROM common as local
3541
COPY --from=local-capabilizer /usr/bin/gateway /usr/bin/
42+
43+
FROM common as goreleaser
44+
COPY --from=goreleaser-capabilizer /usr/bin/gateway /usr/bin/

0 commit comments

Comments
 (0)