Skip to content

Commit

Permalink
Merge pull request #16 from kubefirst/goreleaser
Browse files Browse the repository at this point in the history
feat: add multi arch build using goreleaser
  • Loading branch information
jokestax authored Dec 19, 2024
2 parents f241c62 + 133bbf1 commit f7586f5
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 58 deletions.
34 changes: 0 additions & 34 deletions .github/workflows/public-ecr.yaml

This file was deleted.

34 changes: 34 additions & 0 deletions .github/workflows/release-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: release container image

on:
push:
tags:
- '*'

jobs:
gorelease:
name: build and push metrics-client
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Login to Github Container Registry
uses: docker/login-action@v3
with:
registry: "ghcr.io"
username: ${{ github.actor }}
password: ${{ secrets.TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Release container image to Github
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
31 changes: 31 additions & 0 deletions .github/workflows/test-goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Testing
on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test-app:
name: Test Application
runs-on: ubuntu-24.04
steps:
- name: Clone repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Test application
run: go test ./...
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Dry-run goreleaser application
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: ~> v2
args: release --snapshot --skip=publish --clean
62 changes: 62 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
version: 2

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
- arm
- arm64
tags:
- netgo
flags:
- -trimpath
ldflags:
- -s -w -extldflags "-static"

dockers:
- image_templates:
- "ghcr.io/kubefirst/metrics-client:{{ .Tag }}-amd64"
goos: linux
goarch: amd64
use: buildx
build_flag_templates:
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.title={{ .ProjectName }}"
- "--label=org.opencontainers.image.description={{ .ProjectName }} version {{ .Version }}. See release notes at https://github.com/kubefirst/{{ .ProjectName }}/releases/tag/v{{ .RawVersion }}"
- "--label=org.opencontainers.image.url=https://github.com/kubefirst/{{ .ProjectName }}"
- "--label=org.opencontainers.image.source=https://github.com/kubefirst/{{ .ProjectName }}"
- "--label=org.opencontainers.image.version={{ .Version }}"
- '--label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}'
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"

- image_templates:
- "ghcr.io/kubefirst/metrics-client:{{ .Tag }}-arm64"
goos: linux
goarch: arm64
use: buildx
build_flag_templates:
- "--platform=linux/arm64"
- "--label=org.opencontainers.image.title={{ .ProjectName }}"
- "--label=org.opencontainers.image.description={{ .ProjectName }} version {{ .Version }}. See release notes at https://github.com/kubefirst/{{ .ProjectName }}/releases/tag/v{{ .RawVersion }}"
- "--label=org.opencontainers.image.url=https://github.com/kubefirst/{{ .ProjectName }}"
- "--label=org.opencontainers.image.source=https://github.com/kubefirst/{{ .ProjectName }}"
- "--label=org.opencontainers.image.version={{ .Version }}"
- '--label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}'
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"

docker_manifests:
- name_template: "ghcr.io/kubefirst/metrics-client:v{{ .RawVersion }}"
image_templates:
- "ghcr.io/kubefirst/metrics-client:{{ .Tag }}-amd64"
- "ghcr.io/kubefirst/metrics-client:{{ .Tag }}-arm64"
- name_template: "ghcr.io/kubefirst/metrics-client:v{{ .Major }}"
image_templates:
- "ghcr.io/kubefirst/metrics-client:{{ .Tag }}-amd64"
- "ghcr.io/kubefirst/metrics-client:{{ .Tag }}-arm64"
- name_template: "ghcr.io/kubefirst/metrics-client:latest"
image_templates:
- "ghcr.io/kubefirst/metrics-client:{{ .Tag }}-amd64"
- "ghcr.io/kubefirst/metrics-client:{{ .Tag }}-arm64"
26 changes: 2 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
FROM golang:alpine AS builder

ENV GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64

WORKDIR /build

# Download go dependencies
COPY go.mod .
COPY go.sum .
RUN go mod download

# Copy into the container
COPY . .

# Build the application
RUN go build -o metrics-client .

# Build final image using nothing but the binary
FROM alpine:3.17.2

COPY --from=builder /build/metrics-client /
COPY metrics-client /usr/bin/

# Command to run
ENTRYPOINT ["/metrics-client"]
ENTRYPOINT ["/usr/bin/metrics-client"]

0 comments on commit f7586f5

Please sign in to comment.