Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,10 @@ help: ## Print this help
include rules.mk
include lint.mk

all: containers images ## Build release mode boot files and container images for all supported architectures

dev: image-dbg-$(ARCH) ## Build debug mode boot files and container images for currently running architecture

images: ## Build release mode boot files for all supported architectures

all: dist dbg-dist ## Build release mode boot files and container images for all supported architectures
containers: hook-bootkit hook-docker ## Build container images

debug: ## Build debug mode boot files and container images for all supported architectures

dev: dbg-image-$(ARCH) ## Build debug mode boot files and container images for currently running architecture
images: ## Build release mode boot files for all supported architectures
push: push-hook-bootkit push-hook-docker ## Push container images to registry

run: run-$(ARCH) ## Boot system using qemu
4 changes: 2 additions & 2 deletions hook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ services:
files:
- path: etc/profile.d/local.sh
contents: |
alias docker='ctr -n services.linuxkit tasks exec --tty --exec-id cmd docker docker'
alias docker-shell='ctr -n services.linuxkit tasks exec --tty --exec-id shell docker sh'
alias docker='ctr -n services.linuxkit tasks exec --tty --exec-id cmd hook-docker docker'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this extra space intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep just an alignment along the = so that its easy to spot the differences.

alias docker-shell='ctr -n services.linuxkit tasks exec --tty --exec-id shell hook-docker sh'
mode: "0644"

#dbg - path: root/.ssh/authorized_keys
Expand Down
90 changes: 43 additions & 47 deletions rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,50 +29,50 @@ hook-bootkit-deps := $(wildcard hook-bootkit/*)
hook-docker-deps := $(wildcard hook-docker/*)

define foreach_mode_arch_rules =
# mode := $(1)
# arch := $(2)
mode := $(1)
arch := $(2)

$$(shell mkdir -p out/$T/$(1)/$(2))
$$(shell mkdir -p out/$T/$(mode)/$(arch))

.PHONY: hook-$(1)-$(2)
image-$(1)-$(2): out/$T/$(1)/$(2)/hook.tar
out/$T/$(1)/$(2)/hook.tar: out/$T/$(1)/$(2)/hook.yaml out/$T/hook-bootkit-$(2) out/$T/hook-docker-$(2)
linuxkit build -docker -arch $(2) -format tar-kernel-initrd -name hook -dir $$(@D) $$<
.PHONY: image-$(mode)-$(arch)
image-$(mode)-$(arch): out/$T/$(mode)/$(arch)/hook.tar

out/$T/$(mode)/$(arch)/hook.tar: out/$T/$(mode)/$(arch)/hook.yaml out/$T/hook-bootkit-$(arch) out/$T/hook-docker-$(arch)
linuxkit build -docker -arch $(arch) -format tar-kernel-initrd -name hook -dir $$(@D) $$<
mv $$(@D)/hook-initrd.tar $$@

out/$T/$(1)/$(2)/cmdline out/$T/$(1)/$(2)/initrd.img out/$T/$(1)/$(2)/kernel: out/$T/$(1)/$(2)/hook.tar
out/$T/$(mode)/$(arch)/cmdline out/$T/$(mode)/$(arch)/initrd.img out/$T/$(mode)/$(arch)/kernel: out/$T/$(mode)/$(arch)/hook.tar
tar xf $$^ -C $$(@D) $$(@F)
touch $$@

out/$T/$(1)/$(2)/hook.yaml: $$(LINUXKIT_CONFIG)
sed '/hook-\(bootkit\|docker\):/ { s|:latest|:$T-$(2)|; s|quay.io/tinkerbell|$(ORG)|; }' $$< > $$@
if [[ $(1) == dbg ]]; then
sed -i '/^\s*dbg/ s|#dbg||' $$@
out/$T/$(mode)/$(arch)/hook.yaml: $$(LINUXKIT_CONFIG)
sed '/hook-\(bootkit\|docker\):/ { s|:latest|:$T-$(arch)|; s|quay.io/tinkerbell|$(ORG)|; }' $$< > $$@
if [[ $(mode) == dbg ]]; then
sed -i '/^\s*#dbg/ s|#dbg||' $$@
fi
endef
$(foreach m,$(modes),$(foreach a,$(arches),$(eval $(call foreach_mode_arch_rules,$m,$a))))

define foreach_arch_rules =
# arch := $(1)

debug: out/$T/dbg/$(1)/hook.tar
images: out/$T/rel/$(1)/hook.tar
image-dbg-$(1): out/$T/dbg/$(1)/hook.tar

out/$T/rel/hook.tar: out/$T/rel/$(1)/initrd.img out/$T/rel/$(1)/kernel
hook-bootkit: out/$T/hook-bootkit-$(1)
hook-docker: out/$T/hook-docker-$(1)

out/$T/hook-bootkit-$(1): $$(hook-bootkit-deps)
out/$T/hook-docker-$(1): $$(hook-docker-deps)
out/$T/hook-bootkit-$(1) out/$T/hook-docker-$(1): platform=linux/$$(lastword $$(subst -, ,$$(notdir $$@)))
out/$T/hook-bootkit-$(1) out/$T/hook-docker-$(1): container=hook-$$(word 2,$$(subst -, ,$$(notdir $$@)))
out/$T/hook-bootkit-$(1) out/$T/hook-docker-$(1):
docker buildx build --platform $$(platform) --load -t $(ORG)/$$(container):$T-$(1) $$(container)
arch := $(1)

debug: dbg-image-$(arch)
dbg-image-$(arch): out/$T/dbg/$(arch)/hook.tar
images: out/$T/rel/$(arch)/hook.tar

hook-bootkit: out/$T/hook-bootkit-$(arch)
hook-docker: out/$T/hook-docker-$(arch)

out/$T/hook-bootkit-$(arch): $$(hook-bootkit-deps)
out/$T/hook-docker-$(arch): $$(hook-docker-deps)
out/$T/hook-bootkit-$(arch) out/$T/hook-docker-$(arch): platform=linux/$$(lastword $$(subst -, ,$$(notdir $$@)))
out/$T/hook-bootkit-$(arch) out/$T/hook-docker-$(arch): container=hook-$$(word 2,$$(subst -, ,$$(notdir $$@)))
out/$T/hook-bootkit-$(arch) out/$T/hook-docker-$(arch):
docker buildx build --platform $$(platform) --load -t $(ORG)/$$(container):$T-$(arch) $$(container)
touch $$@

run-$(1): out/$T/dbg/$(1)/hook.tar
run-$(1):
run-$(arch): out/$T/dbg/$(arch)/hook.tar
run-$(arch):
linuxkit run qemu --mem 2048 $$^
endef
$(foreach a,$(arches),$(eval $(call foreach_arch_rules,$a)))
Expand All @@ -87,21 +87,17 @@ push-hook-bootkit push-hook-docker:
docker buildx build --platform $$platforms --push -t $(ORG)/$(container):$T $(container)

.PHONY: dist
dist: out/$T/rel/hook-$T.tar.gz ## Build tarball for distribution
out/$T/rel/hook-$T.tar.gz: out/$T/rel/hook.tar
pigz < $< > $@

out/$T/rel/hook.tar:
rm -rf out/$T/rel/dist
mkdir -p out/$T/rel/dist
for a in $(arches); do
cp out/$T/rel/$$a/initrd.img out/$T/rel/dist/initramfs-$$a
cp out/$T/rel/$$a/kernel out/$T/rel/dist/vmlinuz-$$a
dist: out/$T/rel/amd64/hook.tar out/$T/rel/arm64/hook.tar ## Build tarballs for distribution
dbg-dist: out/$T/dbg/$(ARCH)/hook.tar ## Build debug enabled tarball
dist dbg-dist:
for f in $^; do
case $$f in
*amd64*) arch=x86_64 ;;
*arm64*) arch=aarch64 ;;
*) echo unknown arch && exit 1;;
esac
d=$$(dirname $$(dirname $$f))
tar -xf $$f -C $$d/ kernel && mv $$d/kernel $$d/vmlinuz-$$arch
tar -xf $$f -C $$d/ initrd.img && mv $$d/initrd.img $$d/initramfs-$$arch
tar -cf- -C $$d initramfs-$$arch vmlinuz-$$arch | pigz > $$d/hook_$$arch.tar.gz
done
cd out/$T/rel/dist && tar -cvf ../$(@F) ./*

deploy: dist ## Push tarball to S3
ifeq ($(shell git rev-parse --abbrev-ref HEAD),main)
s3cmd sync ./out/hook-$T.tar.gz s3://s.gianarb.it/hook/$T.tar.gz
s3cmd cp s3://s.gianarb.it/hook/hook-$T.tar.gz s3://s.gianarb.it/hook/hook-main.tar.gz
endif