Skip to content

Commit 2d8f5db

Browse files
committed
Build packages for multiple architectures
1 parent 90c9f48 commit 2d8f5db

30 files changed

+225
-6332
lines changed

.github/workflows/ci.yml

Lines changed: 55 additions & 94 deletions
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

Lines changed: 8 additions & 1 deletion
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

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

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 1 deletion
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

Lines changed: 20 additions & 0 deletions
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

Lines changed: 16 additions & 26 deletions
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)