Skip to content

Commit

Permalink
improves hook build
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxesn committed Nov 7, 2024
1 parent 7b5b5b1 commit de0a3aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ stop-docker-builder:

.PHONY: run-buildkit-and-registry
run-buildkit-and-registry:
docker run --rm -d --name buildkitd --net host --privileged moby/buildkit:v0.12.2-rootless
docker buildx create --name multiarch --driver docker-container --use --driver-opt network=host
docker run --rm -d --name registry --net host registry:2

.PHONY: stop-buildkit-and-registry
stop-buildkit-and-registry:
docker rm -v --force buildkitd
docker buildx rm multiarch
docker rm -v --force registry

.PHONY: generate-project-list
Expand Down
31 changes: 18 additions & 13 deletions projects/tinkerbell/hook/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ EMBEDDED_IMAGES=$(foreach platform,$(HOOK_PLATFORMS),$(OUTPUT_DIR)/hook-embedded
LINUXKIT_VERSION=$(shell cat $(MAKE_ROOT)/../../linuxkit/linuxkit/GIT_TAG | cut -c2-)
LINUXKIT_CACHE_FILE=$(REPO)/cache/linuxkit-linux-$(BUILDER_PLATFORM_ARCH)-$(LINUXKIT_VERSION)
LINUXKIT_IMAGE_REPO?=$(IMAGE_REPO)
EMBEDDED_IMAGES_REPO?=$(IMAGE_REPO)

# 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)
Expand Down Expand Up @@ -143,6 +144,20 @@ $(LINUXKIT_CACHE_FILE): $(PROJECT_DEPENDENCIES_TARGETS)
@mkdir -p $(@D)
cp $(BINARY_DEPS_DIR)/linux-$(BUILDER_PLATFORM_ARCH)/eksa/linuxkit/linuxkit/linuxkit $@

.PHONY: populate-linuxkit-cache
populate-linuxkit-cache:
@git -C $(REPO) checkout -- linuxkit-templates/hook.template.yaml; \
sed -i 's/[^ ]*linuxkit\/\([^:]*\)\(:.*$$\)/$(subst /,\/,$(LINUXKIT_IMAGE_REPO))\/linuxkit\/\1:$(LATEST_TAG)/' $(REPO)/linuxkit-templates/hook.template.yaml; \
images=(); \
while read -r image; do \
if [[ "$$image" == *"sshd"* ]]; then continue; fi; \
images+=($$image); \
done < <(sed -n 's/.*\($(subst /,\/,$(LINUXKIT_IMAGE_REPO)).*$$\)/\1/p' $(REPO)/linuxkit-templates/hook.template.yaml); \
for image in hook-bootkit hook-docker hook-runc hook-containerd hook-kernel hook-ip hook-mdev hook-embedded; do \
images+=($(IMAGE_REPO)/tinkerbell/$$image:$(LATEST_TAG)$(IMAGE_TAG_SUFFIX)); \
done; \
for image in "$${images[@]}"; do build::common::echo_and_run retry $(LINUXKIT_CACHE_FILE) cache pull --cache $(REPO)/cache/linuxkit $$image; done

# We use the linuxkit built from eks-a build tooling
# This includes the linuxkit bin and the images
# The hook linuxkit-template has two sets of images it pulls in
Expand All @@ -156,19 +171,9 @@ $(LINUXKIT_CACHE_FILE): $(PROJECT_DEPENDENCIES_TARGETS)
# Using sed they are pulled back out so that we can run cache pull with retries since we tend to see
# issues from time to time pulling from ecr
$(CREATE_HOOK_FILES_PATTERN)-%: BUILD_ARCH=$(if $(findstring x86_64,$*),amd64,arm64)
$(CREATE_HOOK_FILES_PATTERN)-%: $(LINUXKIT_CACHE_FILE) | $$(ENABLE_DOCKER)
$(CREATE_HOOK_FILES_PATTERN)-%: $(LINUXKIT_CACHE_FILE) | populate-linuxkit-cache $$(ENABLE_DOCKER)
@source $(BUILD_LIB)/common.sh && build::common::use_go_version $(GOLANG_VERSION); \
if [ -f $(REPO)/out/linuxkit-hook-default-$(BUILD_ARCH)/hook-cmdline ]; then echo "remove hook/out before continuing"; exit 1; fi; \
sed -i 's/[^ ]*linuxkit\/\([^:]*\)\(:.*$$\)/$(subst /,\/,$(LINUXKIT_IMAGE_REPO))\/linuxkit\/\1:$(LATEST_TAG)/' $(REPO)/linuxkit-templates/hook.template.yaml; \
images=(); \
while read -r image; do \
if [[ "$$image" == *"sshd"* ]]; then continue; fi; \
images+=($$image); \
done < <(sed -n 's/.*\($(subst /,\/,$(LINUXKIT_IMAGE_REPO)).*$$\)/\1/p' $(REPO)/linuxkit-templates/hook.template.yaml); \
for image in hook-bootkit hook-docker hook-runc hook-containerd hook-kernel hook-ip hook-mdev hook-embedded; do \
images+=($(IMAGE_REPO)/tinkerbell/$$image:$(LATEST_TAG)$(IMAGE_TAG_SUFFIX)); \
done; \
for image in "$${images[@]}"; do build::common::echo_and_run retry $(LINUXKIT_CACHE_FILE) cache pull --cache $(REPO)/cache/linuxkit $$image; done; \
cd $(REPO); \
DEBUG=yes LINUXKIT_VERSION_DEFAULT=$(LINUXKIT_VERSION) HOOK_KERNEL_OCI_BASE=$(IMAGE_REPO)/$(KERNEL_IMAGE_COMPONENT) \
HOOK_LK_CONTAINERS_OCI_BASE=$(IMAGE_REPO)/tinkerbell/ \
Expand All @@ -194,9 +199,9 @@ $(OUTPUT_DIR)/hook-embedded/linux-%/images: IMAGE_TAG_SUFFIX=
$(OUTPUT_DIR)/hook-embedded/linux-%/images: DIND_IMAGE=$(shell $(MAKE) var-value-LATEST_IMAGE IMAGE_NAME=hook-dind)
$(OUTPUT_DIR)/hook-embedded/linux-%/images: $(GIT_PATCH_TARGET)
mkdir -p $(@D)
echo "$$($(MAKE) -C $(MAKE_ROOT)/../tink var-value-LATEST_IMAGE IMAGE_NAME=tink-worker) 127.0.0.1/embedded/tink-worker true" > $@.txt
echo "$$($(MAKE) -C $(MAKE_ROOT)/../tink var-value-LATEST_IMAGE IMAGE_NAME=tink-worker IMAGE_REPO=$(EMBEDDED_IMAGES_REPO)) 127.0.0.1/embedded/tink-worker true" > $@.txt
for action in cexec kexec image2disk oci2disk writefile reboot; do \
echo "$$($(MAKE) -C $(MAKE_ROOT)/../hub var-value-LATEST_IMAGE IMAGE_NAME=$$action) 127.0.0.1/embedded/$$action true" >> $@.txt; \
echo "$$($(MAKE) -C $(MAKE_ROOT)/../hub var-value-LATEST_IMAGE IMAGE_NAME=$$action IMAGE_REPO=$(EMBEDDED_IMAGES_REPO)) 127.0.0.1/embedded/$$action true" >> $@.txt; \
done
cat $@.txt
@if [[ "$(JOB_TYPE)" == "presubmit" ]] && [[ "$(DOCKER_AVAILABLE)" == "false" ]]; then \
Expand Down

0 comments on commit de0a3aa

Please sign in to comment.