Skip to content

Commit

Permalink
feat: multi arch build
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatur authored Oct 18, 2022
1 parent 6985b1a commit 8bf9aad
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 105 deletions.
22 changes: 7 additions & 15 deletions .github/workflows/main.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
push:
branches:
- master
tags:
- v*
pull_request:

jobs:
Expand All @@ -14,8 +12,8 @@ jobs:
name: Main Process
runs-on: ubuntu-latest
env:
GO_VERSION: 1.16
GOLANGCI_LINT_VERSION: v1.41.1
GO_VERSION: 1.19
GOLANGCI_LINT_VERSION: v1.50.0
CGO_ENABLED: 0

steps:
Expand Down Expand Up @@ -46,21 +44,15 @@ jobs:
go mod tidy
git diff --exit-code go.mod
git diff --exit-code go.sum
go mod download
# https://golangci-lint.run/usage/install#other-ci
- name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}
golangci-lint --version
- name: Make
run: make

# https://goreleaser.com/ci/actions/
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
if: startsWith(github.ref, 'refs/tags/v')
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Make Image
run: make image
2 changes: 1 addition & 1 deletion .github/workflows/go-cross.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

strategy:
matrix:
go-version: [ 1.16, 1.x ]
go-version: [ 1.19, 1.x ]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: "Release a tag"
on:
push:
tags:
- v*

jobs:
release:
name: Release Process
runs-on: ubuntu-latest
env:
GO_VERSION: 1.19
CGO_ENABLED: 0

steps:

# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

# https://github.com/marketplace/actions/checkout
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Docker Login
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
run: |
echo "${DOCKER_TOKEN}" | docker login --username "${DOCKER_USERNAME}" --password-stdin
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# https://goreleaser.com/ci/actions/
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71 changes: 0 additions & 71 deletions .golangci.toml

This file was deleted.

70 changes: 70 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
run:
timeout: 2m
skip-files:
- ^unsecured/

linters-settings:
govet:
check-shadowing: true
gocyclo:
min-complexity: 16
goconst:
min-len: 3
min-occurrences: 3
misspell:
locale: US

linters:
enable-all: true
disable:
- maligned # deprecated
- interfacer # deprecated
- scopelint # deprecated
- golint # deprecated
- ifshort # deprecated
- varcheck # deprecated
- deadcode # deprecated
- nosnakecase # deprecated
- structcheck # deprecated
- exhaustivestruct # deprecated
- execinquery # not relevant (SQL)
- sqlclosecheck # not relevant (SQL)
- rowserrcheck # not relevant (SQL)
- cyclop # duplicate of gocyclo
- contextcheck
- lll
- gas
- dupl
- prealloc
- scopelint
- gomnd
- wsl
- nlreturn
- gocognit
- nestif
- testpackage
- paralleltest
- tparallel
- goerr113
- wrapcheck
- exhaustive
- exhaustruct
- noctx
- varnamelen
- nilnil

issues:
exclude-use-default: false
max-per-linter: 0
max-same-issues: 0
exclude:
- 'ST1000: at least one file in a package should have a package comment'
- 'package-comments: should have a package comment'
exclude-rules:
- path: (.+)_test.go
linters:
- funlen
- path: version.go
text: (version|date|commit) is a global variable
- path: version.go
text: use of `fmt.Printf` forbidden by pattern
91 changes: 75 additions & 16 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ project_name: bibikoffi

builds:
- binary: bibikoffi
main: ./

env:
- CGO_ENABLED=0
flags:
- -trimpath
ldflags:
- -s -w -X main.version={{.Version}}

goos:
- windows
- darwin
- linux
goarch:
- amd64
- 386
- arm
- arm64
goarm:
- 7

ignore:
- goos: darwin
goarch: 386

changelog:
sort: asc
Expand All @@ -28,11 +29,69 @@ changelog:
- '^test:'
- '^tests:'

archive:
name_template: '{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
format: tar.gz
format_overrides:
- goos: windows
format: zip
files:
- LICENSE
archives:
- id: bibikoffi
name_template: '{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
format: tar.gz
format_overrides:
- goos: windows
format: zip
files:
- LICENSE

docker_manifests:
- name_template: 'traefik/bibikoffi:{{ .Tag }}'
image_templates:
- 'traefik/bibikoffi:{{ .Tag }}-amd64'
- 'traefik/bibikoffi:{{ .Tag }}-arm64'
- name_template: 'traefik/bibikoffi:latest'
image_templates:
- 'traefik/bibikoffi:{{ .Tag }}-amd64'
- 'traefik/bibikoffi:{{ .Tag }}-arm64'
- name_template: 'traefik/bibikoffi:v{{ .Major }}.{{ .Minor }}'
image_templates:
- 'traefik/bibikoffi:v{{ .Major }}.{{ .Minor }}-amd64'
- 'traefik/bibikoffi:v{{ .Major }}.{{ .Minor }}-arm64'

dockers:
- use: buildx
goos: linux
goarch: amd64
dockerfile: buildx.Dockerfile
image_templates:
- 'traefik/bibikoffi:latest-amd64'
- 'traefik/bibikoffi:{{ .Tag }}-amd64'
- 'traefik/bibikoffi:v{{ .Major }}.{{ .Minor }}-amd64'
build_flag_templates:
- '--pull'
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
- '--label=org.opencontainers.image.title={{.ProjectName}}'
- '--label=org.opencontainers.image.description=Myrmica Bibikoffi - Closes stale issues'
- '--label=org.opencontainers.image.source={{.GitURL}}'
- '--label=org.opencontainers.image.url={{.GitURL}}'
- '--label=org.opencontainers.image.documentation={{.GitURL}}'
- '--label=org.opencontainers.image.created={{.Date}}'
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
- '--label=org.opencontainers.image.version={{.Version}}'
- '--platform=linux/amd64'

- use: buildx
goos: linux
goarch: arm64
dockerfile: buildx.Dockerfile
image_templates:
- 'traefik/bibikoffi:latest-arm64'
- 'traefik/bibikoffi:{{ .Tag }}-arm64'
- 'traefik/bibikoffi:v{{ .Major }}.{{ .Minor }}-arm64'
build_flag_templates:
- '--pull'
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
- '--label=org.opencontainers.image.title={{.ProjectName}}'
- '--label=org.opencontainers.image.description=Myrmica Bibikoffi - Closes stale issues'
- '--label=org.opencontainers.image.source={{.GitURL}}'
- '--label=org.opencontainers.image.url={{.GitURL}}'
- '--label=org.opencontainers.image.documentation={{.GitURL}}'
- '--label=org.opencontainers.image.created={{.Date}}'
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
- '--label=org.opencontainers.image.version={{.Version}}'
- '--platform=linux/arm64'
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ SHA := $(shell git rev-parse --short HEAD)
VERSION := $(if $(TAG_NAME),$(TAG_NAME),$(SHA))
BUILD_DATE := $(shell date -u '+%Y-%m-%d_%I:%M:%S%p')

BIN_OUTPUT := $(if $(filter $(shell go env GOOS), windows), bibikoffi.exe, bibikoffi)

IMAGE_NAME := traefik/bibikoffi

default: clean check test build

test: clean
Expand All @@ -17,7 +21,10 @@ clean:

build: clean
@echo Version: $(VERSION) $(BUILD_DATE)
go build -v -ldflags '-X "main.version=${VERSION}" -X "main.commit=${SHA}" -X "main.date=${BUILD_DATE}"'
CGO_ENABLED=0 go build -trimpath -ldflags '-s -w -X "main.version=${VERSION}" -X "main.commit=${SHA}" -X "main.date=${BUILD_DATE}"' -o ${BIN_OUTPUT} .

check:
golangci-lint run

image:
docker build -t $(IMAGE_NAME) .
10 changes: 10 additions & 0 deletions buildx.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# syntax=docker/dockerfile:1.4
FROM alpine:3.16

RUN apk --no-cache --no-progress add ca-certificates git \
&& rm -rf /var/cache/apk/*

COPY bibikoffi /

ENTRYPOINT ["/bibikoffi"]
EXPOSE 80
Loading

0 comments on commit 8bf9aad

Please sign in to comment.