Skip to content

Commit

Permalink
feat(goreleaser): produce OCI manifest images (#402)
Browse files Browse the repository at this point in the history
Switch our build pipeline to match hetznercloud/hcloud-cloud-controller-manager#417
  • Loading branch information
apricote authored and lukasmetzner committed Oct 10, 2024
1 parent 5f878a4 commit 86bb719
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 41 deletions.
26 changes: 17 additions & 9 deletions .github/workflows/publish_on_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,31 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.19

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ github.repository_owner }}/hcloud-csi-driver:latest
cache-from: type=registry,ref=${{ github.repository_owner }}/hcloud-csi-driver:buildcache
cache-to: type=registry,ref=${{ github.repository_owner }}/hcloud-csi-driver:buildcache,mode=max

- name: "make docker plugin"
run: |
cd deploy/docker-swarm/pkg
make push PLUGIN_NAME=${{ github.repository_owner }}/hcloud-csi-driver PLUGIN_TAG=latest-swarm
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: snapshot --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20 changes: 11 additions & 9 deletions .github/workflows/publish_on_tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.19

- id: release_version
run: echo ::set-output name=value::${GITHUB_REF:11}

- name: update pushed tag
env:
RELEASE_VERSION: ${{ steps.release_version.outputs.value}}
Expand All @@ -26,28 +33,23 @@ jobs:
git tag -d v$RELEASE_VERSION
git tag v$RELEASE_VERSION
git push origin v$RELEASE_VERSION -f
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ github.repository_owner }}/hcloud-csi-driver:${{ steps.release_version.outputs.value}}
cache-from: type=registry,ref=${{ github.repository_owner }}/hcloud-csi-driver:buildcache
cache-to: type=registry,ref=${{ github.repository_owner }}/hcloud-csi-driver:buildcache,mode=max

- name: "make docker plugin"
env:
RELEASE_VERSION: ${{ steps.release_version.outputs.value}}
run: |
cd deploy/docker-swarm/pkg
make push PLUGIN_NAME=${{ github.repository_owner }}/hcloud-csi-driver PLUGIN_TAG=$RELEASE_VERSION-swarm
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# rootfs for docker plugin
deploy/docker-swarm/pkg/plugin
hack/.*
dist/
38 changes: 31 additions & 7 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
builds:
- skip: true
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- id: controller
main: ./cmd/controller
env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
binary: controller.bin
- id: node
main: ./cmd/node
env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
binary: node.bin

dockers:
- build_flag_templates: [--platform=linux/amd64]
dockerfile: Dockerfile
goarch: amd64
image_templates: ["hetznercloud/hcloud-csi-driver:{{ if not .IsSnapshot }}v{{ end }}{{ .Version }}-amd64"]
use: buildx

docker_manifests:
- name_template: hetznercloud/hcloud-csi-driver:{{ if not .IsSnapshot }}v{{ end }}{{ .Version }}
image_templates:
- hetznercloud/hcloud-csi-driver:{{ if not .IsSnapshot }}v{{ end }}{{ .Version }}-amd64

18 changes: 3 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
FROM golang:1.19 as builder
WORKDIR /csi
ADD go.mod go.sum /csi/
RUN go mod download
ADD . /csi/
RUN ls -al
# `skaffold debug` sets SKAFFOLD_GO_GCFLAGS to disable compiler optimizations
ARG SKAFFOLD_GO_GCFLAGS
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -o controller.bin github.com/hetznercloud/csi-driver/cmd/controller
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -o node.bin github.com/hetznercloud/csi-driver/cmd/node

FROM --platform=linux/amd64 alpine:3.15
FROM alpine:3.15
RUN apk add --no-cache ca-certificates e2fsprogs xfsprogs blkid xfsprogs-extra e2fsprogs-extra btrfs-progs cryptsetup
ENV GOTRACEBACK=all
COPY --from=builder /csi/controller.bin /bin/hcloud-csi-driver-controller
COPY --from=builder /csi/node.bin /bin/hcloud-csi-driver-node
COPY ./controller.bin /bin/hcloud-csi-driver-controller
COPY ./node.bin /bin/hcloud-csi-driver-node
16 changes: 16 additions & 0 deletions hack/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM golang:1.19 as builder
WORKDIR /csi
ADD go.mod go.sum /csi/
RUN go mod download
ADD . /csi/
RUN ls -al
# `skaffold debug` sets SKAFFOLD_GO_GCFLAGS to disable compiler optimizations
ARG SKAFFOLD_GO_GCFLAGS
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -o controller.bin github.com/hetznercloud/csi-driver/cmd/controller
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -o node.bin github.com/hetznercloud/csi-driver/cmd/node

FROM alpine:3.15
RUN apk add --no-cache ca-certificates e2fsprogs xfsprogs blkid xfsprogs-extra e2fsprogs-extra btrfs-progs cryptsetup
ENV GOTRACEBACK=all
COPY --from=builder /csi/controller.bin /bin/hcloud-csi-driver-controller
COPY --from=builder /csi/node.bin /bin/hcloud-csi-driver-node
2 changes: 1 addition & 1 deletion skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build:
artifacts:
- image: hetznercloud/hcloud-csi-driver
docker:
dockerfile: Dockerfile
dockerfile: hack/Dockerfile
cacheFrom:
- hetznercloud/hcloud-csi-driver:buildcache
local:
Expand Down

0 comments on commit 86bb719

Please sign in to comment.