Skip to content
Open
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
8 changes: 8 additions & 0 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v7

- name: Set up Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache-dependency-path: |
go.sum
tools/go.sum

- name: Build Container Image
run: make build

Expand Down
31 changes: 0 additions & 31 deletions .github/workflows/manifest.yaml

This file was deleted.

69 changes: 4 additions & 65 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,75 +14,14 @@ concurrency:
cancel-in-progress: true

jobs:
check-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7

- name: Check git tag
run: |
GIT_VERSION="${GITHUB_REF_NAME}"
FILE_VERSION=$(cat VERSION)
if [ "$GIT_VERSION" != "$FILE_VERSION" ]; then
echo "::error::Tag $GIT_VERSION does not match VERSION file ($FILE_VERSION)"
exit 1
fi

release:
runs-on: ubuntu-latest
needs: [docker, helm]
steps:
# Fetch full history so that we can find the previous git tag.
- uses: actions/checkout@v7
with:
fetch-depth: 0

- name: Create or update release
run: |
# Create a release, with generated notes starting from the previous tag.
PREV=$(git describe --tags --abbrev=0 "${GITHUB_REF_NAME}^" 2>/dev/null || true)
NOTES_ARGS="--generate-notes"
PREV_COMMIT_ARG=""
if [ -n "$PREV" ]; then
NOTES_ARGS="$NOTES_ARGS --notes-start-tag $PREV"
PREV_COMMIT_ARG="-f previous_tag_name=$PREV"
fi
if gh release view ${{ github.ref_name }} > /dev/null 2>&1; then
BODY=$(gh api -X POST "/repos/${GITHUB_REPOSITORY}/releases/generate-notes" \
-f tag_name="${GITHUB_REF_NAME}" $PREV_COMMIT_ARG \
-q .body)
gh release edit ${{ github.ref_name }} --notes "$BODY"
else
gh release create ${{ github.ref_name }} \
$NOTES_ARGS
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

docker:
runs-on: ubuntu-latest
needs: [check-version]
steps:
- uses: actions/checkout@v7

- uses: docker/setup-buildx-action@v4

- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: build and push
run: |
RELEASE=true make push

helm:
runs-on: ubuntu-latest
needs: [check-version, docker]
steps:
- uses: actions/checkout@v7

- uses: actions/setup-go@v7
with:
go-version-file: go.mod
Expand All @@ -96,7 +35,7 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: build and push
run: |
make helm-package
make helm-push
- name: release
run: make release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Ignore Helm packages.
*.tgz

/_artifacts/
/dist/
61 changes: 61 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
version: 2

before:
hooks:
- make manifests VERSION={{ .Version }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine .Version is the tag, but I'm not sure where it's been set. Is it a "magical" value provided by goreleaser?

Copy link
Copy Markdown
Contributor Author

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/

Copy link
Copy Markdown
Member

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 VERSION file, but I see how its simplicity wins out many times.

I was happy to see that a make build uses the tag and commit for a non-release version though:

> make build> make build
Building container image: ghcr.io/oxidecomputer/oxide-cloud-controller-manager:0.8.0-18-gb3c0460

Copy link
Copy Markdown
Contributor Author

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 version that 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 the VERSION file 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.


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
26 changes: 0 additions & 26 deletions Containerfile

This file was deleted.

110 changes: 39 additions & 71 deletions Makefile
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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:
https://github.com/oxidecomputer/terraform-provider-oxide/blob/8934dfd92115dadcbdaed5813c5d836c52e0e276/Makefile#L33


.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:
Expand Down
Loading