forked from lxc/incus-os
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
197 lines (160 loc) · 7.8 KB
/
Copy pathMakefile
File metadata and controls
197 lines (160 loc) · 7.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
GO ?= go
.PHONY: default
default: build
.PHONY: clean
clean:
sudo -E rm -Rf .cache/ certs/efi/updates/*.tar.gz mkosi.output/ mkosi.packages/initrd-tmpfs-root_*_all.deb
sudo -E $(shell command -v mkosi) clean
.PHONY: incus-osd
incus-osd:
(cd incus-osd && go build ./cmd/incus-osd)
strip incus-osd/incus-osd
.PHONY: flasher-tool
flasher-tool:
(cd incus-osd && go build ./cmd/flasher-tool)
strip incus-osd/flasher-tool
.PHONY: kpx
kpx:
$(eval KPX_VERSION := 1.11.0)
ifeq (,$(wildcard incus-osd/kpx/))
git clone https://github.com/momiji/kpx incus-osd/kpx/ --depth 1 -b "v${KPX_VERSION}"
else
(cd incus-osd/kpx && git reset --hard && git fetch --depth 1 origin "v${KPX_VERSION}":refs/tags/"v${KPX_VERSION}" && git checkout "v${KPX_VERSION}")
endif
(cd incus-osd/kpx && patch -p1 < ../../patches/kpx-0001-Enable-IPv6-support.patch)
(cd incus-osd/kpx/cli && go build -o kpx -ldflags="-s -w -X github.com/momiji/kpx.AppVersion=${KPX_VERSION}")
strip incus-osd/kpx/cli/kpx
.PHONY: initrd-deb-package
initrd-deb-package:
$(eval OSNAME := $(shell grep "ImageId=" mkosi.conf | cut -d '=' -f 2))
(cd mkosi.packages/initrd-tmpfs-root && cp initrd-message.service.in initrd-message.service && sed -i -e "s/@OSNAME@/${OSNAME}/" initrd-message.service && debuild)
rm -rf mkosi.packages/initrd-tmpfs-root/debian/.debhelper/ mkosi.packages/initrd-tmpfs-root/debian/debhelper-build-stamp \
mkosi.packages/initrd-tmpfs-root/debian/files \mkosi.packages/initrd-tmpfs-root/debian/initrd-tmpfs-root.postrm.debhelper \
mkosi.packages/initrd-tmpfs-root/debian/initrd-tmpfs-root.substvars mkosi.packages/initrd-tmpfs-root/debian/initrd-tmpfs-root/ \
mkosi.packages/initrd-tmpfs-root_*.dsc mkosi.packages/initrd-tmpfs-root_*.tar.xz mkosi.packages/initrd-tmpfs-root_*.build \
mkosi.packages/initrd-tmpfs-root_*.buildinfo mkosi.packages/initrd-tmpfs-root_*.changes
.PHONY: static-analysis
static-analysis:
ifeq ($(shell command -v go-licenses),)
(cd / ; $(GO) install -v -x github.com/google/go-licenses@latest)
endif
ifeq ($(shell command -v golangci-lint),)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$($(GO) env GOPATH)/bin
endif
cd incus-osd/ && run-parts $(shell run-parts -V >/dev/null 2>&1 && echo -n "--verbose --exit-on-error --regex '.sh'") ../scripts/lint
.PHONY: generate-test-certs
generate-test-certs:
ifeq (,$(wildcard ./certs/))
./scripts/test/generate-test-certificates.sh
./scripts/test/generate-secure-boot-vars.sh
./scripts/test/switch-secure-boot-signing-key.sh 1
endif
.PHONY: build
build: incus-osd flasher-tool kpx initrd-deb-package
ifeq (, $(shell which mkosi))
@echo "mkosi couldn't be found, please install it and try again"
exit 1
endif
-mkosi genkey
mkdir -p mkosi.images/base/mkosi.extra/boot/EFI/
openssl x509 -in mkosi.crt -out mkosi.images/base/mkosi.extra/boot/EFI/mkosi.der -outform DER
mkdir -p mkosi.images/base/mkosi.extra/usr/local/bin/
cp incus-osd/incus-osd mkosi.images/base/mkosi.extra/usr/local/bin/
cp incus-osd/kpx/cli/kpx mkosi.images/base/mkosi.extra/usr/local/bin/
sudo rm -Rf mkosi.output/base* mkosi.output/debug* mkosi.output/incus*
sudo -E $(shell command -v mkosi) --cache-dir .cache/ build
sudo chown $(shell id -u):$(shell id -g) mkosi.output
ifneq (,$(wildcard ./certs/))
# For some reason getting the image name via $(shell ...) is always empty here?
sudo ./scripts/inject-secure-boot-vars.sh `ls mkosi.output/IncusOS_*.raw | grep -v usr | grep -v esp | sort | tail -1`
endif
.PHONY: build-iso
build-iso: build
sudo ./scripts/convert-img-to-iso.sh $(shell ls mkosi.output/IncusOS_*.raw | grep -v usr | grep -v esp | sort | tail -1)
.PHONY: test
test:
# Cleanup
incus delete -f test-incus-os || true
rm -f mkosi.output/IncusOS_boot_media.img
# Prepare the install media
cp $(shell ls mkosi.output/IncusOS_*.raw | grep -v usr | grep -v esp | sort | tail -1) mkosi.output/IncusOS_boot_media.img
dd if=test/seed.install.tar of=mkosi.output/IncusOS_boot_media.img seek=4196352 bs=512 conv=notrunc
# Create the VM
incus init --empty --vm test-incus-os \
-c security.secureboot=false \
-c limits.cpu=4 \
-c limits.memory=8GiB \
-d root,size=50GiB
incus config device add test-incus-os vtpm tpm
incus config device add test-incus-os boot-media disk source=$$(pwd)/mkosi.output/IncusOS_boot_media.img io.bus=usb boot.priority=10 readonly=false
# Wait for installation to complete
incus start test-incus-os --console
@sleep 5 # Wait for VM self-reboot
incus console test-incus-os
@sleep 5 # Wait for VM self-reboot
@clear # Clear the console
# Remove install media
incus stop -f test-incus-os
incus config device remove test-incus-os boot-media
# Start the installed system
incus start test-incus-os --console
.PHONY: test-iso
test-iso:
# Cleanup
incus delete -f test-incus-os || true
incus storage volume delete default IncusOS_boot_media.iso || true
rm -f mkosi.output/IncusOS_boot_media.iso
# Prepare the install media
cp $(shell ls mkosi.output/IncusOS_*.iso | grep -v usr | grep -v esp | sort | tail -1) mkosi.output/IncusOS_boot_media.iso
dd if=test/seed.install.tar of=mkosi.output/IncusOS_boot_media.iso seek=4196352 bs=512 conv=notrunc
incus storage volume import default mkosi.output/IncusOS_boot_media.iso IncusOS_boot_media.iso --type=iso
# Create the VM
incus init --empty --vm test-incus-os \
-c security.secureboot=false \
-c limits.cpu=4 \
-c limits.memory=8GiB \
-d root,size=50GiB
incus config device add test-incus-os vtpm tpm
incus config device add test-incus-os boot-media disk pool=default source=IncusOS_boot_media.iso boot.priority=10
# Wait for installation to complete
incus start test-incus-os --console
@sleep 5 # Wait for VM self-reboot
incus console test-incus-os
@sleep 5 # Wait for VM self-reboot
@clear # Clear the console
# Remove install media
incus stop -f test-incus-os
incus config device remove test-incus-os boot-media
# Start the installed system
incus start test-incus-os --console
.PHONY: test-applications
test-applications:
$(eval RELEASE := $(shell ls mkosi.output/*.efi | sed -e "s/.*_//g" -e "s/.efi//g" | sort -n | tail -1))
incus exec test-incus-os -- mkdir -p /root/updates
echo ${RELEASE} | incus file push - test-incus-os/root/updates/RELEASE
incus file push mkosi.output/debug.raw test-incus-os/root/updates/
incus file push mkosi.output/incus.raw test-incus-os/root/updates/
incus exec test-incus-os -- curl --unix-socket /run/incus-os/unix.socket http://localhost/1.0/system/update -X POST
.PHONY: test-update
test-update:
$(eval RELEASE := $(shell ls mkosi.output/*.efi | sed -e "s/.*_//g" -e "s/.efi//g" | sort -n | tail -1))
incus exec test-incus-os -- mkdir -p /root/updates
echo ${RELEASE} | incus file push - test-incus-os/root/updates/RELEASE
incus file push mkosi.output/IncusOS_${RELEASE}.efi test-incus-os/root/updates/
incus file push mkosi.output/IncusOS_${RELEASE}.usr* test-incus-os/root/updates/
incus file push mkosi.output/debug.raw test-incus-os/root/updates/
incus file push mkosi.output/incus.raw test-incus-os/root/updates/
incus exec test-incus-os -- curl --unix-socket /run/incus-os/unix.socket http://localhost/1.0/system/update -X POST
.PHONY: test-update-sb-keys
test-update-sb-keys:
$(eval RELEASE := $(shell ls mkosi.output/*.efi | sed -e "s/.*_//g" -e "s/.efi//g" | sort -n | tail -1))
incus exec test-incus-os -- mkdir -p /root/updates
echo ${RELEASE} | incus file push - test-incus-os/root/updates/RELEASE
cd certs/efi/updates/ && tar czf IncusOS_SecureBootKeys_${RELEASE}.tar.gz *.auth
incus file push certs/efi/updates/*.tar.gz test-incus-os/root/updates/
incus exec test-incus-os -- curl --unix-socket /run/incus-os/unix.socket http://localhost/1.0/system/update -X POST
.PHONY: update-gomod
update-gomod:
cd incus-osd && go get -t -v -u ./...
cd incus-osd && go mod tidy --go=1.24.0
cd incus-osd && go get toolchain@none