Skip to content

Commit 4812465

Browse files
kranurag7nrb
andauthored
✨ use goreleaser for releasing binary (#4748)
* use goreleaser for releasing the binaries Signed-off-by: Anurag <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * Update documentation and remove unused targets Signed-off-by: Nolan Brubaker <[email protected]> * Remove unused gh targets/client Signed-off-by: Nolan Brubaker <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * Remove reference to unused steps Signed-off-by: Nolan Brubaker <[email protected]> --------- Signed-off-by: Anurag <[email protected]> Signed-off-by: Nolan Brubaker <[email protected]> Co-authored-by: Nolan Brubaker <[email protected]>
1 parent dd2962d commit 4812465

File tree

11 files changed

+505
-126
lines changed

11 files changed

+505
-126
lines changed

.github/workflows/release.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write # required to write to github release.
10+
11+
jobs:
12+
release:
13+
name: Create draft release
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
- name: Set up Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version: '1.21'
24+
- name: Set version info
25+
run: |
26+
echo "VERSION=${GITHUB_REF_NAME}" >> $GITHUB_ENV
27+
echo "PREVIOUS_VERSION=$(git describe --abbrev=0 2> /dev/null)" >> $GITHUB_ENV
28+
echo "RELEASE_BRANCH=release-$(echo ${GITHUB_REF_NAME} | grep -Eo '[0-9]\.[0-9]+')" >> $GITHUB_ENV
29+
echo "RELEASE_TAG=${GITHUB_REF_NAME}" >> $GITHUB_ENV
30+
- name: Run release
31+
run: |
32+
echo "Version is: $VERSION"
33+
echo "Previous version is: $PREVIOUS_VERSION"
34+
echo "Release branch is: $RELEASE_BRANCH"
35+
echo "Release tag is: $RELEASE_TAG"
36+
make release
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ junit.*.xml
5757
.DS_Store
5858

5959
.tiltbuild
60+
dist
6061

6162
# test results
6263
_artifacts

.goreleaser.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
builds:
2+
# clusterctl-aws
3+
- id: "clusterctl-aws"
4+
main: ./cmd/clusterawsadm
5+
binary: bin/clusterctl-aws
6+
env:
7+
- CGO_ENABLED=0
8+
ldflags:
9+
- -s -w
10+
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitMajor={{.Major}}'
11+
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitMinor={{.Minor}}'
12+
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitVersion={{.Version}}'
13+
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitCommit={{.Commit}}'
14+
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitTreeState={{.GitTreeState}}'
15+
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.buildDate={{.Date}}'
16+
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/cmd/clusterawsadm/cmd/version.CLIName=clusterctl-aws'
17+
goos:
18+
- linux
19+
- darwin
20+
- windows
21+
goarch:
22+
- amd64
23+
- arm64
24+
25+
# clusterawsadm
26+
- id: "clusterawsadm"
27+
main: ./cmd/clusterawsadm
28+
binary: bin/clusterawsadm
29+
env:
30+
- CGO_ENABLED=0
31+
ldflags:
32+
- -s -w
33+
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitMajor={{.Major}}'
34+
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitMinor={{.Minor}}'
35+
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitVersion={{.Version}}'
36+
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitCommit={{.Commit}}'
37+
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.gitTreeState={{.GitTreeState}}'
38+
- -X 'sigs.k8s.io/cluster-api-provider-aws/v2/version.buildDate={{.Date}}'
39+
goos:
40+
- linux
41+
- darwin
42+
- windows
43+
goarch:
44+
- amd64
45+
- arm64
46+
47+
archives:
48+
- id: clusterctl-aws
49+
builds:
50+
- clusterctl-aws
51+
name_template: "clusterctl-aws_{{ .Tag }}_{{ .Os }}_{{ .Arch }}"
52+
format: binary
53+
- id: clusterawsadm
54+
builds:
55+
- clusterawsadm
56+
name_template: "clusterawsadm_{{ .Tag }}_{{ .Os }}_{{ .Arch }}"
57+
format: binary
58+
59+
release:
60+
discussion_category_name: General
61+
extra_files:
62+
- glob: ./templates/*.yaml
63+
- glob: ./out/*
64+
draft: true

Makefile

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ E2E_CONF_PATH ?= $(E2E_DATA_DIR)/e2e_conf.yaml
4646
E2E_EKS_CONF_PATH ?= $(E2E_DATA_DIR)/e2e_eks_conf.yaml
4747
KUBETEST_CONF_PATH ?= $(abspath $(E2E_DATA_DIR)/kubetest/conformance.yaml)
4848
EXP_DIR := exp
49+
GORELEASER_CONFIG := .goreleaser.yaml
4950

5051
# Binaries.
5152
GO_INSTALL := ./scripts/go_install.sh
@@ -70,6 +71,7 @@ SSM_PLUGIN := $(TOOLS_BIN_DIR)/session-manager-plugin
7071
YQ := $(TOOLS_BIN_DIR)/yq
7172
KPROMO := $(TOOLS_BIN_DIR)/kpromo
7273
RELEASE_NOTES := $(TOOLS_BIN_DIR)/release-notes
74+
GORELEASER := $(TOOLS_BIN_DIR)/goreleaser
7375

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

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

504-
.PHONY: create-gh-release
505-
create-gh-release:$(GH) ## Create release on Github
506-
$(GH) release create $(VERSION) -d -F $(RELEASE_DIR)/CHANGELOG.md -t $(VERSION) -R $(GH_REPO)
507-
508506
.PHONY: compiled-manifest
509507
compiled-manifest: $(RELEASE_DIR) $(KUSTOMIZE) ## Compile the manifest files
510508
$(MAKE) image-patch-source-manifest
@@ -565,13 +563,12 @@ list-image: ## List images for RELEASE_TAG
565563
gcloud container images list-tags $(STAGING_REGISTRY)/$(IMAGE) --filter="tags=('$(RELEASE_TAG)')" --format=json
566564

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

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

@@ -605,28 +602,8 @@ promote-images: $(KPROMO) $(YQ)
605602
$(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
606603

607604
.PHONY: release-binaries
608-
release-binaries: ## Builds the binaries to publish with a release
609-
RELEASE_BINARY=./cmd/clusterawsadm GOOS=linux GOARCH=amd64 $(MAKE) release-binary
610-
RELEASE_BINARY=./cmd/clusterawsadm GOOS=linux GOARCH=arm64 $(MAKE) release-binary
611-
RELEASE_BINARY=./cmd/clusterawsadm GOOS=darwin GOARCH=amd64 $(MAKE) release-binary
612-
RELEASE_BINARY=./cmd/clusterawsadm GOOS=darwin GOARCH=arm64 $(MAKE) release-binary
613-
RELEASE_BINARY=./cmd/clusterawsadm GOOS=windows GOARCH=amd64 EXT=.exe $(MAKE) release-binary
614-
RELEASE_BINARY=./cmd/clusterawsadm GOOS=windows GOARCH=arm64 EXT=.exe $(MAKE) release-binary
615-
616-
.PHONY: release-binary
617-
release-binary: $(RELEASE_DIR) versions.mk ## Release binary
618-
docker run \
619-
--rm \
620-
-e CGO_ENABLED=0 \
621-
-e GOOS=$(GOOS) \
622-
-e GOARCH=$(GOARCH) \
623-
-e GOCACHE=/tmp/ \
624-
--user $$(id -u):$$(id -g) \
625-
-v "$$(pwd):/workspace$(DOCKER_VOL_OPTS)" \
626-
-w /workspace \
627-
$(GO_CONTAINER_IMAGE) \
628-
go build -ldflags '$(LDFLAGS) -extldflags "-static"' \
629-
-o $(RELEASE_DIR)/$(notdir $(RELEASE_BINARY))-$(GOOS)-$(GOARCH)$(EXT) $(RELEASE_BINARY)
605+
release-binaries: $(GORELEASER) ## Builds only the binaries, not a release.
606+
$(GORELEASER) build --config $(GORELEASER_CONFIG) --snapshot --clean
630607

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

651-
.PHONY: release-templates
652-
release-templates: $(RELEASE_DIR) ## Generate release templates
653-
cp templates/cluster-template*.yaml $(RELEASE_DIR)/
654-
655628
.PHONY: upload-staging-artifacts
656629
upload-staging-artifacts: ## Upload release artifacts to the staging bucket
657630
gsutil cp $(RELEASE_DIR)/* gs://$(BUCKET)/components/$(RELEASE_ALIAS_TAG)
658631

659-
.PHONY: upload-gh-artifacts
660-
upload-gh-artifacts: $(GH) ## Upload artifacts to Github release
661-
$(GH) release upload $(VERSION) -R $(GH_REPO) --clobber $(RELEASE_DIR)/*
662-
663632
IMAGE_PATCH_DIR := $(ARTIFACTS)/image-patch
664633

665634
$(IMAGE_PATCH_DIR): $(ARTIFACTS)

cmd/clusterawsadm/cmd/version/version.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ type Version struct {
3434
ClientVersion *version.Info `json:"awsProviderVersion"`
3535
}
3636

37+
// CLIName defaults to clusterawsadm.
38+
var CLIName = "clusterawsadm"
39+
3740
// Cmd provides the version information clusterawsadm.
3841
func Cmd(out io.Writer) *cobra.Command {
3942
cmd := &cobra.Command{
@@ -64,7 +67,7 @@ func RunVersion(out io.Writer, cmd *cobra.Command) error {
6467

6568
switch of {
6669
case "":
67-
fmt.Fprintf(out, "clusterawsadm version: %#v\n", v.ClientVersion)
70+
fmt.Fprintf(out, "%s version: %#v\n", CLIName, v.ClientVersion)
6871
case "short":
6972
fmt.Fprintf(out, "%s\n", v.ClientVersion.GitVersion)
7073
case "yaml":

docs/book/src/development/releasing.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414
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.
1515
1. Update the release branch on the repository, e.g. `git push upstream HEAD:release-1.5`. `upstream` refers to the upstream git reference.
1616
1. Make sure your repo is clean by git standards.
17-
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.
18-
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`).
17+
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`).
1918
_**Note**_: the version MUST contain a `v` in front.
2019
_**Note**_: you must have a gpg signing configured with git and registered with GitHub.
2120

2221
1. Create a tag `git tag -s -m $VERSION $VERSION`. `-s` flag is for GNU Privacy Guard (GPG) signing.
23-
1. Make sure you have push permissions to the upstream CAPA repo. Push tag you've just created (`git push <upstream-repo-remote> $VERSION`).
22+
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.
2423
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>.
2524
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 <...>`.
2625

@@ -53,30 +52,34 @@ Promote the container images from the staging registry to the production registr
5352
docker pull registry.k8s.io/cluster-api-aws/cluster-api-aws-controller:${VERSION}
5453
```
5554
56-
## Create release artifacts, and a GitHub draft release
5755
58-
1. Again, make sure your repo is clean by git standards.
59-
1. Export the current branch `export BRANCH=release-1.5` (`export BRANCH=main`)and run `make release`.
60-
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.
61-
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.
56+
## Verify and Publish the draft release
57+
6258
1. Verify that all the files below are attached to the drafted release:
6359
1. `clusterawsadm-darwin-amd64`
60+
1. `clusterawsadm-darwin-arm64`
6461
1. `clusterawsadm-linux-amd64`
62+
1. `clusterawsadm-linux-arm64`
63+
1. `clusterawsadm-windows-amd64.exe`
64+
1. `clusterawsadm-windows-arm64.exe`
6565
1. `infrastructure-components.yaml`
6666
1. `cluster-template.yaml`
6767
1. `cluster-template-machinepool.yaml`
6868
1. `cluster-template-eks.yaml`
69+
1. `cluster-template-eks-ipv6.yaml`
70+
1. `cluster-template-eks-fargate.yaml`
6971
1. `cluster-template-eks-managedmachinepool.yaml`
7072
1. `cluster-template-eks-managedmachinepool-vpccni.yaml`
7173
1. `cluster-template-eks-managedmachinepool-gpu.yaml`
72-
1. `eks-controlplane-components.yaml`
73-
1. `eks-bootstrap-components.yaml`
74+
1. `cluster-template-external-cloud-provider.yaml`
75+
1. `cluster-template-flatcar.yaml`
76+
1. `cluster-template-machinepool.yaml`
77+
1. `cluster-template-multitenancy-clusterclass.yaml`
78+
1. `cluster-template-rosa-machinepool.yaml`
79+
1. `cluster-template-rosa.yaml`
80+
1. `cluster-template-simple-clusterclass.yaml`
7481
1. `metadata.yaml`
75-
1. Finalise the release notes by editing the draft release.
76-
_**Note**_: ONLY do this _after_ you verified that the promotion succeeded [here](https://testgrid.k8s.io/sig-k8s-infra-k8sio#post-k8sio-image-promo).
77-
78-
## Publish the draft release
79-
82+
1. Update the release description to link to the promotion image.
8083
1. Publish release. Use the pre-release option for release candidate versions of Cluster API Provider AWS.
8184
1. Email `[email protected]` to announce the release. You can use this template for the email:
8285

hack/tools/Makefile

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,6 @@ GENCRDAPIREFERENCEDOCS := $(BIN_DIR)/gen-crd-api-reference-docs
9494
$(GENCRDAPIREFERENCEDOCS): $(BIN_DIR) go.mod go.sum # Build gen-crd-api-reference-docs from tools folder.
9595
go build -tags=tools -o $@ github.com/ahmetb/gen-crd-api-reference-docs
9696

97-
GH_SHARE := $(SHARE_DIR)/gh
98-
99-
$(GH_SHARE): $(SHARE_DIR)
100-
mkdir -p $@
101-
102-
$(GH_SHARE)/gh.tar.gz: $(GH_SHARE)
103-
curl -L "https://github.com/cli/cli/releases/download/v$(GH_VERSION)/gh_$(GH_VERSION)_$(GH_ARCH_SUFFIX).tar.gz" -o $@
104-
105-
GH := $(BIN_DIR)/gh
106-
$(GH): $(GTAR) $(GH_SHARE)/gh.tar.gz
107-
$(GTAR) -xvf share/gh/gh.tar.gz gh_$(GH_VERSION)_$(GH_ARCH_SUFFIX)/bin/gh --strip-components 1 --directory $(BIN_DIR)
108-
chmod +x $@
109-
touch -m $@
110-
11197
GOJQ := $(BIN_DIR)/gojq
11298
$(GOJQ): $(BIN_DIR) go.mod go.sum
11399
go build -tags=tools -o $@ github.com/itchyny/gojq/cmd/gojq
@@ -174,6 +160,15 @@ $(RELEASE_NOTES_BIN): $(RELEASE_NOTES)
174160
$(RELEASE_NOTES): ## Build release notes from tools folders.
175161
GOBIN=$(abspath $(BIN_DIR)) go install $(RELEASE_NOTES_PKG)@$(RELEASE_NOTES_VERSION)
176162

163+
GORELEASER_BIN := goreleaser
164+
GORELEASER := $(BIN_DIR)/$(GORELEASER_BIN)
165+
GORELEASER_PKG := github.com/goreleaser/goreleaser
166+
.PHONY: $(GORELEASER_BIN)
167+
$(GORELEASER_BIN): $(GORELEASER)
168+
169+
$(GORELEASER):
170+
GOBIN=$(abspath $(BIN_DIR)) go install $(GORELEASER_PKG)@$(GORELEASER_VERSION)
171+
177172

178173
## ------------------------------------------------------------------------------------------------
179174
## AWS Session Manager Plugin Installation. Currently support Linux and MacOS AMD64 architectures.

0 commit comments

Comments
 (0)