Skip to content

Commit

Permalink
✨ use goreleaser for releasing binary (kubernetes-sigs#4748)
Browse files Browse the repository at this point in the history
* use goreleaser for releasing the binaries

Signed-off-by: Anurag <81210977+kranurag7@users.noreply.github.com>

* disable releasing of binaries using make targets

since we intend to use goreleaser now, we can remove the make targets.
This commit does the same.

Signed-off-by: Anurag <81210977+kranurag7@users.noreply.github.com>

* Update release-binaries target to use goreleaser

* Add goreleaser as a tool dependency
* Update .goreleaser configuration to upload YAML templates as GitHub
  release artifacts
* Create binaries rather than archives to mimic current uploads.

Signed-off-by: Nolan Brubaker <nolan@nbrubaker.com>

* Update documentation and remove unused targets

Signed-off-by: Nolan Brubaker <nolan@nbrubaker.com>

* Remove unused gh targets/client

Signed-off-by: Nolan Brubaker <nolan@nbrubaker.com>

* Updates based on doing dry runs

* Remove Windows format override
* Move goreleaser invocation into the Makefile
* Add output directory to goreleaser configuration
* Use generated release notes as the release contents
* Run make release target inside the GitHub workflow
* Set expected environment variables in the GitHub workflow
* Build goreleaser before running the release target

Signed-off-by: Nolan Brubaker <nolan@nbrubaker.com>

* Updates based on doing dry runs

* Remove Windows format override
* Move goreleaser invocation into the Makefile
* Add output directory to goreleaser configuration
* Use generated release notes as the release contents
* Run make release target inside the GitHub workflow
* Set expected environment variables in the GitHub workflow
* Build goreleaser before running the release target
* Force goreleaser to use local config
* Set RELEASE_TAG env variable for release notes
* Output env vars for debugging
* Re-enable changelog support

Signed-off-by: Nolan Brubaker <nolan@nbrubaker.com>

* Remove reference to unused steps

Signed-off-by: Nolan Brubaker <nolan@nbrubaker.com>

---------

Signed-off-by: Anurag <81210977+kranurag7@users.noreply.github.com>
Signed-off-by: Nolan Brubaker <nolan@nbrubaker.com>
Co-authored-by: Nolan Brubaker <nolan@nbrubaker.com>
  • Loading branch information
kranurag7 and nrb committed Apr 12, 2024
1 parent dd2962d commit 4812465
Show file tree
Hide file tree
Showing 11 changed files with 505 additions and 126 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: release

on:
push:
tags:
- 'v*'

permissions:
contents: write # required to write to github release.

jobs:
release:
name: Create draft release
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Set version info
run: |
echo "VERSION=${GITHUB_REF_NAME}" >> $GITHUB_ENV
echo "PREVIOUS_VERSION=$(git describe --abbrev=0 2> /dev/null)" >> $GITHUB_ENV
echo "RELEASE_BRANCH=release-$(echo ${GITHUB_REF_NAME} | grep -Eo '[0-9]\.[0-9]+')" >> $GITHUB_ENV
echo "RELEASE_TAG=${GITHUB_REF_NAME}" >> $GITHUB_ENV
- name: Run release
run: |
echo "Version is: $VERSION"
echo "Previous version is: $PREVIOUS_VERSION"
echo "Release branch is: $RELEASE_BRANCH"
echo "Release tag is: $RELEASE_TAG"
make release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ junit.*.xml
.DS_Store

.tiltbuild
dist

# test results
_artifacts
Expand Down
64 changes: 64 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
builds:
# clusterctl-aws
- id: "clusterctl-aws"
main: ./cmd/clusterawsadm
binary: bin/clusterctl-aws
env:
- CGO_ENABLED=0
ldflags:
- -s -w
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitMajor={{.Major}}'
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitMinor={{.Minor}}'
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitVersion={{.Version}}'
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitCommit={{.Commit}}'
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitTreeState={{.GitTreeState}}'
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.buildDate={{.Date}}'
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/cmd/clusterawsadm/cmd/version.CLIName=clusterctl-aws'
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64

# clusterawsadm
- id: "clusterawsadm"
main: ./cmd/clusterawsadm
binary: bin/clusterawsadm
env:
- CGO_ENABLED=0
ldflags:
- -s -w
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitMajor={{.Major}}'
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitMinor={{.Minor}}'
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitVersion={{.Version}}'
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitCommit={{.Commit}}'
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitTreeState={{.GitTreeState}}'
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.buildDate={{.Date}}'
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64

archives:
- id: clusterctl-aws
builds:
- clusterctl-aws
name_template: "clusterctl-aws_{{ .Tag }}_{{ .Os }}_{{ .Arch }}"
format: binary
- id: clusterawsadm
builds:
- clusterawsadm
name_template: "clusterawsadm_{{ .Tag }}_{{ .Os }}_{{ .Arch }}"
format: binary

release:
discussion_category_name: General
extra_files:
- glob: ./templates/*.yaml
- glob: ./out/*
draft: true
43 changes: 6 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ E2E_CONF_PATH ?= $(E2E_DATA_DIR)/e2e_conf.yaml
E2E_EKS_CONF_PATH ?= $(E2E_DATA_DIR)/e2e_eks_conf.yaml
KUBETEST_CONF_PATH ?= $(abspath $(E2E_DATA_DIR)/kubetest/conformance.yaml)
EXP_DIR := exp
GORELEASER_CONFIG := .goreleaser.yaml

# Binaries.
GO_INSTALL := ./scripts/go_install.sh
Expand All @@ -70,6 +71,7 @@ SSM_PLUGIN := $(TOOLS_BIN_DIR)/session-manager-plugin
YQ := $(TOOLS_BIN_DIR)/yq
KPROMO := $(TOOLS_BIN_DIR)/kpromo
RELEASE_NOTES := $(TOOLS_BIN_DIR)/release-notes
GORELEASER := $(TOOLS_BIN_DIR)/goreleaser

CLUSTERAWSADM_SRCS := $(call rwildcard,.,cmd/clusterawsadm/*.*)

Expand Down Expand Up @@ -501,10 +503,6 @@ check-release-tag: ## Check if the release tag is set
@if [ -z "${RELEASE_TAG}" ]; then echo "RELEASE_TAG is not set"; exit 1; fi
@if ! [ -z "$$(git status --porcelain)" ]; then echo "Your local git repository contains uncommitted changes, use git clean before proceeding."; exit 1; fi

.PHONY: create-gh-release
create-gh-release:$(GH) ## Create release on Github
$(GH) release create $(VERSION) -d -F $(RELEASE_DIR)/CHANGELOG.md -t $(VERSION) -R $(GH_REPO)

.PHONY: compiled-manifest
compiled-manifest: $(RELEASE_DIR) $(KUSTOMIZE) ## Compile the manifest files
$(MAKE) image-patch-source-manifest
Expand Down Expand Up @@ -565,13 +563,12 @@ list-image: ## List images for RELEASE_TAG
gcloud container images list-tags $(STAGING_REGISTRY)/$(IMAGE) --filter="tags=('$(RELEASE_TAG)')" --format=json

.PHONY: release
release: clean-release check-release-tag $(RELEASE_DIR) ## Builds and push container images using the latest git tag for the commit.
release: clean-release check-release-tag $(RELEASE_DIR) $(GORELEASER) ## Builds and push container images using the latest git tag for the commit.
git checkout "${RELEASE_TAG}"
$(MAKE) release-changelog
$(MAKE) release-binaries
CORE_CONTROLLER_IMG=$(PROD_REGISTRY)/$(CORE_IMAGE_NAME) $(MAKE) release-manifests
$(MAKE) release-templates
$(MAKE) release-policies
$(GORELEASER) release --config $(GORELEASER_CONFIG) --release-notes $(RELEASE_DIR)/CHANGELOG.md --clean

release-policies: $(RELEASE_POLICIES) ## Release policies

Expand Down Expand Up @@ -605,28 +602,8 @@ promote-images: $(KPROMO) $(YQ)
$(KPROMO) pr --project cluster-api-aws --tag $(RELEASE_TAG) --reviewers "$(shell ./hack/get-project-maintainers.sh ${YQ})" --fork $(USER_FORK) --image cluster-api-aws-controller

.PHONY: release-binaries
release-binaries: ## Builds the binaries to publish with a release
RELEASE_BINARY=./cmd/clusterawsadm GOOS=linux GOARCH=amd64 $(MAKE) release-binary
RELEASE_BINARY=./cmd/clusterawsadm GOOS=linux GOARCH=arm64 $(MAKE) release-binary
RELEASE_BINARY=./cmd/clusterawsadm GOOS=darwin GOARCH=amd64 $(MAKE) release-binary
RELEASE_BINARY=./cmd/clusterawsadm GOOS=darwin GOARCH=arm64 $(MAKE) release-binary
RELEASE_BINARY=./cmd/clusterawsadm GOOS=windows GOARCH=amd64 EXT=.exe $(MAKE) release-binary
RELEASE_BINARY=./cmd/clusterawsadm GOOS=windows GOARCH=arm64 EXT=.exe $(MAKE) release-binary

.PHONY: release-binary
release-binary: $(RELEASE_DIR) versions.mk ## Release binary
docker run \
--rm \
-e CGO_ENABLED=0 \
-e GOOS=$(GOOS) \
-e GOARCH=$(GOARCH) \
-e GOCACHE=/tmp/ \
--user $$(id -u):$$(id -g) \
-v "$$(pwd):/workspace$(DOCKER_VOL_OPTS)" \
-w /workspace \
$(GO_CONTAINER_IMAGE) \
go build -ldflags '$(LDFLAGS) -extldflags "-static"' \
-o $(RELEASE_DIR)/$(notdir $(RELEASE_BINARY))-$(GOOS)-$(GOARCH)$(EXT) $(RELEASE_BINARY)
release-binaries: $(GORELEASER) ## Builds only the binaries, not a release.
$(GORELEASER) build --config $(GORELEASER_CONFIG) --snapshot --clean

.PHONY: release-staging
release-staging: ## Builds and push container images and manifests to the staging bucket.
Expand All @@ -648,18 +625,10 @@ release-staging-nightly: ## Tags and push container images to the staging bucket
release-alias-tag: # Adds the tag to the last build tag.
gcloud container images add-tag -q $(CORE_CONTROLLER_IMG):$(TAG) $(CORE_CONTROLLER_IMG):$(RELEASE_ALIAS_TAG)

.PHONY: release-templates
release-templates: $(RELEASE_DIR) ## Generate release templates
cp templates/cluster-template*.yaml $(RELEASE_DIR)/

.PHONY: upload-staging-artifacts
upload-staging-artifacts: ## Upload release artifacts to the staging bucket
gsutil cp $(RELEASE_DIR)/* gs://$(BUCKET)/components/$(RELEASE_ALIAS_TAG)

.PHONY: upload-gh-artifacts
upload-gh-artifacts: $(GH) ## Upload artifacts to Github release
$(GH) release upload $(VERSION) -R $(GH_REPO) --clobber $(RELEASE_DIR)/*

IMAGE_PATCH_DIR := $(ARTIFACTS)/image-patch

$(IMAGE_PATCH_DIR): $(ARTIFACTS)
Expand Down
5 changes: 4 additions & 1 deletion cmd/clusterawsadm/cmd/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ type Version struct {
ClientVersion *version.Info `json:"awsProviderVersion"`
}

// CLIName defaults to clusterawsadm.
var CLIName = "clusterawsadm"

// Cmd provides the version information clusterawsadm.
func Cmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -64,7 +67,7 @@ func RunVersion(out io.Writer, cmd *cobra.Command) error {

switch of {
case "":
fmt.Fprintf(out, "clusterawsadm version: %#v\n", v.ClientVersion)
fmt.Fprintf(out, "%s version: %#v\n", CLIName, v.ClientVersion)
case "short":
fmt.Fprintf(out, "%s\n", v.ClientVersion.GitVersion)
case "yaml":
Expand Down
33 changes: 18 additions & 15 deletions docs/book/src/development/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
1. Update the release branch on the repository, e.g. `git push origin HEAD:release-1.5`. `origin` refers to the remote git reference to your fork.
1. Update the release branch on the repository, e.g. `git push upstream HEAD:release-1.5`. `upstream` refers to the upstream git reference.
1. Make sure your repo is clean by git standards.
1. Set environment variable `GITHUB_TOKEN` to a GitHub personal access token. The token must have write access to the `kubernetes-sigs/cluster-api-provider-aws` repository.
1. Set environment variables `PREVIOUS_VERSION` which is the last release tag and `VERSION` which is the current release version, e.g. `export PREVIOUS_VERSION=v1.4.0 VERSION=v1.5.0`, or `export PREVIOUS_VERSION=v1.5.0 VERSION=v1.5.1`).
1. Set environment variables which is the last release tag and `VERSION` which is the current release version, e.g. `export VERSION=v1.5.0`, or `export VERSION=v1.5.1`).
_**Note**_: the version MUST contain a `v` in front.
_**Note**_: you must have a gpg signing configured with git and registered with GitHub.

1. Create a tag `git tag -s -m $VERSION $VERSION`. `-s` flag is for GNU Privacy Guard (GPG) signing.
1. Make sure you have push permissions to the upstream CAPA repo. Push tag you've just created (`git push <upstream-repo-remote> $VERSION`).
1. Make sure you have push permissions to the upstream CAPA repo. Push tag you've just created (`git push <upstream-repo-remote> $VERSION`). Pushing this tag will kick off a GitHub Action that will create the release and attach the binaries and YAML templates to it.
1. A prow job will start running to push images to the staging repo, can be seen [here](https://testgrid.k8s.io/sig-cluster-lifecycle-image-pushes#post-cluster-api-provider-aws-push-images). The job is called "post-cluster-api-provider-aws-push-images," and is defined in <https://github.com/kubernetes/test-infra/blob/master/config/jobs/image-pushing/k8s-staging-cluster-api.yaml>.
1. When the job is finished, wait for the images to be created: `docker pull gcr.io/k8s-staging-cluster-api-aws/cluster-api-aws-controller:$VERSION`. You can also wrap this with a command to retry periodically, until the job is complete, e.g. `watch --interval 30 --chgexit docker pull <...>`.

Expand Down Expand Up @@ -53,30 +52,34 @@ Promote the container images from the staging registry to the production registr
docker pull registry.k8s.io/cluster-api-aws/cluster-api-aws-controller:${VERSION}
```

## Create release artifacts, and a GitHub draft release

1. Again, make sure your repo is clean by git standards.
1. Export the current branch `export BRANCH=release-1.5` (`export BRANCH=main`)and run `make release`.
1. Run `make create-gh-release` to create a draft release on Github, copying the generated release notes from `out/CHANGELOG.md` into the draft.
1. Run `make upload-gh-artifacts` to upload artifacts from .out/ directory. You may run into API limit errors, so verify artifacts at next step.
## Verify and Publish the draft release

1. Verify that all the files below are attached to the drafted release:
1. `clusterawsadm-darwin-amd64`
1. `clusterawsadm-darwin-arm64`
1. `clusterawsadm-linux-amd64`
1. `clusterawsadm-linux-arm64`
1. `clusterawsadm-windows-amd64.exe`
1. `clusterawsadm-windows-arm64.exe`
1. `infrastructure-components.yaml`
1. `cluster-template.yaml`
1. `cluster-template-machinepool.yaml`
1. `cluster-template-eks.yaml`
1. `cluster-template-eks-ipv6.yaml`
1. `cluster-template-eks-fargate.yaml`
1. `cluster-template-eks-managedmachinepool.yaml`
1. `cluster-template-eks-managedmachinepool-vpccni.yaml`
1. `cluster-template-eks-managedmachinepool-gpu.yaml`
1. `eks-controlplane-components.yaml`
1. `eks-bootstrap-components.yaml`
1. `cluster-template-external-cloud-provider.yaml`
1. `cluster-template-flatcar.yaml`
1. `cluster-template-machinepool.yaml`
1. `cluster-template-multitenancy-clusterclass.yaml`
1. `cluster-template-rosa-machinepool.yaml`
1. `cluster-template-rosa.yaml`
1. `cluster-template-simple-clusterclass.yaml`
1. `metadata.yaml`
1. Finalise the release notes by editing the draft release.
_**Note**_: ONLY do this _after_ you verified that the promotion succeeded [here](https://testgrid.k8s.io/sig-k8s-infra-k8sio#post-k8sio-image-promo).

## Publish the draft release

1. Update the release description to link to the promotion image.
1. Publish release. Use the pre-release option for release candidate versions of Cluster API Provider AWS.
1. Email `kubernetes-sig-cluster-lifecycle@googlegroups.com` to announce the release. You can use this template for the email:

Expand Down
23 changes: 9 additions & 14 deletions hack/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,6 @@ GENCRDAPIREFERENCEDOCS := $(BIN_DIR)/gen-crd-api-reference-docs
$(GENCRDAPIREFERENCEDOCS): $(BIN_DIR) go.mod go.sum # Build gen-crd-api-reference-docs from tools folder.
go build -tags=tools -o $@ github.com/ahmetb/gen-crd-api-reference-docs

GH_SHARE := $(SHARE_DIR)/gh

$(GH_SHARE): $(SHARE_DIR)
mkdir -p $@

$(GH_SHARE)/gh.tar.gz: $(GH_SHARE)
curl -L "https://github.com/cli/cli/releases/download/v$(GH_VERSION)/gh_$(GH_VERSION)_$(GH_ARCH_SUFFIX).tar.gz" -o $@

GH := $(BIN_DIR)/gh
$(GH): $(GTAR) $(GH_SHARE)/gh.tar.gz
$(GTAR) -xvf share/gh/gh.tar.gz gh_$(GH_VERSION)_$(GH_ARCH_SUFFIX)/bin/gh --strip-components 1 --directory $(BIN_DIR)
chmod +x $@
touch -m $@

GOJQ := $(BIN_DIR)/gojq
$(GOJQ): $(BIN_DIR) go.mod go.sum
go build -tags=tools -o $@ github.com/itchyny/gojq/cmd/gojq
Expand Down Expand Up @@ -174,6 +160,15 @@ $(RELEASE_NOTES_BIN): $(RELEASE_NOTES)
$(RELEASE_NOTES): ## Build release notes from tools folders.
GOBIN=$(abspath $(BIN_DIR)) go install $(RELEASE_NOTES_PKG)@$(RELEASE_NOTES_VERSION)

GORELEASER_BIN := goreleaser
GORELEASER := $(BIN_DIR)/$(GORELEASER_BIN)
GORELEASER_PKG := github.com/goreleaser/goreleaser
.PHONY: $(GORELEASER_BIN)
$(GORELEASER_BIN): $(GORELEASER)

$(GORELEASER):
GOBIN=$(abspath $(BIN_DIR)) go install $(GORELEASER_PKG)@$(GORELEASER_VERSION)


## ------------------------------------------------------------------------------------------------
## AWS Session Manager Plugin Installation. Currently support Linux and MacOS AMD64 architectures.
Expand Down
Loading

0 comments on commit 4812465

Please sign in to comment.