Skip to content

Commit

Permalink
Delegate docker image builds to goreleaser (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgaughan authored Jul 22, 2024
1 parent 8c0d0f9 commit fab8fb9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
37 changes: 11 additions & 26 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:

permissions:
contents: write
packages: write

steps:
- uses: actions/checkout@v3
Expand All @@ -33,26 +34,6 @@ jobs:
check-latest: true
cache: true

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAP_GITHUB_TOKEN: ${{ secrets.TAP }}

build-and-push-image:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
Expand All @@ -66,10 +47,14 @@ jobs:
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAP_GITHUB_TOKEN: ${{ secrets.TAP }}
REGISTRY: ${{ env.REGISTRY }}
IMAGE: ${{ env.IMAGE_NAME }}
7 changes: 7 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ archives:
- LICENSE
- README.md

dockers:
- image_templates:
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE }}:{{ .Tag }}"
skip_push: auto
use: buildx
dockerfile: Dockerfile

checksum:
name_template: "checksums.txt"

Expand Down
9 changes: 1 addition & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
FROM golang:1.21 AS builder

ENV GOPATH /go
ENV APPPATH /repo
COPY . /repo
RUN cd /repo && CGO_ENABLED=0 go build -tags netgo -trimpath -ldflags '-s -w' -o mercury ./cmd/mercury

FROM alpine:latest

LABEL org.opencontainers.image.title=Mercury
Expand All @@ -16,6 +9,6 @@ LABEL org.opencontainers.image.source=https://github.com/kgaughan/mercury
LABEL org.opencontainers.image.documentation=https://kgaughan.github.io/mercury/

RUN apk --no-cache add ca-certificates tzdata
COPY --from=builder /repo/mercury /mercury
COPY mercury .
USER nobody
ENTRYPOINT ["/mercury"]

0 comments on commit fab8fb9

Please sign in to comment.