Skip to content

Commit

Permalink
[release-0.20] breaks kind batch build up even more (#4134)
Browse files Browse the repository at this point in the history
Cherry-picked from #4133
  • Loading branch information
2ez4szliu authored Dec 15, 2024
1 parent ca3c762 commit 0a4a119
Show file tree
Hide file tree
Showing 11 changed files with 557 additions and 60 deletions.
4 changes: 3 additions & 1 deletion Common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ SUPPORTED_K8S_VERSIONS=$(shell cat $(BASE_DIRECTORY)/release/SUPPORTED_RELEASE_B
SKIPPED_K8S_VERSIONS?=
BINARIES_ARE_RELEASE_BRANCHED?=true
IS_RELEASE_BRANCH_BUILD=$(filter true,$(HAS_RELEASE_BRANCHES))
UNRELEASE_BRANCH_BINARY_TARGETS=patch-repo binaries attribution checksums
UNRELEASE_BRANCH_BINARY_TARGETS=patch-repo binaries attribution checksums validate-checksums
IS_UNRELEASE_BRANCH_TARGET=$(and $(filter false,$(BINARIES_ARE_RELEASE_BRANCHED)),$(filter $(UNRELEASE_BRANCH_BINARY_TARGETS) $(foreach target,$(UNRELEASE_BRANCH_BINARY_TARGETS),run-$(target)-in-docker run-in-docker/$(target)),$(MAKECMDGOALS)))
TARGETS_ALLOWED_WITH_NO_RELEASE_BRANCH?=
TARGETS_ALLOWED_WITH_NO_RELEASE_BRANCH+=build release clean clean-extra clean-go-cache help start-docker-builder stop-docker-builder create-ecr-repos all-attributions all-checksums all-attributions-checksums update-patch-numbers check-for-release-branch-skip run-buildkit-and-registry $(if $(filter false, $(HAS_LICENSES)),attribution,) $(if $(filter true, $(HAS_HELM_CHART)),,helm/push)
Expand Down Expand Up @@ -845,6 +845,8 @@ clean-job-caches: $(and $(findstring presubmit,$(JOB_TYPE)),$(filter true,$(PRUN
PHONY: combine-images
combine-images: IMAGE_BUILD_ARGS=IMAGE
combine-images: DOCKERFILE_FOLDER=$(BUILD_LIB)/docker/linux/combine
combine-images: IMAGE_TARGET=
combine-images: IMAGE_CONTEXT_DIR=.
combine-images: images

## Helm Targets
Expand Down
16 changes: 14 additions & 2 deletions build/lib/generate_staging_buildspec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ for project in "${PROJECTS[@]}"; do
PROJECT_DEPENDENCIES=$(make_var $PROJECT_PATH PROJECT_DEPENDENCIES)
fi

if [ -n "$PROJECT_DEPENDENCIES" ] && [[ "${buildspec}" = "buildspecs/combine-images.yml" || "$SKIP_DEPEND_ON" != "true" ]]; then
if [ -n "$PROJECT_DEPENDENCIES" ] && [[ "${buildspec}" = "buildspecs/combine-images.yml" || "$SKIP_DEPEND_ON" != "true" || "${buildspec}" = "projects/kubernetes-sigs/kind/buildspecs/node-images.yml" ]]; then
DEPS=(${PROJECT_DEPENDENCIES// / })
for dep in "${DEPS[@]}"; do
if [ "$HARDCODED_DEP" = "true" ]; then
Expand Down Expand Up @@ -221,12 +221,24 @@ for project in "${PROJECTS[@]}"; do
for val1 in "${ARR_1[@]}"; do
for val2 in "${ARR_2[@]}"; do
BUILDSPEC_NAME=$(basename $buildspec .yml)
IDENTIFIER=${org//-/_}_${repo//-/_}_${val1//-/_}_${val2//-/_}_${BUILDSPEC_NAME//-/_}
IDENTIFIER=${org//-/_}_${repo//-/_}_${val1//[-\/]/_}_${val2//[-\/]/_}_${BUILDSPEC_NAME//-/_}
# TODO: revisit this to make it more dynamic if other projects need it in the future
EXTRA_VARS=""
if [[ "$IDENTIFIER" =~ "kubernetes_sigs_image_builder_bottlerocket" ]]; then
EXTRA_VARS+=",\"IMAGE_OS_VERSION\":\"1\""
fi
if [ "${KEYS[1]}" = "IMAGE_PLATFORMS" ]; then
EXTRA_VARS+=",\"BINARY_PLATFORMS\":\"${val2}\",\"IMAGE_TAG_SUFFIX\":\"-${val2#linux/}\""
fi
# If building on one binary platform assume we want to run on a specific arch instance
ARCH_TYPE="\"type\":\"$BUILDSPEC_PLATFORM\",\"compute-type\":\"$BUILDSPEC_COMPUTE_TYPE\","
if [ "${KEYS[1]}" = "BINARY_PLATFORMS" ] || [ "${KEYS[1]}" = "IMAGE_PLATFORMS" ]; then
if [ "${val2}" = "linux/amd64" ]; then
ARCH_TYPE="\"type\":\"LINUX_CONTAINER\",\"compute-type\":\"$BUILDSPEC_COMPUTE_TYPE\","
else
ARCH_TYPE="\"type\":\"ARM_CONTAINER\",\"compute-type\":\"$BUILDSPEC_COMPUTE_TYPE\","
fi
fi
ALL_PROJECT_IDS+="\"$IDENTIFIER\","
yq eval -i -P \
".batch.build-graph += [{\"identifier\":\"$IDENTIFIER\",$buildspec_field$DEPEND_ON\"env\":{$ARCH_TYPE\"variables\":{\"PROJECT_PATH\": \"projects/$org/$repo\"$CLONE_URL,\"${KEYS[0]}\":\"$val1\",\"${KEYS[1]}\":\"$val2\"$EXTRA_VARS}}}]" \
Expand Down
71 changes: 46 additions & 25 deletions projects/kubernetes-sigs/kind/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ EKSD_KUBE_VERSION=
# Overriding since kind is released branch it will try to add git_tag to latest tag
LATEST_TAG=$(LATEST)

UNVERSIONED_BASE_IMAGE=$(IMAGE_REPO)/$(KIND_BASE_IMAGE_COMPONENT):$(GIT_TAG)-$(GIT_HASH)
VERSIONED_BASE_IMAGE=$(IMAGE_REPO)/$(KIND_BASE_IMAGE_COMPONENT):$(EKSD_KUBE_VERSION)-$(GIT_TAG)-$(GIT_HASH)
UNVERSIONED_BASE_IMAGE=$(IMAGE_REPO)/$(KIND_BASE_IMAGE_COMPONENT):$(GIT_TAG)-$(GIT_HASH)$(IMAGE_TAG_SUFFIX)
VERSIONED_BASE_IMAGE=$(IMAGE_REPO)/$(KIND_BASE_IMAGE_COMPONENT):$(EKSD_KUBE_VERSION)-$(GIT_TAG)-$(GIT_HASH)$(IMAGE_TAG_SUFFIX)

HAS_S3_ARTIFACTS?=true
HAS_RELEASE_BRANCHES=true
Expand All @@ -52,18 +52,50 @@ IMAGE_NAMES?=haproxy kindnetd kind-base

FIX_LICENSES_KINDNETD_TARGET=$(REPO)/images/kindnetd/LICENSE

BUILDSPECS=buildspecs/binaries.yml buildspecs/images.yml
# we need to set IMAGE_BUILD_ARGS here even though its the same as the default.
# it is set in Common.mk on the images target (https://github.com/aws/eks-anywhere-build-tooling/blob/8b6d6d66974e881b22e3c9c8ea29adc26f7df5fd/Common.mk#L799)
# and the combine-images target (https://github.com/aws/eks-anywhere-build-tooling/blob/8b6d6d66974e881b22e3c9c8ea29adc26f7df5fd/Common.mk#L846)
# since combine-images has images as prereq target, the ?= does not really behavior as one might expect.
# the images target being the actual action, its version of the set takes prioirty and resets to empty
# setting it explicitly to empty here takes allows the combine-images override to take proirty
IMAGE_BUILD_ARGS=

# We are using this pattern of setting the dockerfile_folder instead of local to the target
# because this project uses the combine-images target which overrides the dockerfile_folder
# to the standard combine-images dockerfile
# If we setup our override in this Makefile at the target it does not allow the combine-images
# to override it
DOCKERFILE_FOLDER=$(strip $(if $(findstring kind-base,$(IMAGE_NAME)),$(REPO)/images/base,$(if $(filter kind-node,$(IMAGE_NAME)),./images/node,./images/$(IMAGE_NAME))))

# setting image_tarrget similiar to how we set dockerfile_folder as to be able to override it in combine-images
KIND_BASE_IMAGE_TARGET=base
KIND_BASE_VERSIONED_IMAGE_TARGET=base-versioned
KIND_NODE_IMAGE_TARGET=node
IMAGE_TARGET=$(call IF_OVERRIDE_VARIABLE,$(call TO_UPPER,$(IMAGE_NAME))_IMAGE_TARGET,)

KIND_BASE_IMAGE_CONTEXT_DIR=$(REPO)/images/base
KIND_BASE_VERSIONED_IMAGE_CONTEXT_DIR=$(OUTPUT_DIR)/$(RELEASE_BRANCH)/images/base
KIND_NODE_IMAGE_CONTEXT_DIR=$(BINARY_DEPS_DIR)
KIND_IF_OVERRIDE_VARIABLE=$(if $(filter undefined,$(origin $1)),$(2),$($(1)))
IMAGE_CONTEXT_DIR=$(call KIND_IF_OVERRIDE_VARIABLE,$(call TO_UPPER,$(IMAGE_NAME))_IMAGE_CONTEXT_DIR,.)

BUILDSPECS=projects/kubernetes-sigs/kind/buildspecs/binaries.yml projects/kubernetes-sigs/kind/buildspecs/base-images.yml projects/kubernetes-sigs/kind/buildspecs/node-images.yml buildspecs/combine-images.yml
BUILDSPEC_1_PLATFORM=ARM_CONTAINER
BUILDSPEC_1_DEPENDS_ON_OVERRIDE=none
BUILDSPEC_2_PLATFORM=LINUX_CONTAINER
BUILDSPEC_2_COMPUTE_TYPE=BUILD_GENERAL1_LARGE
BUILDSPEC_2_VARS_KEYS=RELEASE_BRANCH
BUILDSPEC_2_VARS_VALUES=SUPPORTED_K8S_VERSIONS

BUILDSPEC_2_VARS_KEYS=IMAGE_PLATFORMS
BUILDSPEC_2_VARS_VALUES=IMAGE_PLATFORMS
BUILDSPEC_3_VARS_KEYS=RELEASE_BRANCH IMAGE_PLATFORMS
BUILDSPEC_3_VARS_VALUES=SUPPORTED_K8S_VERSIONS IMAGE_PLATFORMS
BUILDSPEC_3_DEPENDS_ON_OVERRIDE=kubernetes_sigs_kind_linux_amd64 kubernetes_sigs_kind_linux_arm64
BUILDSPEC_4_VARS_KEYS=RELEASE_BRANCH
BUILDSPEC_4_VARS_VALUES=SUPPORTED_K8S_VERSIONS
BUILDSPEC_4_DEPENDS_ON_OVERRIDE=$(foreach version,$(SUPPORTED_K8S_VERSIONS),$(foreach arch,arm64 amd64,kubernetes_sigs_kind_$(subst -,_,$(version))_linux_$(arch)_node_images))
BUILDSPEC_COMPUTE_TYPE=BUILD_GENERAL1_LARGE


include $(BASE_DIRECTORY)/Common.mk


# Do not need to import if running clean or any var-value-% targets
ifneq ($(and $(RELEASE_BRANCH),$(filter-out clean help-list add-generated-help-block,$(MAKECMDGOALS_WITHOUT_VAR_VALUE))),)
-include $(KIND_BASE_IMAGE_BUILD_ARGS)
Expand All @@ -82,7 +114,6 @@ create-ecr-repos: kind-node/create-ecr-repo
$(OUTPUT_BIN_DIR)/%/kind: EXTRA_GO_LDFLAGS=-X=sigs.k8s.io/kind/pkg/cmd/kind/version.gitCommit=$(shell git -C $(REPO) rev-list -n 1 "${GIT_TAG}")

# haproxy
haproxy/images/%: DOCKERFILE_FOLDER=./images/haproxy
haproxy/images/%: BASE_IMAGE_NAME=$(MINIMAL_BASE_HAPROXY_IMAGE_NAME)
$(call IMAGE_TARGETS_FOR_NAME, haproxy): $(HAPROXY_CFG)

Expand All @@ -91,44 +122,32 @@ $(HAPROXY_CFG): $(GIT_PATCH_TARGET)
cp $(REPO)/images/haproxy/haproxy.cfg $@

# Kindnetd
kindnetd/images/%: DOCKERFILE_FOLDER=./images/kindnetd
kindnetd/images/%: BASE_IMAGE_NAME=$(MINIMAL_BASE_IPTABLES_IMAGE_NAME)

# Kind-base
kind-base/images/% kind-base-versioned/images/%: DOCKERFILE_FOLDER=$(REPO)/images/base
kind-base/images/% kind-base-versioned/images/%: BASE_IMAGE_NAME=$(MINIMAL_BASE_KIND_IMAGE_NAME)
kind-base/images/% kind-base-versioned/images/%: BASE_IMAGE_OS_VERSION=$(MINIMAL_BASE_KIND_IMAGE_NAME_OS_VERSION)
kind-base/images/% kind-base-versioned/images/%: IMAGE_BUILD_ARGS=CNI_PLUGINS_AMD64_URL CNI_PLUGINS_ARM64_URL CNI_PLUGINS_AMD64_SHA256SUM \
CNI_PLUGINS_ARM64_SHA256SUM
kind-base-versioned/images/%: IMAGE_BUILD_ARGS+=CNI_PLUGINS_AMD64_URL CNI_PLUGINS_ARM64_URL CNI_PLUGINS_AMD64_SHA256SUM CNI_PLUGINS_ARM64_SHA256SUM

kind-base/images/%: IMAGE_TARGET=base
kind-base/images/%: IMAGE_CONTEXT_DIR=$(REPO)/images/base
$(call IMAGE_TARGETS_FOR_NAME, kind-base): $(KIND_BASE_IMAGE_BUILD_ARGS)

kind-base-versioned/images/%: IMAGE_TARGET=base-versioned
kind-base-versioned/images/%: IMAGE_TAG:=$(EKSD_KUBE_VERSION)-$(IMAGE_TAG)
kind-base-versioned/images/%: LATEST_TAG:=$(EKSD_KUBE_VERSION)-$(LATEST_TAG)
kind-base-versioned/images/%: IMAGE_CONTEXT_DIR=$(OUTPUT_DIR)/$(RELEASE_BRANCH)/images/base
kind-base-versioned/images/%: BUILDER_IMAGE=$(UNVERSIONED_BASE_IMAGE)
$(call IMAGE_TARGETS_FOR_NAME, kind-base-versioned): $(KIND_BASE_KUBEADM_OVERRIDE)
$(call IMAGE_TARGETS_FOR_NAME, kind-base-versioned): $(KIND_BASE_IMAGE_BUILD_ARGS) $(KIND_BASE_KUBEADM_OVERRIDE)

# Kind-node
kind-node/images/push: DOCKERFILE_FOLDER=./images/node
kind-node/images/push: IMAGE_CONTEXT_DIR=$(BINARY_DEPS_DIR)
kind-node/images/push: BASE_IMAGE=$(VERSIONED_BASE_IMAGE)
# We are fully overriding the base_image above, setting the name is to ensure the builder image is set correctly
kind-node/images/push: BASE_IMAGE_NAME=$(MINIMAL_BASE_KIND_IMAGE_NAME)
kind-node/images/push: BASE_IMAGE_OS_VERSION=$(MINIMAL_BASE_KIND_IMAGE_NAME_OS_VERSION)
kind-node/images/push: IMAGE_TAG=$(NODE_IMAGE_TAG)
kind-node/images/push: LATEST_TAG=$(NODE_IMAGE_LATEST_TAG)
kind-node/images/push: IMAGE_TARGET=node
kind-node/images/push: $(KIND_NODE_BUILD_AMD64_TARGET) $(KIND_NODE_BUILD_ARM64_TARGET) $(ARM_ENV_CONF_TARGET)
kind-node/images/push: $(if $(filter linux/amd64,$(IMAGE_PLATFORMS)),$(KIND_NODE_BUILD_AMD64_TARGET),) $(if $(filter linux/arm64,$(IMAGE_PLATFORMS)),$(KIND_NODE_BUILD_ARM64_TARGET) $(ARM_ENV_CONF_TARGET),)

$(KIND_BASE_IMAGE_BUILD_ARGS): | ensure-yq $$(ENABLE_LOGGING)
@build/base-image-build-args.sh $(RELEASE_BRANCH) $(ARTIFACTS_BUCKET) $@ $(LATEST)

$(KIND_NODE_IMAGE_BUILD_ARGS): | ensure-yq $$(ENABLE_LOGGING)
@build/node-image-build-args.sh $(RELEASE_BRANCH) $(KINDNETD_IMAGE_COMPONENT) $(IMAGE_REPO) "$(ARTIFACTS_BUCKET)" $(IMAGE_TAG) $(LATEST) $@
@build/node-image-build-args.sh $(RELEASE_BRANCH) $(KINDNETD_IMAGE_COMPONENT) $(IMAGE_REPO) "$(ARTIFACTS_BUCKET)" $(IMAGE_TAG) $(LATEST) $@ $(IMAGE_TAG_SUFFIX)

# Tweak the kind/base image to have a hardcode kubeadm config
# so that during the image pull phase it pulls eks-d images
Expand All @@ -151,7 +170,9 @@ $(KIND_NODE_BUILD_AMD64_TARGET): $(KIND_NODE_IMAGE_BUILD_ARGS) $(ORGANIZE_BINARI
$(MAKE) $(KIND_CLI) BINARY_PLATFORMS=$(BUILDER_PLATFORM)
build/build-kind-node-image.sh $(RELEASE_BRANCH) $(VERSIONED_BASE_IMAGE) amd64 $(BUILDER_PLATFORM_ARCH)

$(KIND_NODE_BUILD_ARM64_TARGET): KIND_CLI=./$(OUTPUT_BIN_DIR)/$(subst /,-,$(BUILDER_PLATFORM))/kind
$(KIND_NODE_BUILD_ARM64_TARGET): $(KIND_NODE_IMAGE_BUILD_ARGS) $(ORGANIZE_BINARIES_ARM64_TARGET) | ensure-jq
$(MAKE) $(KIND_CLI) BINARY_PLATFORMS=$(BUILDER_PLATFORM)
build/build-kind-node-image.sh $(RELEASE_BRANCH) $(VERSIONED_BASE_IMAGE) arm64 $(BUILDER_PLATFORM_ARCH)

$(ORGANIZE_BINARIES_AMD64_TARGET): $(HANDLE_DEPENDENCIES_TARGET)
Expand Down
3 changes: 2 additions & 1 deletion projects/kubernetes-sigs/kind/build/node-image-build-args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ARTIFACTS_BUCKET="$4"
IMAGE_TAG="$5"
LATEST="$6"
OUTPUT_FILE="$7"
IMAGE_TAG_SUFFIX="$8"

MAKE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
BUILD_LIB="${MAKE_ROOT}/../../../build/lib"
Expand All @@ -33,7 +34,7 @@ AL2_HELPER_IMAGE="public.ecr.aws/amazonlinux/amazonlinux:2"
LOCAL_PATH_PROVISONER_IMAGE_TAG_OVERRIDE="$IMAGE_REPO/rancher/local-path-provisioner:$LATEST"
LOCAL_PATH_PROVISONER_RELEASE_OVERRIDE="public.ecr.aws/eks-anywhere/rancher/local-path-provisioner:$(cat $MAKE_ROOT/../../rancher/local-path-provisioner/GIT_TAG)"
KIND_KINDNETD_RELEASE_OVERRIDE="public.ecr.aws/eks-anywhere/kubernetes-sigs/kind/kindnetd:$(cat $MAKE_ROOT/GIT_TAG)"
KIND_KINDNETD_IMAGE_OVERRIDE="$IMAGE_REPO/$KINDNETD_IMAGE_COMPONENT:$LATEST"
KIND_KINDNETD_IMAGE_OVERRIDE="$IMAGE_REPO/$KINDNETD_IMAGE_COMPONENT:$LATEST$IMAGE_TAG_SUFFIX"

# Preload release yaml
build::eksd_releases::load_release_yaml $EKSD_RELEASE_BRANCH
Expand Down
14 changes: 14 additions & 0 deletions projects/kubernetes-sigs/kind/buildspecs/base-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 0.2

env:
variables:
HAS_S3_ARTIFACTS: ""

phases:
pre_build:
commands:
- ./build/lib/setup.sh

build:
commands:
- if $(make check-project-path-exists); then make binaries haproxy/images/push kindnetd/images/push kind-base/images/push -C $PROJECT_PATH; fi
Loading

0 comments on commit 0a4a119

Please sign in to comment.