Skip to content

Commit

Permalink
Build packages for multiple architectures (#267)
Browse files Browse the repository at this point in the history
Adds support for multiple architectures and simplifies build process.

Closes #223
  • Loading branch information
lucacome committed Aug 24, 2022
1 parent 69d7852 commit 16bc280
Show file tree
Hide file tree
Showing 32 changed files with 214 additions and 6,342 deletions.
140 changes: 41 additions & 99 deletions .github/workflows/ci.yml
@@ -1,11 +1,13 @@
name: Continuous Integration
name: CI

on:
push:
branches:
- main
paths-ignore:
- '**.md'
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
pull_request:
branches:
- main
Expand All @@ -15,136 +17,76 @@ on:
- synchronize
paths-ignore:
- '**.md'
create:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'

env:
DOCKER_BUILDKIT: 1

jobs:

binary:
name: Build Binary
runs-on: ubuntu-20.04
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Determine Go version from go.mod
run: echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
- name: Setup Golang Environment
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
- name: Build Binary
run: make build
- name: Store Artifacts in Cache
uses: actions/cache@v3
go-version-file: go.mod
cache: true
- name: Determine GOPATH
id: go
run: echo "::set-output name=go_path::$(go env GOPATH)"
- name: Build binary
uses: goreleaser/goreleaser-action@v3
with:
path: ${{ github.workspace }}/nginx-asg-sync
key: nginx-asg-sync-${{ github.run_id }}-${{ github.run_number }}
version: latest
args: build --snapshot --rm-dist --single-target
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOPATH: ${{ steps.go.outputs.go_path }}

unit-tests:
name: Unit Tests
runs-on: ubuntu-20.04
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Determine Go version from go.mod
run: echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
- name: Setup Golang Environment
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
go-version-file: go.mod
cache: true
- name: Run Tests
run: make test

build:
name: Build Image
name: Build Packages
runs-on: ubuntu-20.04
needs: [binary, unit-tests]
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Fetch Cached Artifacts
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/nginx-asg-sync
key: nginx-asg-sync-${{ github.run_id }}-${{ github.run_number }}
- name: Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build Image Amazon 2
uses: docker/build-push-action@v3
with:
file: build/Dockerfile
context: '.'
target: local
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: amazon2-builder:${{ github.sha }}
build-args: |
CONTAINER_VERSION=amazonlinux:2
OS_TYPE=rpm_based
- name: Run Amazon 2
uses: addnab/docker-run-action@v3
with:
image: amazon2-builder:${{ github.sha }}
run: /build.sh
options: -v ${{ github.workspace }}/build/package/rpm:/rpm -v ${{ github.workspace }}/build_output:/build_output
- name: Build Image Centos 7
uses: docker/build-push-action@v3
with:
file: build/Dockerfile
context: '.'
target: local
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: centos7-builder:${{ github.sha }}
build-args: |
CONTAINER_VERSION=centos:7
OS_TYPE=rpm_based
- name: Run Centos 7
uses: addnab/docker-run-action@v3
with:
image: centos7-builder:${{ github.sha }}
run: /build.sh
options: -v ${{ github.workspace }}/build/package/rpm:/rpm -v ${{ github.workspace }}/build_output:/build_output
- name: Build Image Centos stream 8
uses: docker/build-push-action@v3
with:
file: build/Dockerfile
context: '.'
target: local
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: centosstream8-builder:${{ github.sha }}
build-args: |
CONTAINER_VERSION=quay.io/centos/centos:stream8
OS_TYPE=rpm_based
- name: Run Centos stream 8
uses: addnab/docker-run-action@v3
fetch-depth: 0
- name: Setup Golang Environment
uses: actions/setup-go@v3
with:
image: centosstream8-builder:${{ github.sha }}
run: /build.sh
options: -v ${{ github.workspace }}/build/package/rpm:/rpm -v ${{ github.workspace }}/build_output:/build_output
- name: Build Image Debian
uses: docker/build-push-action@v3
go-version-file: go.mod
cache: true
- name: Determine GOPATH
id: go
run: echo "::set-output name=go_path::$(go env GOPATH)"
- name: Publish Release Notes
uses: release-drafter/release-drafter@v5
with:
file: build/Dockerfile
context: '.'
target: local
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: debian-builder:${{ github.sha }}
build-args: |
OS_TYPE=deb_based
- name: Run Debian
uses: addnab/docker-run-action@v3
publish: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ startsWith(github.ref, 'refs/tags/') }}
- name: Download Syft
uses: anchore/sbom-action/download-syft@v0.12.0
- name: Build binaries
uses: goreleaser/goreleaser-action@v3
with:
image: debian-builder:${{ github.sha }}
run: /build.sh
options: -v ${{ github.workspace }}/build/package/debian:/debian -v ${{ github.workspace }}/build_output:/build_output
version: latest
args: release ${{ startsWith(github.ref, 'refs/tags/') && '' || '--snapshot' }} --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOPATH: ${{ steps.go.outputs.go_path }}
6 changes: 2 additions & 4 deletions .github/workflows/lint.yml
Expand Up @@ -24,12 +24,10 @@ jobs:
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Output Variables
id: vars
run: echo "::set-output name=go_version::$(grep "go 1." go.mod | cut -d " " -f 2)"
- name: Setup Golang Environment
uses: actions/setup-go@v3
with:
go-version: ${{ steps.vars.outputs.go_version }}
go-version-file: go.mod
cache: true
- name: Lint Code
uses: golangci/golangci-lint-action@v3
2 changes: 1 addition & 1 deletion .github/workflows/notifications.yml
Expand Up @@ -4,7 +4,7 @@ on:
workflow_run:
branches: main
workflows:
- "Continuous Integration"
- "CI"
- "CodeQL"
- "Fossa"
- "Lint"
Expand Down
9 changes: 8 additions & 1 deletion .gitignore
@@ -1,3 +1,10 @@
/build_output
.DS_Store

# binaries
nginx-asg-sync
/build_output
dist

# IDEs
.vscode
.idea
92 changes: 92 additions & 0 deletions .goreleaser.yml
@@ -0,0 +1,92 @@
env:
- CGO_ENABLED=0

before:
hooks:
- make LICENSES

builds:
- id: nginx-asg-sync
goos:
- linux
goarch:
- 386
- amd64
- arm64
- s390x
flags:
- -trimpath
gcflags:
- all=-trimpath={{.Env.GOPATH}}
asmflags:
- all=-trimpath={{.Env.GOPATH}}
main: ./cmd/sync
binary: nginx-asg-sync

archives:
- files:
- README.md
- LICENSE
- CHANGELOG.md
- build/config.yaml.example

sboms:
- artifacts: archive

changelog:
skip: true

nfpms:
- file_name_template: "{{ .ConventionalFileName }}"
vendor: NGINX Inc.
homepage: https://github.com/nginxinc/nginx-asg-sync
maintainer: NGINX Inc. <integrations@nginx.com>
description: |-
NGINX Plus Integration with Cloud Autoscaling.
This package contains software that integrates NGINX Plus
with AWS Auto Scaling groups and Azure Virtual Machine Scale Set
license: BSD-2-Clause
dependencies:
- nginx-plus
- systemd
suggests:
- logrotate
formats:
- deb
- rpm
release: 1
section: utils
priority: optional
bindir: /usr/sbin
contents:
- src: build/config.yaml.example
dst: /etc/nginx/config.yaml.example
type: "config|noreplace"
- src: build/logrotate
dst: /etc/logrotate.d/nginx-asg-sync
type: "config|noreplace"
- dst: /var/log/nginx-asg-sync
type: dir
- src: build/nginx-asg-sync.service
dst: /lib/systemd/system/nginx-asg-sync.service
- src: LICENSE
dst: /usr/share/doc/nginx-asg-sync/copyright
packager: deb
- src: LICENSES
dst: /usr/share/doc/nginx-asg-sync/LICENSES
packager: deb
- src: LICENSE
dst: /usr/share/licenses/nginx-asg-sync/LICENSE
packager: rpm
- src: LICENSES
dst: /usr/share/licenses/nginx-asg-sync/LICENSES
packager: rpm
- src: README.md
dst: /usr/share/doc/nginx-asg-sync/README
type: doc
overrides:
rpm:
scripts:
postinstall: "build/postinstall.sh"
preremove: "build/preremove.sh"
postremove: "build/postremove.sh"
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Expand Up @@ -57,7 +57,7 @@ further defined and clarified by project maintainers.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [mailto:nginx@nginx.org]. All
reported by contacting the project team at integrations@nginx.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Expand Down
20 changes: 20 additions & 0 deletions LICENSES
@@ -0,0 +1,20 @@
github.com/Azure/azure-sdk-for-go,https://github.com/Azure/azure-sdk-for-go/blob/v66.0.0/LICENSE.txt,MIT
github.com/Azure/go-autorest/autorest,https://github.com/Azure/go-autorest/blob/autorest/v0.11.24/autorest/LICENSE,Apache-2.0
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
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
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
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
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
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
github.com/Azure/go-autorest/logger,https://github.com/Azure/go-autorest/blob/logger/v0.2.1/logger/LICENSE,Apache-2.0
github.com/Azure/go-autorest/tracing,https://github.com/Azure/go-autorest/blob/tracing/v0.6.0/tracing/LICENSE,Apache-2.0
github.com/aws/aws-sdk-go,https://github.com/aws/aws-sdk-go/blob/v1.44.4/LICENSE.txt,Apache-2.0
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
github.com/dimchansky/utfbom,https://github.com/dimchansky/utfbom/blob/v1.1.1/LICENSE,Apache-2.0
github.com/golang-jwt/jwt/v4,https://github.com/golang-jwt/jwt/blob/v4.2.0/LICENSE,MIT
github.com/jmespath/go-jmespath,https://github.com/jmespath/go-jmespath/blob/v0.4.0/LICENSE,Apache-2.0
github.com/mitchellh/go-homedir,https://github.com/mitchellh/go-homedir/blob/v1.1.0/LICENSE,MIT
github.com/nginxinc/nginx-asg-sync/cmd/sync,https://github.com/nginxinc/nginx-asg-sync/blob/HEAD/LICENSE,BSD-2-Clause
github.com/nginxinc/nginx-plus-go-client/client,https://github.com/nginxinc/nginx-plus-go-client/blob/v0.10.0/LICENSE,Apache-2.0
golang.org/x/crypto/pkcs12,https://cs.opensource.google/go/x/crypto/+/e495a2d5:LICENSE,BSD-3-Clause
gopkg.in/yaml.v2,https://github.com/go-yaml/yaml/blob/v2.4.0/LICENSE,Apache-2.0

0 comments on commit 16bc280

Please sign in to comment.