Skip to content

Commit

Permalink
feat: multi-arch docker (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
notnmeyer authored Jan 10, 2024
1 parent ca00fc8 commit 408cbfb
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 25 deletions.
33 changes: 20 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,40 @@ name: release

on:
workflow_dispatch:
workflow_run:
workflows:
- test
branches:
- main
types:
- completed
push:
tags:
- "v*"

permissions:
contents: write
packages: write

jobs:
run:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --force --tags

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5

- uses: goreleaser/goreleaser-action@v5
with:
push: true
tags: docker.io/notnmeyer/mockpi:latest
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# keep .git out of telescope pickers
.git

.env
dist/
59 changes: 59 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 1

before:
hooks:
- go mod tidy

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin

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 }}
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"

dockers:
- image_templates:
- "notnmeyer/mockpi:{{ .Tag }}-amd64"
use: buildx
build_flag_templates:
- "--pull"
- "--platform=linux/amd64"
- image_templates:
- "notnmeyer/mockpi:{{ .Tag }}-arm64"
use: buildx
build_flag_templates:
- "--pull"
- "--platform=linux/arm64"
goarch: arm64

docker_manifests:
- name_template: "notnmeyer/mockpi:{{ .Tag }}"
image_templates:
- "notnmeyer/mockpi:{{ .Tag }}-amd64"
- "notnmeyer/mockpi:{{ .Tag }}-arm64"
14 changes: 2 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
FROM docker.io/golang:1.21 as builder
ENV CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64
WORKDIR /build
COPY *.go .
COPY go.mod .
RUN go mod tidy
RUN go build -o dist/mockpi ./main.go

FROM scratch
COPY --from=builder /build/dist/mockpi /usr/local/bin/
CMD ["/usr/local/bin/mockpi"]
COPY mockpi /
ENTRYPOINT ["/mockpi"]
21 changes: 21 additions & 0 deletions tasks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tasks.run]
cmds = ["go run main.go {{.CLI_ARGS}}"]

[tasks.test]
cmds = ["go test ./... {{.CLI_ARGS}}"]

[tasks.build]
dotenv = ".env"
cmds = [
"docker context use default",
"goreleaser build --clean --snapshot {{.CLI_ARGS}}",
]

# `tsk release -- --snapshot` to build images without publishing
[tasks.release]
dotenv = ".env"
cmds = [
"docker context use default",
"goreleaser release --clean {{.CLI_ARGS}}",
]

0 comments on commit 408cbfb

Please sign in to comment.