From 511c6d444870348c3b4ee5c693cfac521919c0d0 Mon Sep 17 00:00:00 2001 From: Jason DeTiberus Date: Tue, 30 Oct 2018 16:56:13 -0400 Subject: [PATCH] Improve release tooling (#340) - Update release image to use a version tag rather than latest - Add a target for generating the release binaries --- .gitignore | 4 +-- BUILD.bazel | 11 ------- Makefile | 15 +++++++-- ...inary.bzl => cluster_api_binary_image.bzl} | 33 ++----------------- cmd/clusterawsadm/BUILD | 4 +-- cmd/clusterctl/BUILD | 4 +-- cmd/manager/BUILD | 5 +-- docs/development.md | 8 ++--- 8 files changed, 26 insertions(+), 58 deletions(-) rename build/{cluster_api_binary.bzl => cluster_api_binary_image.bzl} (65%) diff --git a/.gitignore b/.gitignore index e784f0a95d..532446fd6a 100644 --- a/.gitignore +++ b/.gitignore @@ -26,7 +26,7 @@ envfile minikube.kubeconfig kubeconfig -# Example output directory +# Example and binary output directory /out # bazel @@ -34,4 +34,4 @@ kubeconfig /bazel-cluster-api-provider-aws /bazel-genfiles /bazel-out -/bazel-testlogs +/bazel-testlogs \ No newline at end of file diff --git a/BUILD.bazel b/BUILD.bazel index 0aaf42bdb0..4397318a6b 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -44,21 +44,10 @@ gazelle( filegroup( name = "all-images", srcs = [ - "//cmd/clusterawsadm:clusterawsadm-image", - "//cmd/clusterctl:clusterctl-image", "//cmd/manager:manager-image", ], ) -filegroup( - name = "all-images-dev", - srcs = [ - "//cmd/clusterawsadm:clusterawsadm-image-dev", - "//cmd/clusterctl:clusterctl-image-dev", - "//cmd/manager:manager-image-dev", - ], -) - workspace_binary( name = "dep", cmd = "@com_github_golang_dep//cmd/dep", diff --git a/Makefile b/Makefile index d04310c766..bf016f1da8 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ FASTBUILD ?= n ## Set FASTBUILD=y (case-sensitive) to skip some slow tasks ## Image URL to use all building/pushing image targets STABLE_DOCKER_REPO ?= gcr.io/cluster-api-provider-aws MANAGER_IMAGE_NAME ?= cluster-api-aws-controller -MANAGER_IMAGE_TAG ?= latest +MANAGER_IMAGE_TAG ?= 0.0.2 MANAGER_IMAGE ?= $(STABLE_DOCKER_REPO)/$(MANAGER_IMAGE_NAME):$(MANAGER_IMAGE_TAG) DEV_DOCKER_REPO ?= gcr.io/$(shell gcloud config get-value project) DEV_MANAGER_IMAGE ?= $(DEV_DOCKER_REPO)/$(MANAGER_IMAGE_NAME):$(MANAGER_IMAGE_TAG) @@ -81,6 +81,15 @@ clusterawsadm: dep-ensure ## Build clusterawsadm binary. cluster-api-dev-helper: dep-ensure ## Build cluster-api-dev-helper binary bazel build //hack/cluster-api-dev-helper $(BAZEL_ARGS) +.PHONY: release-binaries +release-binaries: ## Build release binaries + bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //cmd/clusterctl //cmd/clusterawsadm + bazel build --platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64 //cmd/clusterctl //cmd/clusterawsadm + install bazel-bin/cmd/clusterawsadm/darwin_amd64_pure_stripped/clusterawsadm out/clusterawsadm-darwin-amd64 + install bazel-bin/cmd/clusterawsadm/linux_amd64_pure_stripped/clusterawsadm out/clusterawsadm-linux-amd64 + install bazel-bin/cmd/clusterctl/darwin_amd64_pure_stripped/clusterctl out/clusterctl-darwin-amd64 + install bazel-bin/cmd/clusterctl/linux_amd64_pure_stripped/clusterctl out/clusterctl-linux-amd64 + .PHONY: test test: generate ## Run tests bazel test --nosandbox_debug //pkg/... //cmd/... $(BAZEL_ARGS) @@ -95,11 +104,11 @@ docker-build: generate ## Build the docker image .PHONY: docker-push docker-push: generate ## Push production docker image - bazel run //cmd/manager:manager-push --define=STABLE_DOCKER_REPO=$(STABLE_DOCKER_REPO) --define=MANAGER_IMAGE_NAME=$(MANAGER_IMAGE_NAME) $(BAZEL_ARGS) + bazel run //cmd/manager:manager-push --define=DOCKER_REPO=$(STABLE_DOCKER_REPO) --define=MANAGER_IMAGE_NAME=$(MANAGER_IMAGE_NAME) --define=MANAGER_IMAGE_TAG=$(MANAGER_IMAGE_TAG) $(BAZEL_ARGS) .PHONY: docker-push-dev docker-push-dev: generate ## Push development image - bazel run //cmd/manager:manager-push-dev --define=DEV_DOCKER_REPO=$(DEV_DOCKER_REPO) --define=MANAGER_IMAGE_NAME=$(MANAGER_IMAGE_NAME) $(BAZEL_ARGS) + bazel run //cmd/manager:manager-push --define=DOCKER_REPO=$(DEV_DOCKER_REPO) --define=MANAGER_IMAGE_NAME=$(MANAGER_IMAGE_NAME) --define=MANAGER_IMAGE_TAG=$(MANAGER_IMAGE_TAG) $(BAZEL_ARGS) .PHONY: clean clean: ## Remove all generated files diff --git a/build/cluster_api_binary.bzl b/build/cluster_api_binary_image.bzl similarity index 65% rename from build/cluster_api_binary.bzl rename to build/cluster_api_binary_image.bzl index f99376321f..cfcce4e405 100644 --- a/build/cluster_api_binary.bzl +++ b/build/cluster_api_binary_image.bzl @@ -23,53 +23,26 @@ load("@io_bazel_rules_docker//container:push.bzl", "container_push") load("@io_bazel_rules_docker//contrib:push-all.bzl", "docker_push") load("@io_bazel_rules_docker//container:container.bzl", "container_bundle") -def cluster_api_binary(name): +def cluster_api_binary_image(name): go_image( name = name + "-amd64", base = "@golang-image//image", embed = [":go_default_library"], goarch = "amd64", goos = "linux", - # goos = select( - # "@io_bazel_rules_go//go/platform:linux": "linux", - # "//conditions:default": fail("only building on Linux supported. Try again with --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 ") - # ) pure = "on", ) tags = [ - "{GIT_COMMIT}", "{GIT_VERSION}", - "{BUILD_TIMESTAMP}", - "latest", + "$(MANAGER_IMAGE_TAG)", ] container_bundle( name = name + "-image", images = { "{registry}/{name}:{tag}".format( - registry = "$(STABLE_DOCKER_REPO)", - name = "$(MANAGER_IMAGE_NAME)", - tag = tag, - ): ":{name}-amd64".format(name = name) - for tag in tags - }, - stamp = True, - tags = ["manual"], - visibility = ["//visibility:public"], - ) - - docker_push( - name = name + "-push-dev", - bundle = ":{name}-image-dev".format(name = name), - tags = ["manual"], - ) - - container_bundle( - name = name + "-image-dev", - images = { - "{registry}/{name}:{tag}".format( - registry = "$(DEV_DOCKER_REPO)", + registry = "$(DOCKER_REPO)", name = "$(MANAGER_IMAGE_NAME)", tag = tag, ): ":{name}-amd64".format(name = name) diff --git a/cmd/clusterawsadm/BUILD b/cmd/clusterawsadm/BUILD index 95b2d4b557..5bb45048e1 100644 --- a/cmd/clusterawsadm/BUILD +++ b/cmd/clusterawsadm/BUILD @@ -1,5 +1,4 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") -load("//build:cluster_api_binary.bzl", "cluster_api_binary") go_library( name = "go_default_library", @@ -13,6 +12,5 @@ go_binary( name = "clusterawsadm", embed = [":go_default_library"], visibility = ["//visibility:public"], + pure = "on", ) - -cluster_api_binary(name = "clusterawsadm") diff --git a/cmd/clusterctl/BUILD b/cmd/clusterctl/BUILD index fdfdc514bb..91da763443 100644 --- a/cmd/clusterctl/BUILD +++ b/cmd/clusterctl/BUILD @@ -1,5 +1,4 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") -load("//build:cluster_api_binary.bzl", "cluster_api_binary") go_library( name = "go_default_library", @@ -17,6 +16,5 @@ go_binary( name = "clusterctl", embed = [":go_default_library"], visibility = ["//visibility:public"], + pure = "on", ) - -cluster_api_binary(name = "clusterctl") diff --git a/cmd/manager/BUILD b/cmd/manager/BUILD index cefed7534f..edfde2c1cd 100644 --- a/cmd/manager/BUILD +++ b/cmd/manager/BUILD @@ -1,5 +1,5 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") -load("//build:cluster_api_binary.bzl", "cluster_api_binary") +load("//build:cluster_api_binary_image.bzl", "cluster_api_binary_image") go_library( name = "go_default_library", @@ -27,6 +27,7 @@ go_binary( name = "manager", embed = [":go_default_library"], visibility = ["//visibility:public"], + pure = "on", ) -cluster_api_binary(name = "manager") +cluster_api_binary_image(name = "manager") diff --git a/docs/development.md b/docs/development.md index 01898a30c0..94914621a4 100644 --- a/docs/development.md +++ b/docs/development.md @@ -8,9 +8,9 @@ - [Committing code](#committing-code) - [Mocks](#mocks) - [Set up](#set-up) - - [Base requirements](#base-requirements) - - [Using Google Cloud](#using-google-cloud) - - [Using images on Google Cloud](#using-images-on-google-cloud) + - [Base requirements](#base-requirements) + - [Using Google Cloud](#using-google-cloud) + - [Using images on Google Cloud](#using-images-on-google-cloud) - [cluster-api-dev-helper](#cluster-api-dev-helper) @@ -58,7 +58,7 @@ Google Container Registry. 1. [Install the gcloud cli][gcloud_sdk]. 1. Set project: `gcloud config set project YOUR_PROJECT_NAME`. -1. Pushing dev images: `make dev_push`. +1. Pushing dev images: `make docker-push-dev`. #### Using images on Google Cloud