Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏃Remove most uses of submakes in Makefile #1040

Closed
wants to merge 14 commits into from
Closed
94 changes: 39 additions & 55 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ BUCKET ?= $(STAGING_BUCKET)
PROD_REGISTRY ?= k8s.gcr.io/capi-openstack
REGISTRY ?= $(STAGING_REGISTRY)
RELEASE_TAG ?= $(shell git describe --abbrev=0 2>/dev/null)
PULL_BASE_REF ?= $(RELEASE_TAG) # PULL_BASE_REF will be provided by Prow
# PULL_BASE_REF will be provided by Prow
PULL_BASE_REF ?= $(RELEASE_TAG)
RELEASE_ALIAS_TAG ?= $(PULL_BASE_REF)
RELEASE_DIR := out

Expand Down Expand Up @@ -148,9 +149,10 @@ CONFORMANCE_GINKGO_ARGS ?= -stream
test-conformance: $(GINKGO) $(KIND) $(KUSTOMIZE) e2e-image ## Run clusterctl based conformance test on workload cluster (requires Docker).
time $(GINKGO) -trace -progress -v -tags=e2e -focus="conformance" $(CONFORMANCE_GINKGO_ARGS) ./test/e2e/suites/conformance/... -- -config-path="$(E2E_CONF_PATH)" -artifacts-folder="$(ARTIFACTS)" --data-folder="$(E2E_DATA_DIR)" $(CONFORMANCE_E2E_ARGS)


test-conformance-fast: ## Run clusterctl based conformance test on workload cluster (requires Docker) using a subset of the conformance suite in parallel.
$(MAKE) test-conformance CONFORMANCE_E2E_ARGS="-kubetest.config-file=$(KUBETEST_FAST_CONF_PATH) -kubetest.ginkgo-nodes=5 $(E2E_ARGS)"
## Run clusterctl based conformance test on workload cluster (requires Docker) using a subset of the conformance suite in parallel.
.PHONY: test-conformance-fast
test-conformance-fast: CONFORMANCE_E2E_ARGS="-kubetest.config-file=$(KUBETEST_FAST_CONF_PATH) -kubetest.ginkgo-nodes=5 $(E2E_ARGS)"
test-conformance-fast: test-conformance

## --------------------------------------
## Binaries
Expand All @@ -160,8 +162,7 @@ test-conformance-fast: ## Run clusterctl based conformance test on workload clus
binaries: managers ## Builds and installs all binaries

.PHONY: managers
managers:
$(MAKE) manager-openstack-infrastructure
managers: manager-openstack-infrastructure

.PHONY: manager-openstack-infrastructure
manager-openstack-infrastructure: ## Build manager binary.
Expand Down Expand Up @@ -192,14 +193,11 @@ modules: ## Runs go mod to ensure proper vendoring.
cd $(TOOLS_DIR); go mod tidy

.PHONY: generate
generate: ## Generate code
$(MAKE) generate-go
$(MAKE) generate-manifests
generate: generate-go generate-manifests

.PHONY: generate-go
generate-go: $(MOCKGEN)
generate-go: $(MOCKGEN) $(CONTROLLER_GEN) $(CONVERSION_GEN) $(DEFAULTER_GEN)
go generate ./...
$(MAKE) -B $(CONTROLLER_GEN) $(CONVERSION_GEN) $(DEFAULTER_GEN)
$(CONTROLLER_GEN) \
paths=./api/... \
object:headerFile=./hack/boilerplate/boilerplate.generatego.txt
Expand Down Expand Up @@ -251,8 +249,7 @@ docker-build-%:
$(MAKE) ARCH=$* docker-build

.PHONY: docker-push-all ## Push all the architecture docker images
docker-push-all: $(addprefix docker-push-,$(ALL_ARCH))
$(MAKE) docker-push-manifest
docker-push-all: $(addprefix docker-push-,$(ALL_ARCH)) docker-push-manifest

docker-push-%:
$(MAKE) ARCH=$* docker-push
Expand All @@ -265,8 +262,9 @@ docker-push-manifest: ## Push the fat manifest docker image.
docker manifest push --purge ${CONTROLLER_IMG}:${TAG}

.PHONY: staging-manifests
staging-manifests:
$(MAKE) $(RELEASE_DIR)/$(MANIFEST_FILE).yaml PULL_POLICY=IfNotPresent TAG=$(RELEASE_ALIAS_TAG)
staging-manifests: PULL_POLICY=IfNotPresent
staging-manifests: TAG=$(RELEASE_ALIAS_TAG)
staging-manifests: compiled-manifest

## --------------------------------------
## Release
Expand All @@ -283,54 +281,48 @@ list-staging-releases: ## List staging images for image promotion
list-image:
gcloud container images list-tags $(STAGING_REGISTRY)/$(IMAGE) --filter="tags=('$(RELEASE_TAG)')" --format=json

## Builds and push container images using the latest git tag for the commit.
.PHONY: release
release: $(RELEASE_NOTES) clean-release $(RELEASE_DIR) ## Builds and push container images using the latest git tag for the commit.
release: REGISTRY=$(PROD_REGISTRY)
release: TAG=$(RELEASE_TAG)
release: PULL_POLICY=IfNotPresent
release: $(RELEASE_NOTES) clean-release release-checkout-tag manifest-modification release-manifests release-templates | $(RELEASE_DIR)

release-checkout-tag:
@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."; fi
git checkout "${RELEASE_TAG}"
# Set the manifest image to the production bucket.
$(MAKE) manifest-modification REGISTRY=$(PROD_REGISTRY)
$(MAKE) release-manifests
$(MAKE) release-templates

## Set the manifest images to the staging/production bucket.
.PHONY: manifest-modification
manifest-modification: # Set the manifest images to the staging/production bucket.
$(MAKE) set-manifest-image \
MANIFEST_IMG=$(REGISTRY)/$(IMAGE_NAME) MANIFEST_TAG=$(RELEASE_TAG) \
TARGET_RESOURCE="./config/default/manager_image_patch.yaml"
$(MAKE) set-manifest-pull-policy PULL_POLICY=IfNotPresent TARGET_RESOURCE="./config/default/manager_pull_policy.yaml"
manifest-modification: set-manifest-image set-manifest-pull-policy

.PHONY: set-manifest-image
set-manifest-image:
$(info Updating kustomize image patch file for manager resource)
sed -i'' -e 's@image: .*@image: '"${MANIFEST_IMG}:$(MANIFEST_TAG)"'@' $(TARGET_RESOURCE)
sed -i'' -e 's@image: .*@image: '"$(REGISTRY)/$(IMAGE_NAME):$(RELEASE_TAG)"'@' ./config/default/manager_image_patch.yaml

.PHONY: set-manifest-pull-policy
set-manifest-pull-policy:
$(info Updating kustomize pull policy file for manager resources)
sed -i'' -e 's@imagePullPolicy: .*@imagePullPolicy: '"$(PULL_POLICY)"'@' $(TARGET_RESOURCE)
sed -i'' -e 's@imagePullPolicy: .*@imagePullPolicy: '"$(PULL_POLICY)"'@' ./config/default/manager_pull_policy.yaml

.PHONY: release-manifests
release-manifests:
$(MAKE) $(RELEASE_DIR)/$(MANIFEST_FILE).yaml TAG=$(RELEASE_TAG) PULL_POLICY=IfNotPresent
release-manifests: TAG=$(RELEASE_TAG)
release-manifests: PULL_POLICY=IfNotPresent
release-manifests: compiled-manifest
# Add metadata to the release artifacts
cp metadata.yaml $(RELEASE_DIR)/metadata.yaml

## Builds and push container images and manifests to the staging bucket.
.PHONY: release-staging
release-staging: ## Builds and push container images and manifests to the staging bucket.
$(MAKE) docker-build-all
$(MAKE) docker-push-all
$(MAKE) release-alias-tag
$(MAKE) staging-manifests
$(MAKE) upload-staging-artifacts
release-staging: docker-build-all docker-push-all release-alias-tag staging-manifests upload-staging-artifacts

## Tags and push container images to the staging bucket. Example image tag: capi-openstack-controller:nightly_master_20210121
.PHONY: release-staging-nightly
release-staging-nightly: ## Tags and push container images to the staging bucket. Example image tag: capi-openstack-controller:nightly_master_20210121
$(eval NEW_RELEASE_ALIAS_TAG := nightly_$(RELEASE_ALIAS_TAG)_$(shell date +'%Y%m%d'))
echo $(NEW_RELEASE_ALIAS_TAG)
$(MAKE) release-alias-tag TAG=$(RELEASE_ALIAS_TAG) RELEASE_ALIAS_TAG=$(NEW_RELEASE_ALIAS_TAG)
$(MAKE) staging-manifests RELEASE_ALIAS_TAG=$(NEW_RELEASE_ALIAS_TAG)
$(MAKE) upload-staging-artifacts RELEASE_ALIAS_TAG=$(NEW_RELEASE_ALIAS_TAG)
release-staging-nightly: RELEASE_ALIAS_TAG := nightly_$(RELEASE_ALIAS_TAG)_$(shell date +'%Y%m%d')
release-staging-nightly: TAG=$(RELEASE_ALIAS_TAG)
release-staging-nightly: release-alias-tag staging-manifests upload-staging-artifacts

.PHONY: upload-staging-artifacts
upload-staging-artifacts: ## Upload release artifacts to the staging bucket
Expand Down Expand Up @@ -361,21 +353,13 @@ IMAGE_PATCH_DIR := $(ARTIFACTS)/image-patch
$(IMAGE_PATCH_DIR): $(ARTIFACTS)
mkdir -p $@

.PHONY: $(RELEASE_DIR)/$(MANIFEST_FILE).yaml
$(RELEASE_DIR)/$(MANIFEST_FILE).yaml:
$(MAKE) compiled-manifest \
PROVIDER=$(MANIFEST_FILE) \
OLD_IMG=$(CONTROLLER_ORIGINAL_IMG) \
MANIFEST_IMG=$(CONTROLLER_IMG) \
CONTROLLER_NAME=$(CONTROLLER_NAME) \
PROVIDER_CONFIG_DIR=$(CONFIG_DIR) \
NAMESPACE=$(NAMESPACE)

$(RELEASE_DIR)/$(MANIFEST_FILE).yaml: compiled-manifest
.PHONY: compiled-manifest
compiled-manifest: $(RELEASE_DIR) $(KUSTOMIZE)
$(MAKE) image-patch-source-manifest
$(MAKE) image-patch-pull-policy
$(MAKE) image-patch-kustomization
compiled-manifest: PROVIDER=$(MANIFEST_FILE)
compiled-manifest: OLD_IMG=$(CONTROLLER_ORIGINAL_IMG)
compiled-manifest: MANIFEST_IMG=$(CONTROLLER_IMG)
compiled-manifest: PROVIDER_CONFIG_DIR=$(CONFIG_DIR)
compiled-manifest: $(KUSTOMIZE) image-patch-source-manifest image-patch-pull-policy image-patch-kustomization | $(RELEASE_DIR)
$(KUSTOMIZE) build $(IMAGE_PATCH_DIR)/$(PROVIDER) > $(RELEASE_DIR)/$(PROVIDER).yaml

.PHONY: image-patch-source-manifest
Expand Down