Skip to content

build: Tidy up goreleaser config #745

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

Merged
merged 1 commit into from
Jun 24, 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
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ jobs:
kind load docker-image \
--name chart-testing \
"ko.local/cluster-api-runtime-extensions-nutanix:$(devbox run -- gojq -r .version dist/metadata.json)" \
"ghcr.io/nutanix-cloud-native/caren-helm-reg:$(devbox run -- gojq -r .version dist/metadata.json)"
"ghcr.io/nutanix-cloud-native/caren-helm-reg:$(devbox run -- gojq -r .version dist/metadata.json)-$(devbox run -- go env GOARCH)"

- if: steps.list-changed.outputs.changed == 'true'
name: Setup Cluster API and cert-manager
Expand Down
53 changes: 19 additions & 34 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,18 @@ before:
name: caren-system
$(helm template {{ .ProjectName }} ./charts/{{ .ProjectName }} \
--namespace caren-system \
--set-string image.tag=v{{ trimprefix .Version "v" }} \
--set-string helmRepositoryImage.tag=v{{ trimprefix .Version "v" }} \
{{ if .IsSnapshot }}--set-string image.repository=ko.local/{{ .ProjectName }}{{ end }} \
--set-string image.tag={{ .Version }} \
--set-string helmRepositoryImage.tag={{ .Version }}{{ if .IsSnapshot }}-{{ .Env.GOARCH }} \
--set-string image.repository=ko.local/{{ .ProjectName }}{{ end }} \
)
EOF'
- sed -i -e 's/\${/$${/g' -e 's/v0.0.0-dev/v{{ trimprefix .Version "v" }}/g' runtime-extension-components.yaml
- sed -i -e 's/\${/$${/g' -e 's/v0.0.0-dev/{{ .Version }}/g' runtime-extension-components.yaml
- |
sh -ec 'gojq --yaml-input --yaml-output \
".releaseSeries |= (. + [{contract: \"v1beta1\", major: {{ .Major }}, minor: {{ .Minor }}}] | unique)" \
metadata.yaml >release-metadata.yaml'
- make template-helm-repository


builds:
- id: cluster-api-runtime-extensions-nutanix
dir: ./cmd
Expand All @@ -67,7 +66,7 @@ builds:
- -X 'k8s.io/component-base/version.buildDate={{ .CommitDate }}'
- -X 'k8s.io/component-base/version.gitCommit={{ .FullCommit }}'
- -X 'k8s.io/component-base/version.gitTreeState={{ .Env.GIT_TREE_STATE }}'
- -X 'k8s.io/component-base/version.gitVersion=v{{ trimprefix .Version "v" }}'
- -X 'k8s.io/component-base/version.gitVersion={{ .Version }}'
- -X 'k8s.io/component-base/version.major={{ .Major }}'
- -X 'k8s.io/component-base/version.minor={{ .Minor }}'
- -X 'k8s.io/component-base/version/verflag.programName={{ .ProjectName }}'
Expand All @@ -86,66 +85,52 @@ builds:
KO_DOCKER_REPO=ko.local/{{ .ProjectName }} \
ko build \
--bare \
-t v{{ trimprefix .Version "v" }} \
-t {{ .Version }} \
./cmd
fi'

archives:
- name_template: '{{ .ProjectName }}_v{{ trimprefix .Version "v" }}_{{ .Os }}_{{ .Arch }}'
- name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
builds:
- cluster-api-runtime-extensions-nutanix

dockers:
- image_templates:
# Specify the image tag including `-amd64` suffix if the build is not a snapshot build or is not being built on
# amd64 machine. This allows for using the snapshot image build without the architecture specific suffix
# consistently on local machines, i.e. can always use `ghcr.io/nutanix-cloud-native/caren-helm-reg:v<VERSION>` on the machine the snapshot
# is built on.
#
# For a release build the `-amd64` suffix will always be included and the `docker_manifests` specification below
# will create the final multiplatform manifest to be pushed to the registry.
- 'ghcr.io/nutanix-cloud-native/caren-helm-reg:v{{ trimprefix .Version "v" }}{{ if or (not .IsSnapshot) (not (eq .Runtime.Goarch "amd64")) }}-amd64{{ end }}'
- 'ghcr.io/nutanix-cloud-native/caren-helm-reg:{{ .Version }}-amd64'
use: buildx
dockerfile: ./hack/addons/mindthegap-helm-registry/Dockerfile
extra_files:
- hack/addons/mindthegap-helm-registry/repos.yaml
build_flag_templates:
- "--platform=linux/amd64"
- "--builder=caren"
- "--pull"
- "--label=org.opencontainers.image.created={{.CommitDate}}"
- "--label=org.opencontainers.image.title=caren-helm-reg"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- '--label=org.opencontainers.image.version=v{{ trimprefix .Version "v" }}'
- '--label=org.opencontainers.image.version={{ .Version }}'
- "--label=org.opencontainers.image.source={{.GitURL}}"
goarch: amd64
- image_templates:
# Specify the image tag including `-arm64` suffix if the build is not a snapshot build or is not being built on
# arm64 machine. This allows for using the snapshot image build without the architecture specific suffix
# consistently on local machines, i.e. can always use `ghcr.io/nutanix-cloud-native/caren-helm-reg:v<VERSION>` on the machine the snapshot
# is built on.
#
# For a release build the `-arm64` suffix will always be included and the `docker_manifests` specification below
# will create the final multiplatform manifest to be pushed to the registry.
- 'ghcr.io/nutanix-cloud-native/caren-helm-reg:v{{ trimprefix .Version "v" }}{{ if or (not .IsSnapshot) (not (eq .Runtime.Goarch "arm64")) }}-arm64{{ end }}'
- 'ghcr.io/nutanix-cloud-native/caren-helm-reg:{{ .Version }}-arm64'
use: buildx
dockerfile: ./hack/addons/mindthegap-helm-registry/Dockerfile
extra_files:
- hack/addons/mindthegap-helm-registry/repos.yaml
build_flag_templates:
- "--platform=linux/arm64"
- "--builder=caren"
- "--pull"
- "--label=org.opencontainers.image.created={{.CommitDate}}"
- "--label=org.opencontainers.image.title=caren-helm-reg"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- '--label=org.opencontainers.image.version=v{{ trimprefix .Version "v" }}'
- '--label=org.opencontainers.image.version={{ .Version }}'
- "--label=org.opencontainers.image.source={{.GitURL}}"
goarch: arm64

docker_manifests:
- name_template: ghcr.io/nutanix-cloud-native/caren-helm-reg:v{{ trimprefix .Version "v" }}
- name_template: ghcr.io/nutanix-cloud-native/caren-helm-reg:{{ .Version }}
image_templates:
- ghcr.io/nutanix-cloud-native/caren-helm-reg:v{{ trimprefix .Version "v" }}-amd64
- ghcr.io/nutanix-cloud-native/caren-helm-reg:v{{ trimprefix .Version "v" }}-arm64
- ghcr.io/nutanix-cloud-native/caren-helm-reg:{{ .Version }}-amd64
- ghcr.io/nutanix-cloud-native/caren-helm-reg:{{ .Version }}-arm64

kos:
- id: cluster-api-runtime-extensions-nutanix
Expand All @@ -156,23 +141,23 @@ kos:
- -X 'k8s.io/component-base/version.buildDate={{ .CommitDate }}'
- -X 'k8s.io/component-base/version.gitCommit={{ .FullCommit }}'
- -X 'k8s.io/component-base/version.gitTreeState={{ .Env.GIT_TREE_STATE }}'
- -X 'k8s.io/component-base/version.gitVersion=v{{ trimprefix .Version "v" }}'
- -X 'k8s.io/component-base/version.gitVersion={{ .Version }}'
- -X 'k8s.io/component-base/version.major={{ .Major }}'
- -X 'k8s.io/component-base/version.minor={{ .Minor }}'
- -X 'k8s.io/component-base/version/verflag.programName={{ .ProjectName }}'
labels:
org.opencontainers.image.created: "{{ .CommitDate }}"
org.opencontainers.image.title: "{{ .ProjectName }}"
org.opencontainers.image.revision: "{{ .FullCommit }}"
org.opencontainers.image.version: v{{ trimprefix .Version "v" }}
org.opencontainers.image.version: "{{ .Version }}"
org.opencontainers.image.source: "{{ .GitURL }}"
platforms:
- linux/amd64
- linux/arm64
repository: ghcr.io/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix
bare: true
tags:
- v{{ trimprefix .Version "v" }}
- "{{ .Version }}"

checksum:
name_template: 'checksums.txt'
Expand Down
17 changes: 14 additions & 3 deletions hack/addons/mindthegap-helm-registry/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
FROM ghcr.io/mesosphere/mindthegap:v1.14.3
ARG MINDTHEGAP_VERSION=v1.14.3

FROM --platform=${BUILDPLATFORM} ghcr.io/mesosphere/mindthegap:${MINDTHEGAP_VERSION} as bundle_builder
# this gets called by goreleaser so the copy source has to be the path relative to the repo root.
RUN --mount=source=./hack/addons/mindthegap-helm-registry/repos.yaml,target=/repos.yaml ["/ko-app/mindthegap", "create", "bundle", "--helm-charts-file=/repos.yaml", "--output-file=/tmp/helm-charts.tar"]
RUN --mount=source=./hack/addons/mindthegap-helm-registry/repos.yaml,target=/repos.yaml \
["/ko-app/mindthegap", "create", "bundle", "--helm-charts-file=/repos.yaml", "--output-file=/tmp/helm-charts.tar"]

FROM --platform=${TARGETPLATFORM} ghcr.io/mesosphere/mindthegap:${MINDTHEGAP_VERSION}
COPY --from=bundle_builder /tmp/helm-charts.tar /tmp/helm-charts.tar
VOLUME /certs
CMD ["serve", "bundle", "--bundle=/tmp/helm-charts.tar", "--listen-port=5000", "--listen-address=0.0.0.0", "--tls-private-key-file=/certs/tls.key", "--tls-cert-file=/certs/tls.crt"]
CMD [ "serve", "bundle", \
"--bundle=/tmp/helm-charts.tar", \
"--listen-port=5000", \
"--listen-address=0.0.0.0", \
"--tls-private-key-file=/certs/tls.key", \
"--tls-cert-file=/certs/tls.crt" ]
20 changes: 10 additions & 10 deletions make/dev.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@
dev.run-on-kind: export KUBECONFIG := $(KIND_KUBECONFIG)
dev.run-on-kind: kind.create clusterctl.init
ifndef SKIP_BUILD
$(MAKE) release-snapshot
dev.run-on-kind: release-snapshot
endif
dev.run-on-kind:
kind load docker-image --name $(KIND_CLUSTER_NAME) \
ko.local/cluster-api-runtime-extensions-nutanix:$$(gojq -r .version dist/metadata.json)
kind load docker-image --name $(KIND_CLUSTER_NAME) \
ghcr.io/nutanix-cloud-native/caren-helm-reg:$$(gojq -r .version dist/metadata.json)
ko.local/cluster-api-runtime-extensions-nutanix:$$(gojq -r .version dist/metadata.json) \
ghcr.io/nutanix-cloud-native/caren-helm-reg:$$(gojq -r .version dist/metadata.json)-$(GOARCH)
helm upgrade --install cluster-api-runtime-extensions-nutanix ./charts/cluster-api-runtime-extensions-nutanix \
--set-string image.repository=ko.local/cluster-api-runtime-extensions-nutanix \
--set-string image.tag=$$(gojq -r .version dist/metadata.json) \
--set-string helmRepositoryImage.tag=$$(gojq -r .version dist/metadata.json) \
--set-string helmRepositoryImage.tag=$$(gojq -r .version dist/metadata.json)-$(GOARCH) \
--wait --wait-for-jobs
kubectl rollout restart deployment cluster-api-runtime-extensions-nutanix
kubectl rollout status deployment cluster-api-runtime-extensions-nutanix

.PHONY: dev.update-webhook-image-on-kind
dev.update-webhook-image-on-kind: export KUBECONFIG := $(KIND_KUBECONFIG)
dev.update-webhook-image-on-kind:
ifndef SKIP_BUILD
$(MAKE) release-snapshot
dev.update-webhook-image-on-kind: release-snapshot
endif
dev.update-webhook-image-on-kind:
kind load docker-image --name $(KIND_CLUSTER_NAME) \
ko.local/cluster-api-runtime-extensions-nutanix:$$(gojq -r .version dist/metadata.json)
kubectl set image deployment cluster-api-runtime-extensions-nutanix webhook=ko.local/cluster-api-runtime-extensions-nutanix:$$(gojq -r .version dist/metadata.json)
ko.local/cluster-api-runtime-extensions-nutanix:$$(gojq -r .version dist/metadata.json)
kubectl set image deployment \
cluster-api-runtime-extensions-nutanix webhook=ko.local/cluster-api-runtime-extensions-nutanix:$$(gojq -r .version dist/metadata.json)
kubectl rollout restart deployment cluster-api-runtime-extensions-nutanix
kubectl rollout status deployment cluster-api-runtime-extensions-nutanix


.PHONY: dev.update-bootstrap-credentials-aws
dev.update-bootstrap-credentials-aws: export KUBECONFIG := $(KIND_KUBECONFIG)
dev.update-bootstrap-credentials-aws:
Expand Down
8 changes: 4 additions & 4 deletions make/go.mk
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ test.%: go-generate ; $(info $(M) running tests$(if $(GOTEST_RUN), matching "$(G

.PHONY: integration-test
integration-test: ## Runs integration tests for all modules in repository
integration-test:
$(MAKE) GOTEST_RUN=Integration test
integration-test: GOTEST_RUN := Integration
integration-test: test

.PHONY: integration-test.%
integration-test.%: ## Runs integration tests for a specific module
integration-test.%:
$(MAKE) GOTEST_RUN=Integration test.$*
integration-test.%: GOTEST_RUN := Integration
integration-test.%: test.$*

.PHONY: bench
bench: ## Runs go benchmarks for all modules in repository
Expand Down
9 changes: 2 additions & 7 deletions make/goreleaser.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ ifndef GORELEASER_CURRENT_TAG
export GORELEASER_CURRENT_TAG=$(GIT_TAG)
endif

.PHONY: docker-buildx
docker-buildx: ## Creates buildx builder container that supports multiple platforms.
docker-buildx:
docker buildx create --name=caren --platform=linux/arm64,linux/amd64 || true

.PHONY: build-snapshot
build-snapshot: ## Builds a snapshot with goreleaser
build-snapshot: go-generate ; $(info $(M) building snapshot $*)
Expand All @@ -25,7 +20,7 @@ build-snapshot: go-generate ; $(info $(M) building snapshot $*)

.PHONY: release
release: ## Builds a release with goreleaser
release: docker-buildx go-generate ; $(info $(M) building release $*)
release: go-generate ; $(info $(M) building release $*)
goreleaser --verbose=$(GORELEASER_VERBOSE) \
release \
--clean \
Expand All @@ -35,7 +30,7 @@ release: docker-buildx go-generate ; $(info $(M) building release $*)

.PHONY: release-snapshot
release-snapshot: ## Builds a snapshot release with goreleaser
release-snapshot: docker-buildx go-generate ; $(info $(M) building snapshot release $*)
release-snapshot: go-generate ; $(info $(M) building snapshot release $*)
goreleaser --verbose=$(GORELEASER_VERBOSE) \
release \
--snapshot \
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/config/caren.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ managementClusterName: caren-e2e
images:
- name: ko.local/cluster-api-runtime-extensions-nutanix:${E2E_IMAGE_TAG}
loadBehavior: mustLoad
- name: ghcr.io/nutanix-cloud-native/caren-helm-reg:${E2E_IMAGE_TAG}
- name: ghcr.io/nutanix-cloud-native/caren-helm-reg:${E2E_IMAGE_TAG}-${GOARCH}
loadBehavior: mustLoad

providers:
Expand Down
Loading