Skip to content

Commit

Permalink
ci: Use goreleaser to build docker images (#589)
Browse files Browse the repository at this point in the history
* add yaml schema comment

* update dockerfile to just copy over the pre-compiled binary

* add docker config to goreleaser

* since goreleaser now pushes to GHCR, we need to authenticate before running gorelaeser

* we don't need the docker release workflow anymore
  • Loading branch information
mircea-pavel-anton authored Sep 12, 2024
1 parent 973a67b commit 1084d11
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 86 deletions.
62 changes: 0 additions & 62 deletions .github/workflows/docker-build-and-push.yaml

This file was deleted.

12 changes: 9 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@ jobs:
- name: Set up Go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: "stable"
go-version: stable

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6.0.0
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: goreleaser/goreleaser-action@v6
with:
args: release --clean ${{ env.GORELEASER_DRY_RUN == 'true' && '--snapshot' || '' }}
env:
Expand Down
44 changes: 44 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
version: 2
project_name: talhelper
builds:
Expand Down Expand Up @@ -72,3 +73,46 @@ scoops:
license: BSD-3
depends:
- sops

dockers:
- image_templates:
- "ghcr.io/budimanjojo/{{.ProjectName}}:v{{.Version}}-amd64"
use: buildx
dockerfile: Dockerfile
build_flag_templates:
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.url=https://github.com/budimanjojo/{{.ProjectName}}"
- "--label=org.opencontainers.image.source=https://github.com/budimanjojo/{{.ProjectName}}"
- "--label=org.opencontainers.image.licenses=BSD-3-Clause"
- "--label=org.opencontainers.image.authors=Budiman Jojo <budimanjojo@gmail.com>"
- "--label=org.opencontainers.image.description=A tool to help creating Talos kubernetes cluster"
- image_templates:
- "ghcr.io/budimanjojo/{{.ProjectName}}:v{{.Version}}-arm64v8"
use: buildx
goarch: arm64
dockerfile: Dockerfile
build_flag_templates:
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.url=https://github.com/budimanjojo/{{.ProjectName}}"
- "--label=org.opencontainers.image.source=https://github.com/budimanjojo/{{.ProjectName}}"
- "--label=org.opencontainers.image.licenses=BSD-3-Clause"
- "--label=org.opencontainers.image.authors=Budiman Jojo <budimanjojo@gmail.com>"
- "--label=org.opencontainers.image.description=A tool to help creating Talos kubernetes cluster"

docker_manifests:
- name_template: "ghcr.io/budimanjojo/{{.ProjectName}}:v{{.Version}}"
image_templates:
- "ghcr.io/budimanjojo/{{.ProjectName}}:v{{.Version}}-amd64"
- "ghcr.io/budimanjojo/{{.ProjectName}}:v{{.Version}}-arm64v8"
- name_template: "ghcr.io/budimanjojo/{{.ProjectName}}:latest"
image_templates:
- "ghcr.io/budimanjojo/{{.ProjectName}}:v{{.Version}}-amd64"
- "ghcr.io/budimanjojo/{{.ProjectName}}:v{{.Version}}-arm64v8"
24 changes: 3 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
ARG VERSION

## ================================================================================================
## Builder Stage -> creating the binary
## ================================================================================================
FROM golang:1.23.0-alpine AS builder
ARG VERSION

WORKDIR /build
COPY . .
RUN go build -ldflags="-s -w -X github.com/budimanjojo/talhelper/v3/cmd.version=${VERSION}" -o /usr/local/bin/talhelper


## ================================================================================================
## Serving/Production Stage
## ================================================================================================
FROM scratch
COPY --from=builder /usr/local/bin/talhelper /usr/local/bin/talhelper
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
WORKDIR /config
ENTRYPOINT [ "/usr/local/bin/talhelper" ]
FROM alpine:3.20.3@sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d
COPY talhelper /bin/talhelper
ENTRYPOINT ["/bin/talhelper"]

0 comments on commit 1084d11

Please sign in to comment.