Skip to content

Commit 052e0fb

Browse files
committed
Build packages for multiple architectures
1 parent 90c9f48 commit 052e0fb

30 files changed

+226
-6332
lines changed

.github/workflows/ci.yml

+55-94
Original file line numberDiff line numberDiff line change
@@ -19,132 +19,93 @@ on:
1919
tags:
2020
- 'v[0-9]+.[0-9]+.[0-9]+*'
2121

22-
env:
23-
DOCKER_BUILDKIT: 1
24-
2522
jobs:
23+
vars:
24+
name: Checks and variables
25+
runs-on: ubuntu-20.04
26+
outputs:
27+
go_version: ${{ steps.vars.outputs.go_version }}
28+
steps:
29+
- name: Checkout Repository
30+
uses: actions/checkout@v3
31+
- name: Output Variables
32+
id: vars
33+
run: |
34+
echo "::set-output name=go_version::$(grep "go 1." go.mod | cut -d " " -f 2)"
2635
2736
binary:
2837
name: Build Binary
2938
runs-on: ubuntu-20.04
39+
needs: vars
3040
steps:
3141
- name: Checkout Repository
3242
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
43+
- name: Cache Go build
44+
uses: actions/cache@v3
45+
with:
46+
path: |
47+
~/.cache/go-build
48+
~/go/pkg/mod
49+
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
50+
restore-keys: |
51+
${{ runner.os }}-go-build-
3552
- name: Setup Golang Environment
3653
uses: actions/setup-go@v3
3754
with:
38-
go-version: ${{ env.GO_VERSION }}
39-
- name: Build Binary
40-
run: make build
41-
- name: Store Artifacts in Cache
42-
uses: actions/cache@v3
55+
go-version: ${{ needs.checks.outputs.go_version }}
56+
- name: Build binary
57+
uses: goreleaser/goreleaser-action@v3
4358
with:
44-
path: ${{ github.workspace }}/nginx-asg-sync
45-
key: nginx-asg-sync-${{ github.run_id }}-${{ github.run_number }}
59+
version: latest
60+
args: build --snapshot --rm-dist --single-target
61+
env:
62+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
GOPATH: ${{ needs.checks.outputs.go_path }}
4664

4765
unit-tests:
4866
name: Unit Tests
4967
runs-on: ubuntu-20.04
68+
needs: vars
5069
steps:
5170
- name: Checkout Repository
5271
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
5572
- name: Setup Golang Environment
5673
uses: actions/setup-go@v3
5774
with:
58-
go-version: ${{ env.GO_VERSION }}
75+
go-version: ${{ needs.vars.outputs.go_version }}
5976
- name: Run Tests
6077
run: make test
6178

6279
build:
63-
name: Build Image
80+
name: Build Packages
6481
runs-on: ubuntu-20.04
6582
needs: [binary, unit-tests]
6683
steps:
6784
- name: Checkout Repository
6885
uses: actions/checkout@v3
69-
- name: Fetch Cached Artifacts
70-
uses: actions/cache@v3
7186
with:
72-
path: ${{ github.workspace }}/nginx-asg-sync
73-
key: nginx-asg-sync-${{ github.run_id }}-${{ github.run_number }}
74-
- name: Docker Buildx
75-
uses: docker/setup-buildx-action@v2
76-
- name: Build Image Amazon 2
77-
uses: docker/build-push-action@v3
78-
with:
79-
file: build/Dockerfile
80-
context: '.'
81-
target: local
82-
load: true
83-
cache-from: type=gha
84-
cache-to: type=gha,mode=max
85-
tags: amazon2-builder:${{ github.sha }}
86-
build-args: |
87-
CONTAINER_VERSION=amazonlinux:2
88-
OS_TYPE=rpm_based
89-
- name: Run Amazon 2
90-
uses: addnab/docker-run-action@v3
91-
with:
92-
image: amazon2-builder:${{ github.sha }}
93-
run: /build.sh
94-
options: -v ${{ github.workspace }}/build/package/rpm:/rpm -v ${{ github.workspace }}/build_output:/build_output
95-
- name: Build Image Centos 7
96-
uses: docker/build-push-action@v3
97-
with:
98-
file: build/Dockerfile
99-
context: '.'
100-
target: local
101-
load: true
102-
cache-from: type=gha
103-
cache-to: type=gha,mode=max
104-
tags: centos7-builder:${{ github.sha }}
105-
build-args: |
106-
CONTAINER_VERSION=centos:7
107-
OS_TYPE=rpm_based
108-
- name: Run Centos 7
109-
uses: addnab/docker-run-action@v3
110-
with:
111-
image: centos7-builder:${{ github.sha }}
112-
run: /build.sh
113-
options: -v ${{ github.workspace }}/build/package/rpm:/rpm -v ${{ github.workspace }}/build_output:/build_output
114-
- name: Build Image Centos stream 8
115-
uses: docker/build-push-action@v3
116-
with:
117-
file: build/Dockerfile
118-
context: '.'
119-
target: local
120-
load: true
121-
cache-from: type=gha
122-
cache-to: type=gha,mode=max
123-
tags: centosstream8-builder:${{ github.sha }}
124-
build-args: |
125-
CONTAINER_VERSION=quay.io/centos/centos:stream8
126-
OS_TYPE=rpm_based
127-
- name: Run Centos stream 8
128-
uses: addnab/docker-run-action@v3
87+
fetch-depth: 0
88+
- name: Cache Go build
89+
uses: actions/cache@v3
12990
with:
130-
image: centosstream8-builder:${{ github.sha }}
131-
run: /build.sh
132-
options: -v ${{ github.workspace }}/build/package/rpm:/rpm -v ${{ github.workspace }}/build_output:/build_output
133-
- name: Build Image Debian
134-
uses: docker/build-push-action@v3
91+
path: |
92+
~/.cache/go-build
93+
~/go/pkg/mod
94+
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
95+
restore-keys: |
96+
${{ runner.os }}-go-build-
97+
- name: Determine GOPATH
98+
id: go
99+
run: echo "::set-output name=go_path::$(go env GOPATH)"
100+
- name: Setup Golang Environment
101+
uses: actions/setup-go@v3
135102
with:
136-
file: build/Dockerfile
137-
context: '.'
138-
target: local
139-
load: true
140-
cache-from: type=gha
141-
cache-to: type=gha,mode=max
142-
tags: debian-builder:${{ github.sha }}
143-
build-args: |
144-
OS_TYPE=deb_based
145-
- name: Run Debian
146-
uses: addnab/docker-run-action@v3
103+
go-version: ${{ needs.vars.outputs.go_version }}
104+
- name: Build binaries
105+
uses: goreleaser/goreleaser-action@v3
147106
with:
148-
image: debian-builder:${{ github.sha }}
149-
run: /build.sh
150-
options: -v ${{ github.workspace }}/build/package/debian:/debian -v ${{ github.workspace }}/build_output:/build_output
107+
version: latest
108+
args: release ${{ startsWith(github.ref, 'refs/tags/') && '' || '--snapshot' }} --rm-dist
109+
env:
110+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111+
GOPATH: ${{ needs.checks.outputs.go_path }}

.gitignore

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
/build_output
21
.DS_Store
2+
3+
# binaries
34
nginx-asg-sync
5+
/build_output
6+
dist
7+
8+
# IDEs
9+
.vscode
10+
.idea

.goreleaser.yml

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
env:
2+
- CGO_ENABLED=0
3+
4+
before:
5+
hooks:
6+
- make deps
7+
- make LICENSES
8+
9+
builds:
10+
- id: nginx-asg-sync
11+
goos:
12+
- linux
13+
goarch:
14+
- 386
15+
- amd64
16+
- arm64
17+
- s390x
18+
flags:
19+
- -trimpath
20+
gcflags:
21+
- all=-trimpath={{.Env.GOPATH}}
22+
asmflags:
23+
- all=-trimpath={{.Env.GOPATH}}
24+
main: ./cmd/sync
25+
binary: nginx-asg-sync
26+
27+
archives:
28+
- files:
29+
- README.md
30+
- LICENSE
31+
- CHANGELOG.md
32+
- build/config.yaml.example
33+
34+
sboms:
35+
- artifacts: archive
36+
37+
changelog:
38+
skip: true
39+
40+
nfpms:
41+
- file_name_template: "{{ .ConventionalFileName }}"
42+
vendor: NGINX Inc.
43+
homepage: https://github.com/nginxinc/nginx-asg-sync
44+
maintainer: NGINX Inc. <[email protected]>
45+
description: |-
46+
NGINX Plus Integration with Cloud Autoscaling.
47+
This package contains software that integrates NGINX Plus
48+
with AWS Auto Scaling groups and Azure Virtual Machine Scale Set
49+
license: BSD-2-Clause
50+
dependencies:
51+
- nginx-plus
52+
- systemd
53+
suggests:
54+
- logrotate
55+
formats:
56+
- deb
57+
- rpm
58+
release: 1
59+
section: utils
60+
priority: optional
61+
bindir: /usr/sbin
62+
contents:
63+
- src: build/config.yaml.example
64+
dst: /etc/nginx/config.yaml.example
65+
type: "config|noreplace"
66+
- src: build/logrotate
67+
dst: /etc/logrotate.d/nginx-asg-sync
68+
type: "config|noreplace"
69+
- dst: /var/log/nginx-asg-sync
70+
type: dir
71+
- src: build/nginx-asg-sync.service
72+
dst: /lib/systemd/system/nginx-asg-sync.service
73+
- src: LICENSE
74+
dst: /usr/share/doc/nginx-asg-sync/copyright
75+
packager: deb
76+
- src: LICENSES
77+
dst: /usr/share/doc/nginx-asg-sync/LICENSES
78+
packager: deb
79+
- src: LICENSE
80+
dst: /usr/share/licenses/nginx-asg-sync/LICENSE
81+
packager: rpm
82+
- src: LICENSES
83+
dst: /usr/share/licenses/nginx-asg-sync/LICENSES
84+
packager: rpm
85+
- src: README.md
86+
dst: /usr/share/doc/nginx-asg-sync/README
87+
type: doc
88+
overrides:
89+
rpm:
90+
scripts:
91+
postinstall: "build/postinstall.sh"
92+
preremove: "build/preremove.sh"
93+
postremove: "build/postremove.sh"

CODE_OF_CONDUCT.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ further defined and clarified by project maintainers.
5757
## Enforcement
5858

5959
Instances of abusive, harassing, or otherwise unacceptable behavior may be
60-
reported by contacting the project team at [mailto:nginx@nginx.org]. All
60+
reported by contacting the project team at integrations@nginx.com. All
6161
complaints will be reviewed and investigated and will result in a response that
6262
is deemed necessary and appropriate to the circumstances. The project team is
6363
obligated to maintain confidentiality with regard to the reporter of an incident.

LICENSES

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
github.com/Azure/azure-sdk-for-go,https://github.com/Azure/azure-sdk-for-go/blob/v66.0.0/LICENSE.txt,MIT
2+
github.com/Azure/go-autorest/autorest,https://github.com/Azure/go-autorest/blob/autorest/v0.11.24/autorest/LICENSE,Apache-2.0
3+
github.com/Azure/go-autorest/autorest/adal,https://github.com/Azure/go-autorest/blob/autorest/adal/v0.9.18/autorest/adal/LICENSE,Apache-2.0
4+
github.com/Azure/go-autorest/autorest/azure/auth,https://github.com/Azure/go-autorest/blob/autorest/azure/auth/v0.5.11/autorest/azure/auth/LICENSE,Apache-2.0
5+
github.com/Azure/go-autorest/autorest/azure/cli,https://github.com/Azure/go-autorest/blob/autorest/azure/cli/v0.4.5/autorest/azure/cli/LICENSE,Apache-2.0
6+
github.com/Azure/go-autorest/autorest/date,https://github.com/Azure/go-autorest/blob/autorest/date/v0.3.0/autorest/date/LICENSE,Apache-2.0
7+
github.com/Azure/go-autorest/autorest/to,https://github.com/Azure/go-autorest/blob/autorest/to/v0.4.0/autorest/to/LICENSE,Apache-2.0
8+
github.com/Azure/go-autorest/autorest/validation,https://github.com/Azure/go-autorest/blob/autorest/validation/v0.3.1/autorest/validation/LICENSE,Apache-2.0
9+
github.com/Azure/go-autorest/logger,https://github.com/Azure/go-autorest/blob/logger/v0.2.1/logger/LICENSE,Apache-2.0
10+
github.com/Azure/go-autorest/tracing,https://github.com/Azure/go-autorest/blob/tracing/v0.6.0/tracing/LICENSE,Apache-2.0
11+
github.com/aws/aws-sdk-go,https://github.com/aws/aws-sdk-go/blob/v1.44.4/LICENSE.txt,Apache-2.0
12+
github.com/aws/aws-sdk-go/internal/sync/singleflight,https://github.com/aws/aws-sdk-go/blob/v1.44.4/internal/sync/singleflight/LICENSE,BSD-3-Clause
13+
github.com/dimchansky/utfbom,https://github.com/dimchansky/utfbom/blob/v1.1.1/LICENSE,Apache-2.0
14+
github.com/golang-jwt/jwt/v4,https://github.com/golang-jwt/jwt/blob/v4.2.0/LICENSE,MIT
15+
github.com/jmespath/go-jmespath,https://github.com/jmespath/go-jmespath/blob/v0.4.0/LICENSE,Apache-2.0
16+
github.com/mitchellh/go-homedir,https://github.com/mitchellh/go-homedir/blob/v1.1.0/LICENSE,MIT
17+
github.com/nginxinc/nginx-asg-sync/cmd/sync,https://github.com/nginxinc/nginx-asg-sync/blob/HEAD/LICENSE,BSD-2-Clause
18+
github.com/nginxinc/nginx-plus-go-client/client,https://github.com/nginxinc/nginx-plus-go-client/blob/v0.10.0/LICENSE,Apache-2.0
19+
golang.org/x/crypto/pkcs12,https://cs.opensource.google/go/x/crypto/+/e495a2d5:LICENSE,BSD-3-Clause
20+
gopkg.in/yaml.v2,https://github.com/go-yaml/yaml/blob/v2.4.0/LICENSE,Apache-2.0

Makefile

+16-26
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
TARGET ?= local
2-
3-
export DOCKER_BUILDKIT = 1
4-
5-
all: amazon2 centos7 centosstream8 debian
1+
.DEFAULT_GOAL := build-goreleaser
62

73
.PHONY: test
84
test:
@@ -12,38 +8,32 @@ test:
128
lint:
139
docker run --pull always --rm -v $(shell pwd):/nginx-asg-sync -w /nginx-asg-sync -v $(shell go env GOCACHE):/cache/go -e GOCACHE=/cache/go -e GOLANGCI_LINT_CACHE=/cache/go -v $(shell go env GOPATH)/pkg:/go/pkg golangci/golangci-lint:latest golangci-lint --color always run
1410

15-
.PHONY: build
16-
build:
17-
ifeq (${TARGET},local)
18-
$(eval GOPATH=$(shell go env GOPATH))
19-
CGO_ENABLED=0 GOFLAGS="-gcflags=-trimpath=${GOPATH} -asmflags=-trimpath=${GOPATH}" GOOS=linux go build -trimpath -ldflags "-s -w" -o nginx-asg-sync github.com/nginxinc/nginx-asg-sync/cmd/sync
20-
endif
21-
22-
amazon2: build
23-
docker build -t amazon2-builder --target ${TARGET} --build-arg CONTAINER_VERSION=amazonlinux:2 --build-arg OS_TYPE=rpm_based -f build/Dockerfile .
24-
docker run --rm -v $(shell pwd)/build/package/rpm:/rpm -v $(shell pwd)/build_output:/build_output amazon2-builder
11+
nginx-asg-sync:
12+
@go version || (code=$$?; printf "\033[0;31mError\033[0m: unable to build locally, try using the parameter TARGET=container or TARGET=download\n"; exit $$code)
13+
CGO_ENABLED=0 GOFLAGS="-gcflags=-trimpath=$(shell go env GOPATH) -asmflags=-trimpath=$(shell go env GOPATH)" GOOS=linux go build -trimpath -ldflags "-s -w" -o nginx-asg-sync github.com/nginxinc/nginx-asg-sync/cmd/sync
2514

26-
centos7: build
27-
docker build -t centos7-builder --target ${TARGET} --build-arg CONTAINER_VERSION=centos:7 --build-arg OS_TYPE=rpm_based -f build/Dockerfile .
28-
docker run --rm -v $(shell pwd)/build/package/rpm:/rpm -v $(shell pwd)/build_output:/build_output centos7-builder
15+
.PHONY: build-goreleaser
16+
build-goreleaser:
17+
@goreleaser -v || (code=$$?; printf "\033[0;31mError\033[0m: there was a problem with GoReleaser. Follow the docs to install it https://goreleaser.com/install\n"; exit $$code)
18+
@GOPATH=$(shell go env GOPATH) goreleaser release --rm-dist --snapshot
2919

30-
centosstream8: build
31-
docker build -t centosstream8-builder --target ${TARGET} --build-arg CONTAINER_VERSION=quay.io/centos/centos:stream8 --build-arg OS_TYPE=rpm_based -f build/Dockerfile .
32-
docker run --rm -v $(shell pwd)/build/package/rpm:/rpm -v $(shell pwd)/build_output:/build_output centosstream8-builder
33-
34-
debian: build
35-
docker build -t debian-builder --target ${TARGET} --build-arg OS_TYPE=deb_based -f build/Dockerfile .
36-
docker run --rm -v $(shell pwd)/build/package/debian:/debian -v $(shell pwd)/build_output:/build_output debian-builder
20+
.PHONY: build-goreleaser-docker
21+
build-goreleaser-docker:
22+
@docker -v || (code=$$?; printf "\033[0;31mError\033[0m: there was a problem with Docker\n"; exit $$code)
23+
@docker run --rm --privileged -v $(PWD):/go/src/github.com/nginxinc/nginx-asg-sync -v /var/run/docker.sock:/var/run/docker.sock -w /go/src/github.com/nginxinc/nginx-asg-sync goreleaser/goreleaser release --snapshot --rm-dist
3724

3825
.PHONY: clean
3926
clean:
4027
-rm -r build_output
4128
-rm nginx-asg-sync
4229

4330
.PHONY: deps
44-
deps:
31+
deps: go.mod go.sum
4532
@go mod tidy && go mod verify && go mod download
4633

34+
LICENSES: go.mod go.sum
35+
go run github.com/google/go-licenses@latest csv ./... > $@
36+
4737
.PHONY: clean-cache
4838
clean-cache:
4939
@go clean -modcache

0 commit comments

Comments
 (0)