-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework the Makefile so its not racy (#105)
## Description Reworks/overhauls the Makefile setup so that we have proper deps and targets, while minimizing repetition. Also merges ci.yaml and push.yaml into just one file/workflow ## Why is this needed I tried building hook locally and was confused as to how to do it and what it was going to do. Once I opened the Makefile I could not let it be. I merged ci.yaml and push.yaml because push.yaml was potentially overwriting the 0.0 tags for the container images in quay.io if a push to a non-main branch occurred. This would cause anyone building hook locally to unintended/possibly buggy code. ## How Has This Been Tested? I've run so many `make` invocations its not even funny. I've built the arm and amd targets for image and the containers. I've run `make dist` and have the expected tarball. I've also run `make run` and have booted a qemu vm with the built files. Everything good so far. Also ran through github actions a bunch. ## How are existing users impacted? What migration steps/scripts do we need? Able to build hook locally, more easily/reliably. Won't get unexpected containers when building hook. ## Checklist: I have: - [ ] updated the documentation and/or roadmap (if required) - [ ] added unit or e2e tests - [ ] provided instructions on how to upgrade
- Loading branch information
Showing
24 changed files
with
282 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!shell.nix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
bin/ | ||
bootkit/local/ | ||
dbg/ | ||
dist/ | ||
.env | ||
hook-*.tar.gz | ||
hook.yaml | ||
hook-* | ||
!/hook-bootkit/ | ||
!/hook-docker/ | ||
hook*.*.yaml | ||
out/ | ||
*.swp | ||
tink-docker/local/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,131 +1,37 @@ | ||
ORG ?= quay.io/tinkerbell | ||
ARCH := $(shell uname -m) | ||
|
||
ifeq ($(strip $(TAG)),) | ||
# ^ guards against TAG being defined but empty string which makes `TAG ?=` not work | ||
TAG := latest | ||
# set the ORG | ||
### !!NOTE!! | ||
# If this is changed then a fresh output dir is required (`git clean -fxd` or just `rm -rf out`) | ||
# Handling this better shows some of make's suckiness compared to newer build tools (redo, tup ...) where the command lines to tools invoked isn't tracked by make | ||
ORG := quay.io/tinkerbell | ||
# makes sure there's no trailing / so we can just add them in the recipes which looks nicer | ||
ORG := $(shell echo "${ORG}" | sed 's|/*$$||') | ||
|
||
# The following `ifeq` are the equivalent of FOO ?= except that they work correctly if FOO is set but empty | ||
ifeq ($(strip $(LINUXKIT_CONFIG)),) | ||
LINUXKIT_CONFIG := hook.yaml | ||
endif | ||
default: bootkitBuild tink-dockerBuild image | ||
|
||
dev: dev-bootkitBuild dev-tink-dockerBuild | ||
ifeq ($(ARCH),x86_64) | ||
dev: dev-image-amd64 | ||
endif | ||
ifeq ($(ARCH),aarch64) | ||
dev: dev-image-arm64 | ||
ifeq ($(strip $(TAG)),) | ||
TAG := sha-$(shell git rev-parse --short HEAD) | ||
endif | ||
T := $(strip $(TAG)) | ||
|
||
# This option is for running docker manifest command | ||
export DOCKER_CLI_EXPERIMENTAL := enabled | ||
|
||
LINUXKIT_CONFIG ?= hook.in.yaml | ||
.PHONY: hook.yaml | ||
hook.yaml: $(LINUXKIT_CONFIG) | ||
sed '/quay.io/ s|:latest|:$(TAG)|' $^ > $@.tmp | ||
mv $@.tmp $@ | ||
|
||
image-amd64: hook.yaml | ||
mkdir -p out | ||
linuxkit build -docker -pull -format kernel+initrd -name hook-x86_64 -dir out hook.yaml | ||
|
||
image-arm64: hook.yaml | ||
mkdir -p out | ||
linuxkit build -docker -pull -arch arm64 -format kernel+initrd -name hook-aarch64 -dir out hook.yaml | ||
|
||
dev-image-amd64: hook.yaml | ||
mkdir -p out | ||
linuxkit build -docker -format kernel+initrd -name hook-x86_64 -dir out hook.yaml | ||
|
||
dev-image-arm64: hook.yaml | ||
mkdir -p out | ||
linuxkit build -docker -arch arm64 -format kernel+initrd -name hook-aarch64 -dir out hook.yaml | ||
|
||
image: image-amd64 image-arm64 | ||
|
||
debug-image-amd64: | ||
mkdir -p out/amd64 | ||
linuxkit build --docker -format kernel+initrd -name debug-x86_64 -dir out hook_debug.yaml | ||
help: ## Print this help | ||
@grep --no-filename -E '^[[:alnum:]_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sed 's/:.*## /·/' | sort | column -t -s '·' -c $$(tput cols) | ||
|
||
debug-image-arm64: | ||
mkdir -p out/arm64 | ||
linuxkit build --docker -arch arm64 -format kernel+initrd -name debug-aarch64 -dir out hook_debug.yaml | ||
include rules.mk | ||
include lint.mk | ||
|
||
debug-image: debug-image-amd64 debug-image-arm64 | ||
all: containers images ## Build release mode boot files and container images for all supported architectures | ||
|
||
run-amd64: | ||
sudo ~/go/bin/linuxkit run qemu --mem 2048 out/hook-x86_64 | ||
dev: image-dbg-$(ARCH) ## Build debug mode boot files and container images for currently running architecture | ||
|
||
run-arm64: | ||
sudo ~/go/bin/linuxkit run qemu --mem 2048 out/hook-aarch64 | ||
images: ## Build release mode boot files for all supported architectures | ||
|
||
run: | ||
sudo ~/go/bin/linuxkit run qemu --mem 2048 out/hook-${ARCH} | ||
containers: hook-bootkit hook-docker ## Build container images | ||
|
||
dev-bootkitBuild: | ||
cd bootkit; docker buildx build --load -t $(ORG)/hook-bootkit:$(TAG) . | ||
|
||
bootkitBuild: | ||
cd bootkit; docker buildx build --platform linux/amd64,linux/arm64 --push -t $(ORG)/hook-bootkit:$(TAG) . | ||
|
||
dev-tink-dockerBuild: | ||
cd tink-docker; docker buildx build --load -t $(ORG)/hook-docker:$(TAG) . | ||
|
||
tink-dockerBuild: | ||
cd tink-docker; docker buildx build --platform linux/amd64,linux/arm64 --push -t $(ORG)/hook-docker:$(TAG) . | ||
|
||
dev-convert: | ||
rm -rf ./convert | ||
mkdir ./convert | ||
cp out/hook-${ARCH}-initrd.img ./convert/initrd.gz | ||
cd convert/; gunzip ./initrd.gz; cpio -idv < initrd; rm initrd; find . -print0 | cpio --null -ov --format=newc > ../initramfs-${ARCH}; gzip ../initramfs-${ARCH} | ||
|
||
.PHONY: convert | ||
convert: | ||
for a in x86_64 aarch64; do \ | ||
rm -rf ./convert; \ | ||
mkdir ./convert; \ | ||
cp out/hook-$$a-initrd.img ./convert/initrd.gz; \ | ||
cd convert/; gunzip ./initrd.gz; cpio -idv < initrd; rm initrd; find . -print0 | cpio --null -ov --format=newc > ../initramfs-$$a; gzip ../initramfs-$$a; cd ../;\ | ||
done | ||
|
||
dist: default convert | ||
rm -rf ./dist ./convert | ||
mkdir ./dist | ||
for a in x86_64 aarch64; do \ | ||
mv ./initramfs-$$a.gz ./dist/initramfs-$$a; \ | ||
mv ./out/hook-$$a-kernel ./dist/vmlinuz-$$a; \ | ||
done | ||
rm -rf out | ||
cd ./dist && tar -czvf ../hook-${TAG}.tar.gz ./* | ||
|
||
dist-existing-images: image convert | ||
rm -rf ./dist ./convert | ||
mkdir ./dist | ||
for a in x86_64 aarch64; do \ | ||
mv ./initramfs-$$a.gz ./dist/initramfs-$$a; \ | ||
mv ./out/hook-$$a-kernel ./dist/vmlinuz-$$a; \ | ||
done | ||
rm -rf out | ||
cd ./dist && tar -czvf ../hook-${TAG}.tar.gz ./* | ||
|
||
|
||
dev-dist: dev dev-convert | ||
rm -rf ./dist ./convert | ||
mkdir ./dist | ||
mv ./initramfs-${ARCH}.gz ./dist/initramfs-${ARCH} | ||
mv ./out/hook-${ARCH}-kernel ./dist/vmlinuz-${ARCH} | ||
rm -rf out | ||
cd ./dist && tar -czvf ../hook-${TAG}.tar.gz ./* | ||
|
||
deploy: dist | ||
ifeq ($(shell git rev-parse --abbrev-ref HEAD),main) | ||
s3cmd sync ./hook-${TAG}.tar.gz s3://s.gianarb.it/hook/${TAG}.tar.gz | ||
s3cmd cp s3://s.gianarb.it/hook/hook-${TAG}.tar.gz s3://s.gianarb.it/hook/hook-main.tar.gz | ||
endif | ||
debug: ## Build debug mode boot files and container images for all supported architectures | ||
|
||
.PHONY: clean | ||
clean: | ||
rm ./hook-${TAG}.tar.gz | ||
rm -rf dist/ out/ tink-docker/local/ bootkit/local/ | ||
push: push-hook-bootkit push-hook-docker ## Push container images to registry | ||
|
||
-include lint.mk | ||
run: run-$(ARCH) ## Boot system using qemu |
Oops, something went wrong.