Skip to content

Commit

Permalink
Build and push docker images for releases with goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
tfabritius committed May 22, 2023
1 parent f61b582 commit 7ac7dfb
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 54 deletions.
40 changes: 0 additions & 40 deletions .github/release.sh

This file was deleted.

55 changes: 42 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,47 @@ jobs:
release:
runs-on: ubuntu-latest
permissions:
# Allow upload of assets to release
contents: write
# Allow push of docker images
packages: write

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-go@v4
- run: sh ./.github/release.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPO: ${{ github.repository }}
GITHUB_RELEASE: ${{ github.event.release.id }}
- uses: actions/checkout@v3
with:
# Required by goreleaser
fetch-depth: 0

### Frontend
- uses: pnpm/action-setup@v2
with:
version: 8
# pnpm has to be installed before node to make use of caching
- uses: actions/setup-node@v3
with:
node-version-file: 'frontend/package.json'
cache: pnpm
cache-dependency-path: frontend/pnpm-lock.yaml
- run: pnpm install --frozen-lockfile
working-directory: frontend
- run: pnpm generate
working-directory: frontend

### Backend
- uses: docker/setup-qemu-action@v2
# Required by goreleaser to build docker images with buildx
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-go@v4
with:
go-version-file: backend/go.mod
cache-dependency-path: backend/go.sum
- uses: goreleaser/goreleaser-action@v4
with:
args: release --clean
workdir: backend
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
.env
bin/
3 changes: 3 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/data
/test/data

# goreleaser output
dist/
76 changes: 76 additions & 0 deletions backend/.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json

before:
hooks:
- go mod download
- go generate ./...

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
ignore:
- goos: windows
goarch: arm64

# Ensure reproducible builds:
mod_timestamp: '{{ .CommitTimestamp }}'

flags:
- -trimpath

ldflags:
# Reduce size:
- -s
- -w
# Embed version
- -X main.version={{.Version}}

archives:
- name_template: >-
{{ .ProjectName }}-
{{- .Version }}-
{{- .Os }}-
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
format: tar.gz
format_overrides:
# use zip for windows archives
- goos: windows
format: zip
dockers:
- image_templates:
- 'ghcr.io/tfabritius/{{ .ProjectName }}:{{ .Tag }}-amd64'
goarch: amd64
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- --pull
- --platform=linux/amd64
- image_templates:
- 'ghcr.io/tfabritius/{{ .ProjectName }}:{{ .Tag }}-arm64'
goarch: arm64
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- --pull
- --platform=linux/arm64

docker_manifests:
- name_template: 'ghcr.io/tfabritius/{{ .ProjectName }}:{{ .Tag }}'
image_templates:
- 'ghcr.io/tfabritius/{{ .ProjectName }}:{{ .Tag }}-amd64'
- 'ghcr.io/tfabritius/{{ .ProjectName }}:{{ .Tag }}-arm64'
- name_template: 'ghcr.io/tfabritius/{{ .ProjectName }}:latest'
image_templates:
- 'ghcr.io/tfabritius/{{ .ProjectName }}:{{ .Tag }}-amd64'
- 'ghcr.io/tfabritius/{{ .ProjectName }}:{{ .Tag }}-arm64'
8 changes: 8 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM gcr.io/distroless/static

COPY plainpage /

VOLUME /data
EXPOSE 8080

ENTRYPOINT ["/plainpage"]

0 comments on commit 7ac7dfb

Please sign in to comment.