Repository navigation
New release process with ko and goreleaser
#331
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| # Ignore Helm packages. | ||
| *.tgz | ||
|
|
||
| /_artifacts/ | ||
| /dist/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| version: 2 | ||
|
|
||
| before: | ||
| hooks: | ||
| - make manifests VERSION={{ .Version }} | ||
|
|
||
| builds: | ||
| - id: oxide-cloud-controller-manager | ||
| main: . | ||
| binary: oxide-cloud-controller-manager | ||
| env: | ||
| - CGO_ENABLED=0 | ||
| flags: | ||
| - -trimpath | ||
| ldflags: | ||
| - -s -w | ||
| - -X k8s.io/component-base/version.gitVersion=v{{ .Version }} | ||
| mod_timestamp: "{{ .CommitTimestamp }}" | ||
| goos: | ||
| - linux | ||
| goarch: | ||
| - amd64 | ||
| - arm64 | ||
|
|
||
| kos: | ||
| - build: oxide-cloud-controller-manager | ||
| base_image: "{{ .Env.KO_DEFAULTBASEIMAGE }}" | ||
| repositories: | ||
| - ghcr.io/oxidecomputer/oxide-cloud-controller-manager | ||
| platforms: | ||
| - linux/amd64 | ||
| - linux/arm64 | ||
| tags: | ||
| - "{{ .Version }}" | ||
| annotations: | ||
| org.opencontainers.image.description: Oxide Cloud Controller Manager | ||
| org.opencontainers.image.source: https://github.com/oxidecomputer/oxide-cloud-controller-manager | ||
| bare: true | ||
| preserve_import_paths: false | ||
| creation_time: "{{ .CommitTimestamp }}" | ||
| ko_data_creation_time: "{{ .CommitTimestamp }}" | ||
|
|
||
| checksum: | ||
| name_template: checksums.txt | ||
| extra_files: | ||
| - glob: ./_artifacts/helm/*.tgz | ||
| - glob: ./_artifacts/oxide-cloud-controller-manager.yaml | ||
|
|
||
| changelog: | ||
| use: github-native | ||
|
|
||
| release: | ||
| github: | ||
| owner: oxidecomputer | ||
| name: oxide-cloud-controller-manager | ||
| # Abort if the tag already has an immutable release or no permissions. | ||
| preflight: | ||
| fail_on_error: true | ||
| extra_files: | ||
| - glob: ./_artifacts/helm/*.tgz | ||
| - glob: ./_artifacts/oxide-cloud-controller-manager.yaml | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,96 +1,64 @@ | ||
| VERSION ?= $(shell cat VERSION) | ||
| GO_VERSION := $(shell go list -m -f '{{.GoVersion}}') | ||
| GO_CONTAINER_IMAGE ?= docker.io/golang:$(GO_VERSION) | ||
|
|
||
| # Set this to non-empty when building and pushing a release. | ||
| RELEASE ?= | ||
| VERSION ?= $(shell git describe --tags --dirty 2>/dev/null || echo v0.0.0-dev) | ||
|
|
||
| CONTAINER_RUNTIME ?= $(shell command -v podman 2>/dev/null || command -v docker 2>/dev/null) | ||
| ifeq ($(CONTAINER_RUNTIME),) | ||
| $(error No container runtime found. Please install podman or docker) | ||
| endif | ||
|
|
||
| PLATFORM ?= linux/amd64,linux/arm64 | ||
|
|
||
| GIT_COMMIT_SHORT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown") | ||
|
|
||
| # Container image configuration. | ||
| IMAGE_REGISTRY ?= ghcr.io/oxidecomputer | ||
| IMAGE_NAME ?= oxide-cloud-controller-manager | ||
| IMAGE_TAG ?= $(patsubst v%,%,$(VERSION))$(if $(RELEASE),,-$(GIT_COMMIT_SHORT)) | ||
| IMAGE_TAG ?= $(patsubst v%,%,$(VERSION)) | ||
| IMAGE_FULL ?= $(if $(IMAGE_REGISTRY),$(IMAGE_REGISTRY)/)$(IMAGE_NAME):$(IMAGE_TAG) | ||
| export KO_DEFAULTBASEIMAGE ?= gcr.io/distroless/static-debian13:nonroot | ||
|
|
||
| # Helm chart configuration. | ||
| HELM_CHART_DIR ?= charts/oxide-cloud-controller-manager | ||
| HELM_CHART_REGISTRY ?= oci://ghcr.io/oxidecomputer/helm-charts | ||
| HELM ?= go tool -modfile tools/go.mod helm | ||
|
|
||
| SED := sed | ||
| OS := $(shell uname) | ||
| ifeq ($(OS), Darwin) | ||
| SED := gsed | ||
| endif | ||
| ARTIFACTS ?= _artifacts | ||
| GORELEASER ?= go tool -modfile tools/go.mod goreleaser | ||
| KO ?= go tool -modfile tools/go.mod ko | ||
|
Comment on lines
+17
to
+18
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how useful it would be in this case, since we only seem to be using two tools for now, but in Terraform I don this: |
||
|
|
||
| .PHONY: test | ||
| test: | ||
| @echo "Running tests in container..." | ||
| $(CONTAINER_RUNTIME) build \ | ||
| --file Containerfile \ | ||
| --build-arg GO_CONTAINER_IMAGE=$(GO_CONTAINER_IMAGE) \ | ||
| --build-arg VERSION=$(VERSION) \ | ||
| --target builder \ | ||
| --tag $(if $(IMAGE_REGISTRY),$(IMAGE_REGISTRY)/)$(IMAGE_NAME)-builder:$(IMAGE_TAG) \ | ||
| . | ||
| $(CONTAINER_RUNTIME) run --rm $(if $(IMAGE_REGISTRY),$(IMAGE_REGISTRY)/)$(IMAGE_NAME)-builder:$(IMAGE_TAG) go test -v ./... | ||
| go test -v ./... | ||
|
|
||
| # Builds a host-arch image with ko, then loads it into podman or docker. | ||
| .PHONY: build | ||
| build: | ||
| ifeq ($(CONTAINER_RUNTIME),) | ||
| $(error No container runtime found. Please install podman or docker) | ||
| endif | ||
| @echo "Building container image: $(IMAGE_FULL)" | ||
| $(CONTAINER_RUNTIME) build \ | ||
| --file Containerfile \ | ||
| --build-arg GO_CONTAINER_IMAGE=$(GO_CONTAINER_IMAGE) \ | ||
| --build-arg VERSION=$(VERSION) \ | ||
| --annotation org.opencontainers.image.description='Oxide Cloud Controller Manager' \ | ||
| --annotation org.opencontainers.image.source=https://github.com/oxidecomputer/oxide-cloud-controller-manager \ | ||
| --tag $(IMAGE_FULL) \ | ||
| . | ||
|
|
||
| .PHONY: push | ||
| push: | ||
| # Note: use docker rather than $(CONTAINER_RUNTIME), since we want to push | ||
| # multi-arch images, and docker and podman use different multi-arch flags. | ||
| @echo "Pushing container image: $(IMAGE_FULL)" | ||
| docker buildx build \ | ||
| --platform $(PLATFORM) \ | ||
| --file Containerfile \ | ||
| --build-arg GO_CONTAINER_IMAGE=$(GO_CONTAINER_IMAGE) \ | ||
| --build-arg VERSION=$(VERSION) \ | ||
| --annotation org.opencontainers.image.description='Oxide Cloud Controller Manager' \ | ||
| --annotation org.opencontainers.image.source=https://github.com/oxidecomputer/oxide-cloud-controller-manager \ | ||
| --tag $(IMAGE_FULL) \ | ||
| --push \ | ||
| . | ||
|
|
||
| .PHONY: helm-set-version | ||
| helm-set-version: | ||
| @$(SED) -i 's/^version: .*/version: "$(patsubst v%,%,$(VERSION))"/' $(HELM_CHART_DIR)/Chart.yaml | ||
| @$(SED) -i 's/^appVersion: .*/appVersion: "$(patsubst v%,%,$(VERSION))"/' $(HELM_CHART_DIR)/Chart.yaml | ||
|
|
||
| .PHONY: manifest | ||
| manifest: helm-set-version | ||
| @echo "Generating Kubernetes manifest: manifests/oxide-cloud-controller-manager.yaml" | ||
| $(HELM) template oxide-cloud-controller-manager $(HELM_CHART_DIR) \ | ||
| mkdir -p $(ARTIFACTS) | ||
| KO_DOCKER_REPO=$(if $(IMAGE_REGISTRY),$(IMAGE_REGISTRY)/)$(IMAGE_NAME) \ | ||
| GOFLAGS=-ldflags=-X=k8s.io/component-base/version.gitVersion=$(VERSION) \ | ||
| $(KO) build . \ | ||
| --bare \ | ||
| --tags $(IMAGE_TAG) \ | ||
| --platform linux/$(shell go env GOARCH) \ | ||
| --push=false \ | ||
| --tarball $(ARTIFACTS)/image.tar | ||
| $(CONTAINER_RUNTIME) load --input $(ARTIFACTS)/image.tar | ||
|
|
||
| .PHONY: manifests | ||
| manifests: | ||
| rm -rf $(ARTIFACTS) | ||
| mkdir -p $(ARTIFACTS)/helm | ||
| $(HELM) package $(HELM_CHART_DIR) \ | ||
| --version $(patsubst v%,%,$(VERSION)) \ | ||
| --app-version $(patsubst v%,%,$(VERSION)) \ | ||
| --destination $(ARTIFACTS)/helm | ||
| $(HELM) template oxide-cloud-controller-manager $(ARTIFACTS)/helm/*.tgz \ | ||
| --namespace kube-system \ | ||
| > manifests/oxide-cloud-controller-manager.yaml | ||
| > $(ARTIFACTS)/oxide-cloud-controller-manager.yaml | ||
|
|
||
| .PHONY: helm-package | ||
| helm-package: helm-set-version | ||
| $(HELM) package $(HELM_CHART_DIR) | ||
| .PHONY: release-dry-run | ||
| release-dry-run: | ||
| $(GORELEASER) release --snapshot --clean | ||
|
|
||
| .PHONY: helm-push | ||
| helm-push: helm-package | ||
| $(HELM) push $(IMAGE_NAME)-$(patsubst v%,%,$(VERSION)).tgz \ | ||
| $(HELM_CHART_REGISTRY) | ||
| .PHONY: release | ||
| release: | ||
| $(GORELEASER) release --clean | ||
| $(HELM) push $(ARTIFACTS)/helm/*.tgz $(HELM_CHART_REGISTRY) | ||
|
|
||
| .PHONY: fmt | ||
| fmt: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine
.Versionis the tag, but I'm not sure where it's been set. Is it a "magical" value provided by goreleaser?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's magically provided by goreleaser. It's basically the tag without a "v" prefix. Different types of builds can produce a suffix like
-SNAPSHOT, but all derived by tag unless overridden. There's a whole list of magical vars you can use for templating with goreleaser: https://goreleaser.com/customization/general/templates/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was my question too when reading the code. Ideally, I like the version for projects to have a single source of truth, but it's not always clear what the source should be across the Go binary, GoReleaser, container image tags, and Helm charts. In the Omni infrastructure provider I switched to using the Go module version as the source of truth using
-buildvcs, but that only publishes a binary, not a container image or Helm chart.I'm trying not to go back to a
VERSIONfile, but I see how its simplicity wins out many times.I was happy to see that a
make builduses the tag and commit for a non-release version though:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible we have a
make versionthat is the single source of truth version that is derived from the goreleaser version today and pass it back into goreleaser so its explicit. Then, we could swap out the version in the future. I mainly don't like theVERSIONfile because it requires either a pre-release or a post-release step.I have snapshot releases as a follow-up to this PR (already implemented in karpenter and CAPOx) that will publish all assets as a draft snapshot release.