Skip to content

Commit

Permalink
configure build with goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiebens committed Jan 31, 2022
1 parent cfdece8 commit 20a4114
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 192 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: build

on:
push:
branches:
- '*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ^1.17
- name: Build
run: |
go build cmd/brink/main.go
- name: Tests
run: |
go test ./...
29 changes: 29 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: ci

on:
pull_request:

jobs:
ci:
runs-on: ubuntu-latest
env:
DOCKER_CLI_EXPERIMENTAL: "enabled"
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ^1.17
- name: Tests
run: |
go test ./...
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist --snapshot
81 changes: 0 additions & 81 deletions .github/workflows/dev-release.yaml

This file was deleted.

90 changes: 25 additions & 65 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,80 +1,40 @@
name: "Release"
name: release

on:
release:
types: [ created ]

jobs:
binaries:
name: "Binaries"
runs-on: "ubuntu-latest"

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ^1.17

- name: Build
run: make dist

- uses: skx/github-action-publish-binaries@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: "./dist/*"

docker:
name: "Docker"
runs-on: "ubuntu-latest"
push:
tags:
- '*'

permissions:
contents: read
packages: write
permissions:
contents: write
packages: write

jobs:
release:
runs-on: ubuntu-latest
env:
DOCKER_CLI_EXPERIMENTAL: "enabled"
steps:
- name: Checkout repository
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Get tags
id: get_tag
run: echo ::set-output name=TAG::${GITHUB_REF#refs/tags/}

- name: Set Username/Repo and ImagePrefix as ENV vars
run: |
echo "USER_REPO"=$(echo "$GITHUB_REPOSITORY" | awk '{print tolower($1)}' | sed -e "s/:refs//") >> $GITHUB_ENV && \
echo "IMAGE_PREFIX"=$(echo "ghcr.io/$GITHUB_REPOSITORY" | awk '{print tolower($1)}' | sed -e "s/:refs//") >> $GITHUB_ENV
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

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

- name: Login to Github Container Registry
- name: Docker Login
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push container images
uses: docker/build-push-action@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
build-args: |
VERSION=latest
GIT_COMMIT=${{ github.sha }}
REPO_URL=https://github.com/${{ env.USER_REPO }}
push: true
tags: |
${{ env.IMAGE_PREFIX }}:${{ steps.get_tag.outputs.TAG }}
go-version: ^1.17
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68 changes: 68 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
project_name: brink

before:
hooks:
- go mod tidy

builds:
- main: ./cmd/brink
env: [ CGO_ENABLED=0 ]
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
ignore:
- goos: windows
goarch: arm64
ldflags:
- -s -w -X github.com/jsiebens/brink/internal/version.Version={{.Version}} -X github.com/jsiebens/brink/internal/version.GitCommit={{.Commit}}

dockers:
- image_templates: [ "ghcr.io/jsiebens/{{ .ProjectName }}:{{ .Version }}-amd64" ]
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- --platform=linux/amd64
- image_templates: [ "ghcr.io/jsiebens/{{ .ProjectName }}:{{ .Version }}-arm64" ]
goarch: arm64
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- --platform=linux/arm64
docker_manifests:
- name_template: ghcr.io/jsiebens/{{ .ProjectName }}:{{ .Version }}
image_templates:
- ghcr.io/jsiebens/{{ .ProjectName }}:{{ .Version }}-amd64
- ghcr.io/jsiebens/{{ .ProjectName }}:{{ .Version }}-arm64
- name_template: ghcr.io/jsiebens/{{ .ProjectName }}:latest
image_templates:
- ghcr.io/jsiebens/{{ .ProjectName }}:{{ .Version }}-amd64
- ghcr.io/jsiebens/{{ .ProjectName }}:{{ .Version }}-arm64

archives:
- format_overrides:
- goos: windows
format: zip

changelog:
sort: asc
filters:
exclude:
- '^test:'
- '^chore'
- Merge pull request
- Merge remote-tracking branch
- Merge branch
- go mod tidy
groups:
- title: 'New Features'
regexp: "^.*feat[(\\w)]*:+.*$"
order: 0
- title: 'Bug fixes'
regexp: "^.*fix[(\\w)]*:+.*$"
order: 10
- title: Other work
order: 999
25 changes: 2 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.17.2-alpine3.14 as build

ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH

ENV CGO_ENABLED=0

WORKDIR /src
COPY . .

RUN apk add git
RUN VERSION=$(git describe --all --exact-match `git rev-parse HEAD` | grep tags | sed 's/tags\///') \
&& GIT_COMMIT=$(git rev-list -1 HEAD) \
&& GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=${CGO_ENABLED} go build \
--ldflags "-s -w \
-X github.com/jsiebens/brink/internal/version.GitCommit=${GIT_COMMIT}\
-X github.com/jsiebens/brink/internal/version.Version=${VERSION}" \
-a -installsuffix cgo -o brink cmd/brink/main.go

FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.14.2 as ship
FROM alpine:3.14.2

RUN apk --no-cache add ca-certificates
RUN addgroup -S brink && adduser -S -g brink brink

COPY --from=build /src/brink /usr/local/bin
COPY brink /usr/local/bin/brink

USER brink
ENTRYPOINT ["brink"]
23 changes: 0 additions & 23 deletions Makefile

This file was deleted.

0 comments on commit 20a4114

Please sign in to comment.