Skip to content

Commit

Permalink
Add goreleaser automatic release when a tag is placed.
Browse files Browse the repository at this point in the history
  • Loading branch information
sgielen committed Mar 11, 2024
1 parent 346d337 commit 59247bc
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 2 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: goreleaser

on:
push:
# run only against tags
tags:
- '*'

permissions:
contents: write
# packages: write
# issues: write

jobs:
test:
uses: ./.github/workflows/e2e.yml

goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ Dockerfile.cross
*.swp
*.swo
*~

dist/
91 changes: 91 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 1

builds:
- main: ./cmd
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64

dockers:
- image_templates:
- 'sjorsgielen/backsnap-restic:latest-amd64'
- 'sjorsgielen/backsnap-restic:{{ .Tag }}-amd64'
dockerfile: 'Dockerfile.restic'
use: buildx
build_flag_templates:
- "--pull"
- "--platform=linux/amd64"
- image_templates:
- 'sjorsgielen/backsnap-restic:latest-arm64'
- 'sjorsgielen/backsnap-restic:{{ .Tag }}-arm64'
dockerfile: 'Dockerfile.restic'
use: buildx
build_flag_templates:
- "--pull"
- "--platform=linux/arm64"
goarch: arm64
- image_templates:
- 'sjorsgielen/backsnap:latest-amd64'
- 'sjorsgielen/backsnap:{{ .Tag }}-amd64'
dockerfile: 'Dockerfile.goreleaser'
use: buildx
build_flag_templates:
- "--pull"
- "--platform=linux/amd64"
- image_templates:
- 'sjorsgielen/backsnap:latest-arm64'
- 'sjorsgielen/backsnap:{{ .Tag }}-arm64'
dockerfile: 'Dockerfile.goreleaser'
use: buildx
build_flag_templates:
- "--pull"
- "--platform=linux/arm64"
goarch: arm64

docker_manifests:
- name_template: 'sjorsgielen/backsnap-restic:latest'
image_templates:
- 'sjorsgielen/backsnap-restic:latest-amd64'
- 'sjorsgielen/backsnap-restic:latest-arm64'
- name_template: 'sjorsgielen/backsnap-restic:{{ .Tag }}'
image_templates:
- 'sjorsgielen/backsnap-restic:{{ .Tag }}-amd64'
- 'sjorsgielen/backsnap-restic:{{ .Tag }}-arm64'
- name_template: 'sjorsgielen/backsnap:latest'
image_templates:
- 'sjorsgielen/backsnap:latest-amd64'
- 'sjorsgielen/backsnap:latest-arm64'
- name_template: 'sjorsgielen/backsnap:{{ .Tag }}'
image_templates:
- 'sjorsgielen/backsnap:{{ .Tag }}-amd64'
- 'sjorsgielen/backsnap:{{ .Tag }}-arm64'

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ COPY go.sum go.sum
RUN go mod download

# Copy the go source
COPY cmd/backsnap cmd/backsnap
COPY cmd/ cmd/
COPY api/ api/
COPY internal/controller/ internal/controller/

Expand Down
8 changes: 8 additions & 0 deletions Dockerfile.goreleaser
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY backsnap manager
USER 65532:65532

ENTRYPOINT ["/manager"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ make undeploy

## How to run it locally

You can run `go run ./cmd/backsnap -help` to get a list of flags. Example run:
You can run `go run ./cmd -help` to get a list of flags. Example run:

```
go run ./cmd \
Expand Down

0 comments on commit 59247bc

Please sign in to comment.