|
1 | | -ORG ?= quay.io/tinkerbell |
2 | | -ARCH := $(shell uname -m) |
3 | | - |
4 | | -ifeq ($(strip $(TAG)),) |
5 | | - # ^ guards against TAG being defined but empty string which makes `TAG ?=` not work |
6 | | - TAG := latest |
| 1 | +# set the ORG |
| 2 | +### !!NOTE!! |
| 3 | +# If this is changed then a fresh output dir is required (`git clean -fxd` or just `rm -rf out`) |
| 4 | +# 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 |
| 5 | +ORG := quay.io/mmlb |
| 6 | +# makes sure there's no trailing / so we can just add them in the recipes which looks nicer |
| 7 | +ORG := $(shell echo "${ORG}" | sed 's|/*$$||') |
| 8 | + |
| 9 | +# The following `ifeq` are the equivalent of FOO ?= except that they work correctly if FOO is set but empty |
| 10 | +ifeq ($(strip $(LINUXKIT_CONFIG)),) |
| 11 | + LINUXKIT_CONFIG := hook.yaml |
7 | 12 | endif |
8 | | -default: hook-bootkitBuild hook-dockerBuild image |
9 | 13 |
|
10 | | -dev: dev-hook-bootkitBuild dev-hook-dockerBuild |
11 | | -ifeq ($(ARCH),x86_64) |
12 | | -dev: dev-image-amd64 |
13 | | -endif |
14 | | -ifeq ($(ARCH),aarch64) |
15 | | -dev: dev-image-arm64 |
| 14 | +ifeq ($(strip $(TAG)),) |
| 15 | + TAG := sha-$(shell git rev-parse --short HEAD) |
16 | 16 | endif |
| 17 | +T := $(strip $(TAG)) |
17 | 18 |
|
18 | | -# This option is for running docker manifest command |
19 | | -export DOCKER_CLI_EXPERIMENTAL := enabled |
20 | | - |
21 | | -LINUXKIT_CONFIG ?= hook.yaml |
22 | | -hook.$(TAG).yaml: $(LINUXKIT_CONFIG) |
23 | | - sed '/quay.io/ s|:latest|:$(TAG)|' $^ > $@.tmp |
24 | | - mv $@.tmp $@ |
25 | | - |
26 | | -hook-debug.$(TAG).yaml: hook.$(TAG).yaml |
27 | | - sed '/^\s*#dbg/ s|#dbg||' $^ > $@.tmp |
28 | | - mv $@.tmp $@ |
29 | | - |
30 | | -image-amd64: hook.$(TAG).yaml |
31 | | - mkdir -p out |
32 | | - linuxkit build -docker -pull -format kernel+initrd -name hook-x86_64 -dir out $^ |
33 | | - |
34 | | -image-arm64: hook.$(TAG).yaml |
35 | | - mkdir -p out |
36 | | - linuxkit build -docker -pull -arch arm64 -format kernel+initrd -name hook-aarch64 -dir out $^ |
37 | | - |
38 | | -dev-image-amd64: hook.$(TAG).yaml |
39 | | - mkdir -p out |
40 | | - linuxkit build -docker -format kernel+initrd -name hook-x86_64 -dir out $^ |
41 | | - |
42 | | -dev-image-arm64: hook.$(TAG).yaml |
43 | | - mkdir -p out |
44 | | - linuxkit build -docker -arch arm64 -format kernel+initrd -name hook-aarch64 -dir out $^ |
45 | | - |
46 | | -image: image-amd64 image-arm64 |
47 | | - |
48 | | -debug-image-amd64: hook-debug.$(TAG).yaml |
49 | | - mkdir -p out/amd64 |
50 | | - linuxkit build --docker -format kernel+initrd -name debug-x86_64 -dir out $^ |
| 19 | +help: ## Print this help |
| 20 | + @grep --no-filename -E '^[[:alnum:]_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sed 's/:.*## /·/' | sort | column -t -W 2 -s '·' -c $$(tput cols) |
51 | 21 |
|
52 | | -debug-image-arm64: hook-debug.$(TAG).yaml |
53 | | - mkdir -p out/arm64 |
54 | | - linuxkit build --docker -arch arm64 -format kernel+initrd -name debug-aarch64 -dir out $^ |
| 22 | +include rules.mk |
| 23 | +include lint.mk |
55 | 24 |
|
56 | | -debug-image: debug-image-amd64 debug-image-arm64 |
| 25 | +all: containers images ## Build release mode boot files and container images for all supported architectures |
57 | 26 |
|
58 | | -run-amd64: |
59 | | - sudo ~/go/bin/linuxkit run qemu --mem 2048 out/hook-x86_64 |
| 27 | +dev: image-dbg-$(ARCH) ## Build debug mode boot files and container images for currently running architecture |
60 | 28 |
|
61 | | -run-arm64: |
62 | | - sudo ~/go/bin/linuxkit run qemu --mem 2048 out/hook-aarch64 |
| 29 | +images: ## Build release mode boot files for all supported architectures |
63 | 30 |
|
64 | | -run: |
65 | | - sudo ~/go/bin/linuxkit run qemu --mem 2048 out/hook-${ARCH} |
| 31 | +containers: hook-bootkit hook-docker ## Build container images |
66 | 32 |
|
67 | | -dev-hook-bootkitBuild: |
68 | | - cd hook-bootkit; docker buildx build --load -t $(ORG)/hook-bootkit:$(TAG) . |
69 | | - |
70 | | -hook-bootkitBuild: |
71 | | - cd hook-bootkit; docker buildx build --platform linux/amd64,linux/arm64 --push -t $(ORG)/hook-bootkit:$(TAG) . |
72 | | - |
73 | | -dev-hook-dockerBuild: |
74 | | - cd hook-docker; docker buildx build --load -t $(ORG)/hook-docker:$(TAG) . |
75 | | - |
76 | | -hook-dockerBuild: |
77 | | - cd hook-docker; docker buildx build --platform linux/amd64,linux/arm64 --push -t $(ORG)/hook-docker:$(TAG) . |
78 | | - |
79 | | -dev-convert: |
80 | | - rm -rf ./convert |
81 | | - mkdir ./convert |
82 | | - cp out/hook-${ARCH}-initrd.img ./convert/initrd.gz |
83 | | - cd convert/; gunzip ./initrd.gz; cpio -idv < initrd; rm initrd; find . -print0 | cpio --null -ov --format=newc > ../initramfs-${ARCH}; gzip ../initramfs-${ARCH} |
84 | | - |
85 | | -.PHONY: convert |
86 | | -convert: |
87 | | - for a in x86_64 aarch64; do \ |
88 | | - rm -rf ./convert; \ |
89 | | - mkdir ./convert; \ |
90 | | - cp out/hook-$$a-initrd.img ./convert/initrd.gz; \ |
91 | | - cd convert/; gunzip ./initrd.gz; cpio -idv < initrd; rm initrd; find . -print0 | cpio --null -ov --format=newc > ../initramfs-$$a; gzip ../initramfs-$$a; cd ../;\ |
92 | | - done |
93 | | - |
94 | | -dist: default convert |
95 | | - rm -rf ./dist ./convert |
96 | | - mkdir ./dist |
97 | | - for a in x86_64 aarch64; do \ |
98 | | - mv ./initramfs-$$a.gz ./dist/initramfs-$$a; \ |
99 | | - mv ./out/hook-$$a-kernel ./dist/vmlinuz-$$a; \ |
100 | | - done |
101 | | - rm -rf out |
102 | | - cd ./dist && tar -czvf ../hook-${TAG}.tar.gz ./* |
103 | | - |
104 | | -dist-existing-images: image convert |
105 | | - rm -rf ./dist ./convert |
106 | | - mkdir ./dist |
107 | | - for a in x86_64 aarch64; do \ |
108 | | - mv ./initramfs-$$a.gz ./dist/initramfs-$$a; \ |
109 | | - mv ./out/hook-$$a-kernel ./dist/vmlinuz-$$a; \ |
110 | | - done |
111 | | - rm -rf out |
112 | | - cd ./dist && tar -czvf ../hook-${TAG}.tar.gz ./* |
113 | | - |
114 | | - |
115 | | -dev-dist: dev dev-convert |
116 | | - rm -rf ./dist ./convert |
117 | | - mkdir ./dist |
118 | | - mv ./initramfs-${ARCH}.gz ./dist/initramfs-${ARCH} |
119 | | - mv ./out/hook-${ARCH}-kernel ./dist/vmlinuz-${ARCH} |
120 | | - rm -rf out |
121 | | - cd ./dist && tar -czvf ../hook-${TAG}.tar.gz ./* |
122 | | - |
123 | | -deploy: dist |
124 | | -ifeq ($(shell git rev-parse --abbrev-ref HEAD),main) |
125 | | - s3cmd sync ./hook-${TAG}.tar.gz s3://s.gianarb.it/hook/${TAG}.tar.gz |
126 | | - s3cmd cp s3://s.gianarb.it/hook/hook-${TAG}.tar.gz s3://s.gianarb.it/hook/hook-main.tar.gz |
127 | | -endif |
| 33 | +debug: ## Build debug mode boot files and container images for all supported architectures |
128 | 34 |
|
129 | | -.PHONY: clean |
130 | | -clean: |
131 | | - rm ./hook-${TAG}.tar.gz |
132 | | - rm -rf dist/ out/ hook-docker/local/ hook-bootkit/local/ |
| 35 | +push: push-hook-bootkit push-hook-docker ## Push container images to registry |
133 | 36 |
|
134 | | --include lint.mk |
| 37 | +run: run-$(ARCH) ## Boot system using qemu |
0 commit comments