Skip to content

Commit 80fdc89

Browse files
authored
release scripts (#411)
1 parent 6cd1dfb commit 80fdc89

File tree

8 files changed

+793
-15
lines changed

8 files changed

+793
-15
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ vendor/sigs.k8s.io/cluster-api/docs/book/*.json
3030

3131
# tilt
3232
.tiltbuild
33+
34+
# release
35+
_artifacts/
36+
out/

Makefile

Lines changed: 135 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,33 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
ROOT_DIR_RELATIVE := .
16+
17+
include $(ROOT_DIR_RELATIVE)/common.mk
18+
1519
# Image URL to use all building/pushing image targets
1620
IMG ?= controller:latest
1721
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
1822
CRD_OPTIONS ?= "crd:crdVersions=v1"
23+
24+
# Directories.
25+
REPO_ROOT := $(shell git rev-parse --show-toplevel)
26+
ARTIFACTS ?= $(REPO_ROOT)/_artifacts
1927
TOOLS_DIR := hack/tools
20-
TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin)
28+
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
2129
GO_INSTALL = ./scripts/go_install.sh
22-
GOLANGCI_LINT_VER := v1.31.0
23-
GOLANGCI_LINT_BIN := golangci-lint
24-
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)
30+
31+
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
32+
KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize
33+
GOJQ := $(TOOLS_BIN_DIR)/gojq
2534

2635
STAGING_REGISTRY ?= gcr.io/k8s-staging-capi-ibmcloud
36+
PROD_REGISTRY := k8s.gcr.io/capi-ibmcloud
2737
REGISTRY ?= $(STAGING_REGISTRY)
2838
RELEASE_TAG ?= $(shell git describe --abbrev=0 2>/dev/null)
2939
PULL_BASE_REF ?= $(RELEASE_TAG) # PULL_BASE_REF will be provided by Prow
3040
RELEASE_ALIAS_TAG ?= $(PULL_BASE_REF)
41+
RELEASE_DIR := out
3142

3243
TAG ?= dev
3344
ARCH ?= amd64
@@ -36,6 +47,11 @@ ALL_ARCH ?= amd64 ppc64le
3647
# main controller
3748
CORE_IMAGE_NAME ?= cluster-api-ibmcloud-controller
3849
CORE_CONTROLLER_IMG ?= $(REGISTRY)/$(CORE_IMAGE_NAME)
50+
CORE_CONTROLLER_ORIGINAL_IMG := gcr.io/k8s-staging-capi-ibmcloud/cluster-api-ibmcloud-controller
51+
CORE_CONTROLLER_NAME := controller-manager
52+
CORE_MANIFEST_FILE := infrastructure-components
53+
CORE_CONFIG_DIR := config/default
54+
CORE_NAMESPACE := capi-ibmcloud-system
3955

4056
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
4157
ifeq (,$(shell go env GOBIN))
@@ -113,9 +129,6 @@ endif
113129
lint: $(GOLANGCI_LINT) ## Lint codebase
114130
$(GOLANGCI_LINT) run -v --fast=false
115131

116-
$(GOLANGCI_LINT): ## Build golangci-lint from tools folder.
117-
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) github.com/golangci/golangci-lint/cmd/golangci-lint $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)
118-
119132
## --------------------------------------
120133
## Docker
121134
## --------------------------------------
@@ -165,15 +178,126 @@ docker-push-manifest:
165178
## Release
166179
## --------------------------------------
167180

168-
.PHONY: release-alias-tag
169-
release-alias-tag: # Adds the tag to the last build tag.
170-
gcloud container images add-tag -q $(CORE_CONTROLLER_IMG):$(TAG) $(CORE_CONTROLLER_IMG):$(RELEASE_ALIAS_TAG)
181+
$(RELEASE_DIR):
182+
mkdir -p $@
183+
184+
$(ARTIFACTS):
185+
mkdir -p $@
186+
187+
.PHONY: list-staging-releases
188+
list-staging-releases: ## List staging images for image promotion
189+
@echo $(CORE_IMAGE_NAME):
190+
$(MAKE) list-image RELEASE_TAG=$(RELEASE_TAG) IMAGE=$(CORE_IMAGE_NAME)
191+
192+
list-image:
193+
gcloud container images list-tags $(STAGING_REGISTRY)/$(IMAGE) --filter="tags=('$(RELEASE_TAG)')" --format=json
194+
195+
.PHONY: check-release-tag
196+
check-release-tag:
197+
@if [ -z "${RELEASE_TAG}" ]; then echo "RELEASE_TAG is not set"; exit 1; fi
198+
@if ! [ -z "$$(git status --porcelain)" ]; then echo "Your local git repository contains uncommitted changes, use git clean before proceeding."; exit 1; fi
199+
200+
.PHONY: check-previous-release-tag
201+
check-previous-release-tag:
202+
@if [ -z "${PREVIOUS_VERSION}" ]; then echo "PREVIOUS_VERSION is not set"; exit 1; fi
203+
204+
.PHONY: check-github-token
205+
check-github-token:
206+
@if [ -z "${GITHUB_TOKEN}" ]; then echo "GITHUB_TOKEN is not set"; exit 1; fi
207+
208+
.PHONY: release
209+
release: clean-release check-release-tag $(RELEASE_DIR) ## Builds and push container images using the latest git tag for the commit.
210+
git checkout "${RELEASE_TAG}"
211+
CORE_CONTROLLER_IMG=$(PROD_REGISTRY)/$(CORE_IMAGE_NAME) $(MAKE) release-manifests
212+
$(MAKE) release-templates
213+
214+
.PHONY: release-manifests
215+
release-manifests:
216+
$(MAKE) $(RELEASE_DIR)/$(CORE_MANIFEST_FILE).yaml TAG=$(RELEASE_TAG)
217+
# Add metadata to the release artifacts
218+
cp metadata.yaml $(RELEASE_DIR)/metadata.yaml
171219

172220
.PHONY: release-staging
173-
release-staging: ## Builds and push container images to the staging image registry.
221+
release-staging: ## Builds and push container images and manifests to the staging bucket.
174222
$(MAKE) docker-build-all
175223
$(MAKE) docker-push-all
176224
$(MAKE) release-alias-tag
225+
$(MAKE) staging-manifests
226+
$(MAKE) release-templates
227+
$(MAKE) upload-staging-artifacts
228+
229+
.PHONY: staging-manifests
230+
staging-manifests:
231+
$(MAKE) $(RELEASE_DIR)/$(CORE_MANIFEST_FILE).yaml TAG=$(RELEASE_ALIAS_TAG)
232+
cp metadata.yaml $(RELEASE_DIR)/metadata.yaml
233+
234+
.PHONY: upload-staging-artifacts
235+
upload-staging-artifacts: ## Upload release artifacts to the staging bucket
236+
gsutil cp $(RELEASE_DIR)/* gs://$(BUCKET)/components/$(RELEASE_ALIAS_TAG)
237+
238+
.PHONY: release-alias-tag
239+
release-alias-tag: # Adds the tag to the last build tag.
240+
gcloud container images add-tag -q $(CORE_CONTROLLER_IMG):$(TAG) $(CORE_CONTROLLER_IMG):$(RELEASE_ALIAS_TAG)
241+
242+
.PHONY: release-templates
243+
release-templates: $(RELEASE_DIR) ## Generate release templates
244+
cp templates/cluster-template*.yaml $(RELEASE_DIR)/
245+
246+
IMAGE_PATCH_DIR := $(ARTIFACTS)/image-patch
247+
248+
$(IMAGE_PATCH_DIR): $(ARTIFACTS)
249+
mkdir -p $@
250+
251+
.PHONY: $(RELEASE_DIR)/$(CORE_MANIFEST_FILE).yaml
252+
$(RELEASE_DIR)/$(CORE_MANIFEST_FILE).yaml:
253+
$(MAKE) compiled-manifest \
254+
PROVIDER=$(CORE_MANIFEST_FILE) \
255+
OLD_IMG=$(CORE_CONTROLLER_ORIGINAL_IMG) \
256+
MANIFEST_IMG=$(CORE_CONTROLLER_IMG) \
257+
CONTROLLER_NAME=$(CORE_CONTROLLER_NAME) \
258+
PROVIDER_CONFIG_DIR=$(CORE_CONFIG_DIR) \
259+
NAMESPACE=$(CORE_NAMESPACE) \
260+
261+
.PHONY: compiled-manifest
262+
compiled-manifest: $(RELEASE_DIR) $(KUSTOMIZE)
263+
$(MAKE) image-patch-source-manifest
264+
$(MAKE) image-patch-kustomization
265+
$(KUSTOMIZE) build $(IMAGE_PATCH_DIR)/$(PROVIDER) > $(RELEASE_DIR)/$(PROVIDER).yaml
266+
267+
.PHONY: image-patch-source-manifest
268+
image-patch-source-manifest: $(IMAGE_PATCH_DIR) $(KUSTOMIZE)
269+
mkdir -p $(IMAGE_PATCH_DIR)/$(PROVIDER)
270+
$(KUSTOMIZE) build $(PROVIDER_CONFIG_DIR) > $(IMAGE_PATCH_DIR)/$(PROVIDER)/source-manifest.yaml
271+
272+
.PHONY: image-patch-kustomization
273+
image-patch-kustomization: $(IMAGE_PATCH_DIR)
274+
mkdir -p $(IMAGE_PATCH_DIR)/$(PROVIDER)
275+
$(MAKE) image-patch-kustomization-without-webhook
276+
277+
.PHONY: image-patch-kustomization-without-webhook
278+
image-patch-kustomization-without-webhook: $(IMAGE_PATCH_DIR) $(GOJQ)
279+
mkdir -p $(IMAGE_PATCH_DIR)/$(PROVIDER)
280+
$(GOJQ) --yaml-input --yaml-output '.images[0]={"name":"$(OLD_IMG)","newName":"$(MANIFEST_IMG)","newTag":"$(TAG)"}' \
281+
"hack/image-patch/kustomization.yaml" > $(IMAGE_PATCH_DIR)/$(PROVIDER)/kustomization.yaml
282+
283+
## --------------------------------------
284+
## Cleanup / Verification
285+
## --------------------------------------
286+
287+
.PHONY: clean
288+
clean: ## Remove all generated files
289+
$(MAKE) -C hack/tools clean
290+
$(MAKE) clean-temporary
291+
292+
.PHONY: clean-temporary
293+
clean-temporary: ## Remove all temporary files and folders
294+
rm -f minikube.kubeconfig
295+
rm -f kubeconfig
296+
rm -rf _artifacts
297+
298+
.PHONY: clean-release
299+
clean-release: ## Remove the release folder
300+
rm -rf $(RELEASE_DIR)
177301

178302
.PHONY: verify
179303
verify:

common.mk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
3+
TOOLS_DIR := $(ROOT_DIR_RELATIVE)/hack/tools
4+
TOOLS_DIR_DEPS := $(TOOLS_DIR)/go.sum $(TOOLS_DIR)/go.mod $(TOOLS_DIR)/Makefile
5+
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
6+
7+
$(TOOLS_BIN_DIR)/%: $(TOOLS_DIR_DEPS)
8+
make -C $(TOOLS_DIR) $(subst $(TOOLS_DIR)/,,$@)

hack/image-patch/kustomization.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
images:
3+
- name: ""
4+
newName: ""
5+
newTag: ""
6+
kind: Kustomization
7+
resources:
8+
- source-manifest.yaml

hack/tools/Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2021 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Directories.
16+
BIN_DIR := bin
17+
18+
$(BIN_DIR):
19+
mkdir -p $@
20+
21+
GOLANGCI_LINT := $(BIN_DIR)/golangci-lint
22+
$(GOLANGCI_LINT): $(BIN_DIR) go.mod go.sum # Build golangci-lint from tools folder.
23+
go build -tags=tools -o $@ github.com/golangci/golangci-lint/cmd/golangci-lint
24+
25+
KUSTOMIZE := $(BIN_DIR)/kustomize
26+
$(KUSTOMIZE): $(BIN_DIR) go.mod go.sum # Build kustomize from tools folder.
27+
CGO_ENABLED=0 go build -tags=tools -o $@ sigs.k8s.io/kustomize/kustomize/v3
28+
29+
GOJQ := $(BIN_DIR)/gojq
30+
$(GOJQ): $(BIN_DIR) go.mod go.sum
31+
go build -tags=tools -o $@ github.com/itchyny/gojq/cmd/gojq

hack/tools/go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ go 1.16
55
require (
66
github.com/blang/semver v3.5.1+incompatible
77
github.com/drone/envsubst/v2 v2.0.0-20210615175204-7bf45dbf5372
8-
github.com/hashicorp/go-multierror v1.0.0
8+
github.com/golangci/golangci-lint v1.41.1
9+
github.com/hashicorp/go-multierror v1.1.1
10+
github.com/itchyny/gojq v0.12.5
911
github.com/joelanford/go-apidiff v0.1.0
1012
github.com/onsi/ginkgo v1.16.4
1113
github.com/pkg/errors v0.9.1
@@ -18,4 +20,5 @@ require (
1820
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20210827150604-1730628f118b
1921
sigs.k8s.io/controller-tools v0.7.0
2022
sigs.k8s.io/kubebuilder/docs/book/utils v0.0.0-20210702145813-742983631190
23+
sigs.k8s.io/kustomize/kustomize/v3 v3.10.0
2124
)

0 commit comments

Comments
 (0)