Skip to content
This repository was archived by the owner on May 24, 2023. It is now read-only.

Commit 186221a

Browse files
authored
Add GoReleaser (#70)
Adds GoReleaser and multi-arch support
1 parent ce19f61 commit 186221a

File tree

7 files changed

+120
-29
lines changed

7 files changed

+120
-29
lines changed

.github/workflows/ci.yml

Lines changed: 75 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
name: Continuous Integration
1+
name: CI
22

33
on:
44
push:
55
branches:
66
- main
77
paths-ignore:
88
- '**.md'
9+
tags:
10+
- 'v[0-9]+.[0-9]+.[0-9]+*'
911
pull_request:
1012
branches:
1113
- main
@@ -15,12 +17,9 @@ on:
1517
- synchronize
1618
paths-ignore:
1719
- '**.md'
18-
create:
19-
tags:
20-
- 'v[0-9]+.[0-9]+.[0-9]+*'
2120

2221
env:
23-
DOCKER_BUILDKIT: 1
22+
DOCKER_PLATFORMS: "linux/arm64,linux/amd64,linux/ppc64le,linux/s390x,linux/386"
2423

2524
jobs:
2625

@@ -30,32 +29,25 @@ jobs:
3029
steps:
3130
- name: Checkout Repository
3231
uses: actions/checkout@v3
33-
- name: Determine Go version from go.mod
34-
run: echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
3532
- name: Setup Golang Environment
3633
uses: actions/setup-go@v3
3734
with:
38-
go-version: ${{ env.GO_VERSION }}
35+
go-version-file: go.mod
36+
cache: true
3937
- name: Build Binary
4038
run: make nginx-ns1-gslb
41-
- name: Cache Artifacts
42-
uses: actions/cache@v3
43-
with:
44-
path: ${{ github.workspace }}/nginx-ns1-gslb
45-
key: nginx-ns1-gslb-${{ github.run_id }}-${{ github.run_number }}
4639

4740
unit-tests:
4841
name: Unit Tests
4942
runs-on: ubuntu-20.04
5043
steps:
5144
- name: Checkout Repository
5245
uses: actions/checkout@v3
53-
- name: Determine Go version from go.mod
54-
run: echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
5546
- name: Setup Golang Environment
5647
uses: actions/setup-go@v3
5748
with:
58-
go-version: ${{ env.GO_VERSION }}
49+
go-version-file: go.mod
50+
cache: true
5951
- name: Run Tests
6052
run: make test
6153

@@ -66,19 +58,80 @@ jobs:
6658
steps:
6759
- name: Checkout Repository
6860
uses: actions/checkout@v3
69-
- name: Fetch Cached Artifacts
70-
uses: actions/cache@v3
7161
with:
72-
path: ${{ github.workspace }}/nginx-ns1-gslb
73-
key: nginx-ns1-gslb-${{ github.run_id }}-${{ github.run_number }}
62+
fetch-depth: 0
63+
- name: Setup Golang Environment
64+
uses: actions/setup-go@v3
65+
with:
66+
go-version-file: go.mod
67+
cache: true
68+
- name: Determine GOPATH
69+
id: go
70+
run: echo "::set-output name=go_path::$(go env GOPATH)"
71+
72+
- name: Setup QEMU
73+
uses: docker/setup-qemu-action@v2
74+
with:
75+
platforms: arm64,ppc64le,s390x,386
76+
if: github.event_name != 'pull_request'
77+
78+
- name: Login to GitHub Container Registry
79+
uses: docker/login-action@v2
80+
with:
81+
registry: ghcr.io
82+
username: ${{ github.repository_owner }}
83+
password: ${{ secrets.GITHUB_TOKEN }}
84+
if: github.event_name != 'pull_request'
85+
86+
- name: Publish Release Notes
87+
uses: release-drafter/release-drafter@v5
88+
with:
89+
publish: true
90+
env:
91+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
93+
94+
- name: Download Syft
95+
uses: anchore/sbom-action/[email protected]
96+
97+
- name: Run GoReleaser
98+
uses: goreleaser/goreleaser-action@v3
99+
with:
100+
version: latest
101+
args: ${{ !startsWith(github.ref, 'refs/tags/') && 'build --snapshot' || 'release' }} ${{ github.event_name == 'pull_request' && '--single-target' || '' }} --rm-dist
102+
env:
103+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
104+
GOPATH: ${{ steps.go.outputs.go_path }}
105+
106+
- name: Docker meta
107+
id: meta
108+
uses: docker/metadata-action@v4
109+
with:
110+
images: |
111+
ghcr.io/nginxinc/nginx-ns1-gslb
112+
tags: |
113+
type=edge
114+
type=ref,event=pr
115+
type=semver,pattern={{version}}
116+
type=semver,pattern={{major}}.{{minor}}
117+
labels: |
118+
org.opencontainers.image.vendor=NGINX Inc <[email protected]>
119+
74120
- name: Docker Buildx
75121
uses: docker/setup-buildx-action@v2
122+
76123
- name: Build Image
77124
uses: docker/build-push-action@v3
78125
with:
79126
file: build/Dockerfile
80127
context: '.'
81-
target: local
128+
target: goreleaser
129+
platforms: ${{ github.event_name != 'pull_request' && env.DOCKER_PLATFORMS || '' }}
130+
load: ${{ github.event_name == 'pull_request' }}
131+
push: ${{ github.event_name != 'pull_request' }}
132+
pull: true
133+
no-cache: ${{ github.event_name != 'pull_request' }}
82134
cache-from: type=gha
83135
cache-to: type=gha,mode=max
84-
tags: nginx/nginx-ns1-gslb:${{ github.sha }}
136+
tags: ${{ steps.meta.outputs.tags }}
137+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/lint.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ jobs:
2323
steps:
2424
- name: Checkout Repository
2525
uses: actions/checkout@v3
26-
- name: Output Variables
27-
id: vars
28-
run: echo "::set-output name=go_version::$(grep "go 1." go.mod | cut -d " " -f 2)"
2926
- name: Setup Golang Environment
3027
uses: actions/setup-go@v3
3128
with:
32-
go-version: ${{ steps.vars.outputs.go_version }}
29+
go-version-file: go.mod
30+
cache: true
3331
- name: Lint Code
3432
uses: golangci/golangci-lint-action@v3

.github/workflows/notifications.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_run:
55
branches: main
66
workflows:
7-
- "Continuous Integration"
7+
- "CI"
88
- "CodeQL"
99
- "Fossa"
1010
- "Lint"

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ default.pem
3636

3737
# Binary
3838
nginx-ns1-gslb
39+
dist
3940

4041
# Development configuration file
41-
dev_config.yaml
42+
dev_config.yaml

.goreleaser.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
env:
2+
- CGO_ENABLED=0
3+
4+
builds:
5+
- id: nginx-ns1-gslb
6+
goos:
7+
- linux
8+
goarch:
9+
- 386
10+
- amd64
11+
- arm64
12+
- s390x
13+
- ppc64le
14+
flags:
15+
- -trimpath
16+
gcflags:
17+
- all=-trimpath={{.Env.GOPATH}}
18+
asmflags:
19+
- all=-trimpath={{.Env.GOPATH}}
20+
main: ./cmd/agent
21+
binary: nginx-ns1-gslb
22+
23+
sboms:
24+
- artifacts: archive
25+
26+
changelog:
27+
skip: true
28+
29+
checksum:
30+
name_template: 'sha256sums.txt'

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# NGINX Plus - NS1 Global Server Load Balancing
2-
[![Continuous Integration](https://github.com/nginxinc/nginx-ns1-gslb/actions/workflows/ci.yml/badge.svg)](https://github.com/nginxinc/nginx-ns1-gslb/actions/workflows/ci.yml)
2+
[![CI](https://github.com/nginxinc/nginx-ns1-gslb/actions/workflows/ci.yml/badge.svg)](https://github.com/nginxinc/nginx-ns1-gslb/actions/workflows/ci.yml)
33
[![FOSSA Status](https://app.fossa.com/api/projects/custom%2B5618%2Fgithub.com%2Fnginxinc%2Fnginx-ns1-gslb.svg?type=shield)](https://app.fossa.com/projects/custom%2B5618%2Fgithub.com%2Fnginxinc%2Fnginx-ns1-gslb?ref=badge_shield)
44
[![Go Report Card](https://goreportcard.com/badge/github.com/nginxinc/nginx-ns1-gslb)](https://goreportcard.com/report/github.com/nginxinc/nginx-ns1-gslb)
55

build/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,12 @@ COPY --from=builder /nginx-ns1-gslb /
2222

2323
FROM base AS local
2424
COPY nginx-ns1-gslb /
25+
26+
FROM base AS goreleaser
27+
ARG TARGETARCH
28+
ARG TARGETPLATFORM
29+
30+
LABEL org.nginx.ns1-gslb.image.build.target="${TARGETPLATFORM}"
31+
LABEL org.nginx.ns1-gslb.image.build.version="goreleaser"
32+
33+
COPY dist/nginx-ns1-gslb_linux_$TARGETARCH*/nginx-ns1-gslb /

0 commit comments

Comments
 (0)