Skip to content

Commit 3a2501a

Browse files
authored
build: Goreleaser (#124)
move Docker image build to Goreleaser
1 parent fef5d1d commit 3a2501a

File tree

6 files changed

+103
-109
lines changed

6 files changed

+103
-109
lines changed

.github/workflows/docker-build-stage.yaml

+11-29
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,28 @@ jobs:
1111
- name: Checkout
1212
uses: actions/checkout@v2
1313

14-
- name: Set up QEMU
15-
uses: docker/setup-qemu-action@v1
16-
17-
- name: Set up Docker Buildx
18-
uses: docker/setup-buildx-action@v1
19-
2014
- name: Login to DockerHub
2115
uses: docker/login-action@v1
2216
with:
2317
username: ${{ secrets.DOCKERHUB_USERNAME }}
2418
password: ${{ secrets.DOCKERHUB_TOKEN }}
2519

26-
- name: Docker meta for Testkube operator
27-
id: meta_testkube_operator
28-
uses: docker/metadata-action@v3
29-
with:
30-
images: kubeshop/testkube-operator
31-
tags: |
32-
type=sha
33-
34-
- name: Build
35-
uses: docker/bake-action@v1
36-
with:
37-
files: |
38-
docker-bake.hcl
39-
${{ steps.meta_testkube_operator.outputs.bake-file }}
40-
targets: build
41-
push: true
42-
4320
- name: Output commit sha
4421
id: github_sha
4522
run: echo "::set-output name=sha_short::${GITHUB_SHA::7}"
4623

47-
- name: Docker meta for Testkube certificate image
48-
id: meta_testkube_certificate
49-
uses: docker/metadata-action@v3
24+
- name: Build images with GoReleaser
25+
uses: goreleaser/goreleaser-action@v4
5026
with:
51-
images: kubeshop/testkube-certificate
52-
tags: |
53-
type=sha
27+
distribution: goreleaser
28+
version: latest
29+
args: release -f .goreleaser-stage.yaml --snapshot
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.CI_BOT_TOKEN }}
32+
33+
- name: Push Docker images
34+
run: |
35+
docker push kubeshop/testkube-operator:${{ steps.github_sha.outputs.sha_short }}
5436
5537
#Trigger Helm repo workflow to deploy Dashboard to Stage cluster
5638
- name: Repository Dispatch

.github/workflows/docker-build.yaml

+11-36
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Docker images building and pushing
1+
name: Docker images building and pushing with GoReleaser
22
on:
33
push:
44
tags:
@@ -11,48 +11,23 @@ jobs:
1111
steps:
1212
- name: Checkout
1313
uses: actions/checkout@v2
14+
with:
15+
fetch-depth: 0
1416

1517
- name: Set up QEMU
1618
uses: docker/setup-qemu-action@v1
1719

18-
- name: Set up Docker Buildx
19-
uses: docker/setup-buildx-action@v1
20-
2120
- name: Login to DockerHub
22-
uses: docker/login-action@v1
21+
uses: docker/login-action@v2
2322
with:
2423
username: ${{ secrets.DOCKERHUB_USERNAME }}
2524
password: ${{ secrets.DOCKERHUB_TOKEN }}
2625

27-
- name: Docker meta for Testkube operator
28-
id: meta_testkube_operator
29-
uses: docker/metadata-action@v3
30-
with:
31-
images: kubeshop/testkube-operator
32-
tags: |
33-
type=ref,event=branch
34-
type=ref,event=pr
35-
type=semver,pattern={{version}}
36-
type=semver,pattern={{major}}.{{minor}}
37-
type=sha
38-
39-
- name: Build
40-
uses: docker/bake-action@v1
41-
with:
42-
files: |
43-
docker-bake.hcl
44-
${{ steps.meta_testkube_operator.outputs.bake-file }}
45-
targets: build
46-
push: true
47-
48-
- name: Docker meta for Testkube certificate
49-
id: meta_testkube_certificate
50-
uses: docker/metadata-action@v3
26+
- name: Release
27+
uses: goreleaser/goreleaser-action@v4
5128
with:
52-
images: kubeshop/testkube-certificate
53-
tags: |
54-
type=ref,event=branch
55-
type=ref,event=pr
56-
type=semver,pattern={{version}}
57-
type=semver,pattern={{major}}.{{minor}}
58-
type=sha
29+
distribution: goreleaser
30+
version: latest
31+
args: release -f .goreleaser.yml
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.CI_BOT_TOKEN }}

.goreleaser-stage.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
project_name: testkube-operator
2+
builds:
3+
- id: "linux"
4+
env: [CGO_ENABLED=0]
5+
goos:
6+
- linux
7+
goarch:
8+
- amd64
9+
mod_timestamp: "{{ .CommitTimestamp }}"
10+
dockers:
11+
- dockerfile: Dockerfile
12+
use: buildx
13+
goos: linux
14+
goarch: amd64
15+
image_templates:
16+
- "kubeshop/testkube-operator:{{ .ShortCommit }}"
17+
build_flag_templates:
18+
- "--platform=linux/amd64"
19+
- "--label=org.opencontainers.image.title={{ .ProjectName }}"
20+
- "--label=org.opencontainers.image.created={{.Date}}"
21+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
22+
23+

.goreleaser.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
project_name: testkube-operator
2+
builds:
3+
- id: "linux"
4+
env: [CGO_ENABLED=0]
5+
goos:
6+
- linux
7+
goarch:
8+
- amd64
9+
- arm64
10+
mod_timestamp: "{{ .CommitTimestamp }}"
11+
dockers:
12+
- dockerfile: Dockerfile
13+
use: buildx
14+
goos: linux
15+
goarch: amd64
16+
image_templates:
17+
- "kubeshop/testkube-operator:{{ .ShortCommit }}-amd64"
18+
- "kubeshop/testkube-operator:{{ .Version }}-amd64"
19+
- "kubeshop/testkube-operator:latest-amd64"
20+
build_flag_templates:
21+
- "--platform=linux/amd64"
22+
- "--label=org.opencontainers.image.title={{ .ProjectName }}"
23+
- "--label=org.opencontainers.image.created={{.Date}}"
24+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
25+
- "--label=org.opencontainers.image.version={{.Version}}"
26+
27+
- dockerfile: Dockerfile
28+
use: buildx
29+
goos: linux
30+
goarch: arm64
31+
image_templates:
32+
- "kubeshop/testkube-operator:{{ .ShortCommit }}-arm64v8"
33+
- "kubeshop/testkube-operator:{{ .Version }}-arm64v8"
34+
- "kubeshop/testkube-operator:latest-arm64v8"
35+
build_flag_templates:
36+
- "--platform=linux/arm64/v8"
37+
- "--label=org.opencontainers.image.created={{.Date}}"
38+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
39+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
40+
- "--label=org.opencontainers.image.version={{.Version}}"
41+
42+
docker_manifests:
43+
- name_template: kubeshop/testkube-operator:{{ .ShortCommit }}
44+
image_templates:
45+
- kubeshop/testkube-operator:{{ .ShortCommit }}-amd64
46+
- kubeshop/testkube-operator:{{ .ShortCommit }}-arm64v8
47+
- name_template: kubeshop/testkube-operator:{{ .Version }}
48+
image_templates:
49+
- kubeshop/testkube-operator:{{ .Version }}-amd64
50+
- kubeshop/testkube-operator:{{ .Version }}-arm64v8
51+
- name_template: kubeshop/testkube-operator:latest
52+
image_templates:
53+
- kubeshop/testkube-operator:latest-amd64
54+
- kubeshop/testkube-operator:latest-arm64v8
55+
56+

Dockerfile

+2-32
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,3 @@
1-
# Build the manager binary
2-
FROM --platform=$BUILDPLATFORM golang:1.18 as builder
3-
4-
ENV CGO_ENABLED=0
5-
ENV GOOS=linux
6-
7-
WORKDIR /workspace
8-
# Copy the Go Modules manifests
9-
COPY go.mod go.mod
10-
COPY go.sum go.sum
11-
# cache deps before building and copying source so that we don't need to re-download as much
12-
# and so that source changes don't invalidate our downloaded layer
13-
RUN go mod download
14-
15-
# Copy the go source
16-
COPY main.go main.go
17-
COPY apis/ apis/
18-
COPY controllers/ controllers/
19-
COPY pkg/ pkg/
20-
COPY utils/ utils/
21-
22-
ARG TARGETOS TARGETARCH
23-
# Build
24-
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -o manager main.go
25-
26-
# Use distroless as minimal base image to package the manager binary
27-
# Refer to https://github.com/GoogleContainerTools/distroless for more details
28-
FROM gcr.io/distroless/static:nonroot
29-
WORKDIR /
30-
COPY --from=builder /workspace/manager .
31-
USER 65532:65532
32-
1+
FROM alpine
2+
COPY testkube-operator /manager
333
ENTRYPOINT ["/manager"]

docker-bake.hcl

-12
This file was deleted.

0 commit comments

Comments
 (0)