Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add multi arch build using goreleaser #16

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]