-
Notifications
You must be signed in to change notification settings - Fork 162
/
Makefile
1143 lines (981 loc) · 52 KB
/
Makefile
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) 2018 Zededa, Inc.
# SPDX-License-Identifier: Apache-2.0
#
# Run make (with no arguments) to see help on what targets are available
# universal constants and functions
null :=
space := $(null) #
comma := ,
uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
# you are not supposed to tweak these variables -- they are effectively R/O
HV_DEFAULT=kvm
GOVER ?= 1.20.1
PKGBASE=github.com/lf-edge/eve
GOMODULE=$(PKGBASE)/pkg/pillar
GOTREE=$(CURDIR)/pkg/pillar
BUILDTOOLS_BIN=$(CURDIR)/build-tools/bin
PATH:=$(BUILDTOOLS_BIN):$(PATH)
GOPKGVERSION=$(shell tools/goversion.sh 2>/dev/null)
export CGO_ENABLED GOOS GOARCH PATH
ifeq ($(BUILDKIT_PROGRESS),)
export BUILDKIT_PROGRESS := plain
endif
# A set of tweakable knobs for our build needs (tweak at your risk!)
# Which version to assign to snapshot builds (0.0.0 if built locally, 0.0.0-snapshot if on CI/CD)
EVE_SNAPSHOT_VERSION=0.0.0
# which language bindings to generate for EVE API
PROTO_LANGS=go python
# Use 'make HV=acrn|xen|kvm|kubevirt' to build ACRN images (AMD64 only), Xen or KVM
HV=$(HV_DEFAULT)
# Enable development build (disabled by default)
DEV=n
# How large to we want the disk to be in Mb
MEDIA_SIZE?=32768
# Image type for final disk images
IMG_FORMAT=qcow2
ifdef LIVE_UPDATE
# For live updates we support read-write FS, like ext4
ROOTFS_FORMAT=ext4
# And generate tar faster
LIVE_FAST=1
else
# Filesystem type for rootfs image
ROOTFS_FORMAT?=squash
endif
# Image type for installer image
INSTALLER_IMG_FORMAT=raw
# SSH port to use for running images live
SSH_PORT=2222
# ports to proxy into a running EVE instance (in ssh notation with -L)
SSH_PROXY=-L6000:localhost:6000
# ssh key to be used for getting into an EVE instance
SSH_KEY=$(CONF_DIR)/ssh.key
# Disable QEMU H/W acceleration (any non-empty value will trigger using it)
NOACCEL=
# Use TPM device (any non-empty value will trigger using it), i.e. 'make TPM=y run'
TPM=
# Prune dangling images after build of package to reduce disk usage (any non-empty value will trigger using it)
# Be aware that with this flag we will clean all dangling images in system, not only EVE-OS related
PRUNE=
# Location of the EVE configuration folder to be used in builds
CONF_DIR=conf
# Source of the cloud-init enabled qcow2 Linux VM for all architectures
BUILD_VM_SRC_arm64=https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-arm64.img
BUILD_VM_SRC_amd64=https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img
BUILD_VM_SRC=$(BUILD_VM_SRC_$(ZARCH))
UNAME_S := $(shell uname -s)
UNAME_S_LCASE=$(shell uname -s | tr '[A-Z]' '[a-z]')
# store the goos for local, as an easier-to-reference var
LOCAL_GOOS=$(UNAME_S_LCASE)
USER = $(shell id -u -n)
GROUP = $(shell id -g -n)
UID = $(shell id -u)
GID = $(shell id -g)
#for MacOS - use predefined user and group IDs
ifeq ($(UNAME_S),Darwin)
USER = eve
GROUP = eve
UID = 1001
GID = 1001
endif
REPO_BRANCH=$(shell git rev-parse --abbrev-ref HEAD | tr / _)
REPO_SHA=$(shell git describe --match '$$^' --abbrev=8 --always --dirty)
# set this variable to the current tag only if we are building from a tag (annotated or not), otherwise set it to "snapshot", which means rootfs version will be constructed differently
REPO_TAG=$(shell git describe --always --tags | grep -E '^[0-9]+\.[0-9]+\.[0-9]+(-lts|-rc[0-9]+)?$$' || echo snapshot)
REPO_DIRTY_TAG=$(if $(findstring -dirty,$(REPO_SHA)),-$(shell date -u +"%Y-%m-%d.%H.%M"))
EVE_TREE_TAG = $(shell git describe --abbrev=8 --always --dirty --tags)
ifeq ($(DEV),y)
DEV_TAG:=-dev
endif
# ROOTFS_VERSION used to construct the installer directory
# set this to the current tag only if we are building from a tag
ROOTFS_VERSION:=$(if $(findstring snapshot,$(REPO_TAG)),$(EVE_SNAPSHOT_VERSION)-$(REPO_BRANCH)-$(REPO_SHA)$(REPO_DIRTY_TAG)$(DEV_TAG),$(REPO_TAG))
#if KERNEL_TAG is set, append it to the ROOTFS_VERSION but replace docker.io/lfedge/eve-kernel:eve-kernel- part with k-
SHORT_KERNEL_TAG=$(subst docker.io/lfedge/eve-kernel:eve-kernel-,k-,$(KERNEL_TAG))
ROOTFS_VERSION:=$(if $(SHORT_KERNEL_TAG),$(ROOTFS_VERSION)-$(SHORT_KERNEL_TAG),$(ROOTFS_VERSION))
HOSTARCH:=$(subst aarch64,arm64,$(subst x86_64,amd64,$(shell uname -m)))
# by default, take the host architecture as the target architecture, but can override with `make ZARCH=foo`
# assuming that the toolchain supports it, of course...
ZARCH ?= $(HOSTARCH)
export ZARCH
# warn if we are cross-compiling and track it
CROSS ?=
ifneq ($(HOSTARCH),$(ZARCH))
CROSS = 1
$(warning "WARNING: We are assembling an $(ZARCH) image on $(HOSTARCH). Things may break.")
endif
DOCKER_ARCH_TAG=$(ZARCH)
FULL_VERSION:=$(ROOTFS_VERSION)-$(HV)-$(ZARCH)
# must be included after ZARCH is set
include $(CURDIR)/kernel-version.mk
# where we store outputs
DIST=$(CURDIR)/dist/$(ZARCH)
DOCKER_DIST=/eve/dist/$(ZARCH)
BUILD_DIR=$(DIST)/$(ROOTFS_VERSION)
INSTALLER=$(BUILD_DIR)/installer
LIVE=$(BUILD_DIR)/live
LIVE_IMG=$(BUILD_DIR)/live.$(IMG_FORMAT)
TARGET_IMG=$(BUILD_DIR)/target.img
VERSION_FILE=$(INSTALLER)/eve_version
CURRENT_DIR=$(DIST)/current
CURRENT_IMG=$(CURRENT_DIR)/live.$(IMG_FORMAT)
CURRENT_SWTPM=$(CURRENT_DIR)/swtpm
CURRENT_INSTALLER=$(CURRENT_DIR)/installer
INSTALLER_FIRMWARE_DIR=$(INSTALLER)/firmware
CURRENT_FIRMWARE_DIR=$(CURRENT_INSTALLER)/firmware
UBOOT_IMG=$(INSTALLER_FIRMWARE_DIR)/boot
# not every firmware file is used on every architecture
BIOS_IMG_amd64=$(INSTALLER_FIRMWARE_DIR)/OVMF.fd $(INSTALLER_FIRMWARE_DIR)/OVMF_CODE.fd $(INSTALLER_FIRMWARE_DIR)/OVMF_VARS.fd
BIOS_IMG_arm64=$(INSTALLER_FIRMWARE_DIR)/OVMF.fd $(INSTALLER_FIRMWARE_DIR)/OVMF_VARS.fd
BIOS_IMG_riscv64=$(INSTALLER_FIRMWARE_DIR)/OVMF.fd $(INSTALLER_FIRMWARE_DIR)/OVMF_CODE.fd $(INSTALLER_FIRMWARE_DIR)/OVMF_VARS.fd
BIOS_IMG=$(BIOS_IMG_$(ZARCH))
RUNME=$(BUILD_DIR)/runme.sh
BUILD_YML=$(BUILD_DIR)/build.yml
BUILD_VM=$(DIST)/build-vm.qcow2
BUILD_VM_CLOUD_INIT=$(DIST)/build-vm-ci.qcow2
ROOTFS=$(INSTALLER)/rootfs
ROOTFS_FULL_NAME=$(INSTALLER)/rootfs-$(ROOTFS_VERSION)
ROOTFS_COMPLETE=$(ROOTFS_FULL_NAME)-%-$(ZARCH).$(ROOTFS_FORMAT)
ROOTFS_IMG=$(ROOTFS).img
# ROOTFS_TAR is in BUILD_DIR, not installer, so it does not get installed
ROOTFS_TAR=$(BUILD_DIR)/rootfs.tar
CONFIG_IMG=$(INSTALLER)/config.img
INITRD_IMG=$(INSTALLER)/initrd.img
INSTALLER_TAR=$(BUILD_DIR)/installer.tar
INSTALLER_IMG=$(INSTALLER)/installer.img
PERSIST_IMG=$(INSTALLER)/persist.img
NETBOOT=$(BUILD_DIR)/netboot
IPXE_IMG=$(NETBOOT)/ipxe.efi
EFI_PART=$(INSTALLER)/EFI
BOOT_PART=$(INSTALLER)/boot
BSP_IMX_PART=$(INSTALLER)/bsp-imx
SBOM?=$(ROOTFS).spdx.json
SOURCES_DIR=$(BUILD_DIR)/sources
COLLECTED_SOURCES=$(SOURCES_DIR)/collected_sources.tar.gz
DEVICETREE_DTB_amd64=
DEVICETREE_DTB_arm64=$(DIST)/dtb/eve.dtb
DEVICETREE_DTB=$(DEVICETREE_DTB_$(ZARCH))
CONF_FILES=$(shell ls -d $(CONF_DIR)/*)
LIVE_PART_SPEC=efi conf imga
# parallels settings
# https://github.com/qemu/qemu/blob/595123df1d54ed8fbab9e1a73d5a58c5bb71058f/docs/interop/prl-xml.txt
# predefined GUID according link ^
PARALLELS_UUID={5fbaabe3-6958-40ff-92a7-860e329aab41}
PARALLELS_VM_NAME=EVE_Live
PARALLELS_CPUS=2 #num
PARALLELS_MEMORY=2048 #in megabytes
# VirtualBox settings
VB_VM_NAME=EVE_Live
VB_CPUS=2 #num
VB_MEMORY=2048 #in megabytes
# public cloud settings (only GCP is supported for now)
# note how GCP doesn't like dots so we replace them with -
CLOUD_IMG_NAME=$(subst .,-,live-$(FULL_VERSION))
CLOUD_PROJECT=-project lf-edge-eve
CLOUD_BUCKET=-bucket eve-live
CLOUD_INSTANCE=-zone us-west1-a -machine n1-standard-1
# qemu settings
QEMU_SYSTEM_arm64=qemu-system-aarch64
QEMU_SYSTEM_amd64=qemu-system-x86_64
QEMU_SYSTEM_riscv64=qemu-system-riscv64
QEMU_SYSTEM=$(QEMU_SYSTEM_$(ZARCH))
ifeq ($(NOACCEL),)
ACCEL=1
else
ACCEL=
endif
ifeq ($(UNAME_S)_$(ZARCH),Darwin_arm64)
QEMU_DEFAULT_MACHINE=virt,
endif
QEMU_ACCEL_Y_Darwin_amd64=-machine q35,accel=hvf,usb=off -cpu kvm64,kvmclock=off
QEMU_ACCEL_Y_Linux_amd64=-machine q35,accel=kvm,usb=off,dump-guest-core=off -cpu host,invtsc=on,kvmclock=off -machine kernel-irqchip=split -device intel-iommu,intremap=on,caching-mode=on,aw-bits=48
# -machine virt,gic_version=3
QEMU_ACCEL_Y_Darwin_arm64=-machine $(QEMU_DEFAULT_MACHINE)accel=hvf,usb=off -cpu host
QEMU_ACCEL_Y_Linux_arm64=-machine virt,accel=kvm,usb=off,dump-guest-core=off -cpu host
QEMU_ACCEL__$(UNAME_S)_arm64=-machine virt,virtualization=true -cpu cortex-a57
QEMU_ACCEL__$(UNAME_S)_amd64=-machine q35 -cpu SandyBridge
QEMU_ACCEL__$(UNAME_S)_riscv64=-machine virt -cpu rv64
QEMU_ACCEL:=$(QEMU_ACCEL_$(ACCEL:%=Y)_$(UNAME_S)_$(ZARCH))
QEMU_OPTS_NET1=192.168.1.0/24
QEMU_OPTS_NET1_FIRST_IP=192.168.1.10
QEMU_OPTS_NET2=192.168.2.0/24
QEMU_OPTS_NET2_FIRST_IP=192.168.2.10
QEMU_MEMORY?=4096
QEMU_EVE_SERIAL?=31415926
PFLASH_amd64=y
PFLASH=$(PFLASH_$(ZARCH))
QEMU_OPTS_BIOS_y=-drive if=pflash,format=raw,unit=0,readonly,file=$(CURRENT_FIRMWARE_DIR)/OVMF_CODE.fd -drive if=pflash,format=raw,unit=1,file=$(CURRENT_FIRMWARE_DIR)/OVMF_VARS.fd
QEMU_OPTS_BIOS_=-bios $(CURRENT_FIRMWARE_DIR)/OVMF.fd
QEMU_OPTS_BIOS=$(QEMU_OPTS_BIOS_$(PFLASH))
QEMU_TPM_DEVICE_amd64=tpm-tis
QEMU_TPM_DEVICE_arm64=tpm-tis-device
QEMU_TPM_DEVICE_riscv64=tpm-tis
QEMU_OPTS_TPM_Y_$(ZARCH)=-chardev socket,id=chrtpm,path=$(CURRENT_SWTPM)/swtpm-sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device $(QEMU_TPM_DEVICE_$(ZARCH)),tpmdev=tpm0
QEMU_OPTS_TPM=$(QEMU_OPTS_TPM_$(TPM:%=Y)_$(ZARCH))
QEMU_OPTS_amd64=-smbios type=1,serial=$(QEMU_EVE_SERIAL)
QEMU_OPTS_arm64=-smbios type=1,serial=$(QEMU_EVE_SERIAL) -drive file=fat:rw:$(dir $(DEVICETREE_DTB)),label=QEMU_DTB,format=vvfat
QEMU_OPTS_riscv64=-kernel $(UBOOT_IMG)/u-boot.bin -device virtio-blk,drive=uefi-disk
QEMU_OPTS_COMMON= -m $(QEMU_MEMORY) -smp 4 -display none $(QEMU_OPTS_BIOS) \
-serial mon:stdio \
-global ICH9-LPC.noreboot=false -watchdog-action reset \
-rtc base=utc,clock=rt \
-netdev user,id=eth0,net=$(QEMU_OPTS_NET1),dhcpstart=$(QEMU_OPTS_NET1_FIRST_IP),hostfwd=tcp::$(SSH_PORT)-:22$(QEMU_TFTP_OPTS) -device virtio-net-pci,netdev=eth0,romfile="" \
-netdev user,id=eth1,net=$(QEMU_OPTS_NET2),dhcpstart=$(QEMU_OPTS_NET2_FIRST_IP) -device virtio-net-pci,netdev=eth1,romfile="" \
-device nec-usb-xhci,id=xhci \
-qmp unix:$(CURDIR)/qmp.sock,server,wait=off
QEMU_OPTS_CONF_PART=$(shell [ -d "$(CONF_PART)" ] && echo '-drive file=fat:rw:$(CONF_PART),format=raw')
QEMU_OPTS=$(QEMU_OPTS_COMMON) $(QEMU_ACCEL) $(QEMU_OPTS_$(ZARCH)) $(QEMU_OPTS_CONF_PART) $(QEMU_OPTS_TPM)
# -device virtio-blk-device,drive=image -drive if=none,id=image,file=X
# -device virtio-net-device,netdev=user0 -netdev user,id=user0,hostfwd=tcp::1234-:22
GOOS=linux
CGO_ENABLED=1
GOBUILDER=eve-build-$(shell echo $(USER) | tr A-Z a-z)
# if proxy is set, use it when building docker builder
ifneq ($(HTTP_PROXY),)
DOCKER_HTTP_PROXY:=--build-arg http_proxy=$(HTTP_PROXY)
endif
ifneq ($(HTTPS_PROXY),)
DOCKER_HTTPS_PROXY:=--build-arg https_proxy=$(HTTPS_PROXY)
endif
ifneq ($(NO_PROXY),)
DOCKER_NO_PROXY:=--build-arg no_proxy=$(NO_PROXY)
endif
ifneq ($(ALL_PROXY),)
DOCKER_ALL_PROXY:=--build-arg all_proxy=$(ALL_PROXY)
endif
# use "make V=1" for verbose logging
DASH_V :=
QUIET := @
SET_X := :
ifeq ($(V),1)
DASH_V := -v
QUIET :=
SET_X := set -x
endif
DOCKER_GO = _() { $(SET_X); mkdir -p $(CURDIR)/.go/src/$${3:-dummy} ; mkdir -p $(CURDIR)/.go/bin ; \
docker_go_line="docker run $$DOCKER_GO_ARGS -i --rm -u $(USER) -w /go/src/$${3:-dummy} \
-v $(CURDIR)/.go:/go:z -v $$2:/go/src/$${3:-dummy}:z -v $${4:-$(CURDIR)/.go/bin}:/go/bin:z -v $(CURDIR)/:/eve:z -v $${HOME}:/home/$(USER):z \
-e GOOS -e GOARCH -e CGO_ENABLED -e BUILD=local $(GOBUILDER) bash --noprofile --norc -c" ; \
verbose=$(V) ;\
verbose=$${verbose:-0} ;\
[ $$verbose -ge 1 ] && echo $$docker_go_line "\"$$1\""; \
$$docker_go_line "$$1" ; } ; _
PARSE_PKGS=$(if $(strip $(EVE_HASH)),EVE_HASH=)$(EVE_HASH) DOCKER_ARCH_TAG=$(DOCKER_ARCH_TAG) KERNEL_TAG=$(KERNEL_TAG) ./tools/parse-pkgs.sh
LINUXKIT=$(BUILDTOOLS_BIN)/linuxkit
# linuxkit version. This **must** be a published semver version so it can be downloaded already compiled from
# the release page at https://github.com/linuxkit/linuxkit/releases
LINUXKIT_VERSION=v1.5.2
LINUXKIT_SOURCE=https://github.com/linuxkit/linuxkit
LINUXKIT_OPTS=$(if $(strip $(EVE_HASH)),--hash) $(EVE_HASH) $(if $(strip $(EVE_REL)),--release) $(EVE_REL)
LINUXKIT_PKG_TARGET=build
ifdef LIVE_FAST
# Check the makerootfs.sh and the linuxkit tool invocation, the --input-tar
# parameter specifically. This will create a new tar based on the old one
# (already generated), which speeds tar generation up a bit.
UPDATE_TAR=-u
endif
RESCAN_DEPS=FORCE
# set FORCE_BUILD to --force to enforce rebuild
FORCE_BUILD=
# ROOTFS_DEPS enforces the scan of all rootfs image dependencies
ifdef ROOTFS_DEPS
ROOTFS_GET_DEPS=-r
else
ROOTFS_GET_DEPS=
endif
# for the go build sources
GOSOURCES=$(BUILDTOOLS_BIN)/go-sources-and-licenses
GOSOURCES_VERSION=6047a068b2702ed2687cd13dcb7eaa2542d20344
GOSOURCES_SOURCE=github.com/deitch/go-sources-and-licenses
# for the compare sbom and collecte sources
COMPARESOURCES=$(BUILDTOOLS_BIN)/compare-sbom-sources
COMPARE_SOURCE=./tools/compare-sbom-sources
# tool for scan docker package dependencies
GET_DEPS_DIR=./tools/get-deps
GET_DEPS=./tools/get-deps/get-deps
DOCKERFILE_FROM_CHECKER_DIR=./tools/dockerfile-from-checker/
DOCKERFILE_FROM_CHECKER=$(DOCKERFILE_FROM_CHECKER_DIR)/dockerfile-from-checker
SYFT_VERSION:=v0.85.0
SYFT_IMAGE:=docker.io/anchore/syft:$(SYFT_VERSION)
# we use the following block to assign correct tag to the Docker registry artifact
ifeq ($(LINUXKIT_PKG_TARGET),push)
# only builds from master branch are allowed to be called snapshots
# everything else gets tagged with a branch name itself UNLESS
# we're building off of a annotated tag
EVE_REL_$(REPO_BRANCH)_$(REPO_TAG):=$(REPO_TAG)
EVE_REL_$(REPO_BRANCH)_snapshot:=$(REPO_BRANCH)
EVE_REL_master_snapshot:=snapshot
EVE_REL:=$(EVE_REL_$(REPO_BRANCH)_$(REPO_TAG))
# the only time we rebuild everything from scratch is when we're building 'latest' release
# in order to achieve that we have to force EVE_HASH to be the release version
ifeq ($(shell [ "`git tag | grep -E '[0-9]*\.[0-9]*\.[0-9]*' | sort -t. -n -k1,1 -k2,2 -k3,3 | tail -1`" = $(REPO_TAG) ] && echo latest),latest)
EVE_HASH:=$(REPO_TAG)
EVE_REL:=latest
endif
endif
# The rootfs partition size is set to 512MB after 10.2.0 release (see commit 719b4d516)
# Before 10.2.0 it was 300MB. We must maintain compatibility with older versions so rootfs size cannot exceed 300MB.
# kubevirt and nvidia are not affected by this limitation because there no installation of kubevirt prior to 10.2.0
# Nethertheless lets check for ROOTFS_MAXSIZE_MB not exceeding 450MB for kubevirt and ARM and 270MB for x86_64
# That helps in catching image size increases earlier than at later stage.
# We are currently filtering out a few packages from bulk builds since they are not getting published in Docker HUB
ifeq ($(HV),kubevirt)
PKGS_$(ZARCH)=$(shell find pkg -maxdepth 1 -type d | grep -Ev "eve|alpine|sources$$")
ROOTFS_MAXSIZE_MB=450
else
#kube container will not be in non-kubevirt builds
PKGS_$(ZARCH)=$(shell find pkg -maxdepth 1 -type d | grep -Ev "eve|alpine|sources|kube|external-boot-image$$")
# nvidia platform requires more space
ifeq ($(PLATFORM),nvidia)
ROOTFS_MAXSIZE_MB=450
else
ROOTFS_MAXSIZE_MB=270
endif
endif
PKGS_riscv64=pkg/ipxe pkg/mkconf pkg/mkimage-iso-efi pkg/grub \
pkg/mkimage-raw-efi pkg/uefi pkg/u-boot pkg/cross-compilers \
pkg/debug pkg/dom0-ztools pkg/gpt-tools pkg/storage-init pkg/mkrootfs-squash \
pkg/bsp-imx pkg/optee-os pkg/recovertpm pkg/bpftrace
# alpine-base and alpine must be the first packages to build
PKGS=pkg/alpine $(PKGS_$(ZARCH))
# eve-alpine-base is bootstrap image for eve-alpine
# to update please see https://github.com/lf-edge/eve/blob/master/docs/BUILD.md#how-to-update-eve-alpine-package
# if you want to bootstrap eve-alpine again, uncomment the line below
# PKGS:=pkg/alpine-base $(PKGS)
# these are the packages that, when built, also need to be loaded into docker
# if you need a pkg to be loaded into docker, in addition to the lkt cache, add it here
PKGS_DOCKER_LOAD=mkconf mkimage-iso-efi mkimage-raw-efi mkrootfs-ext4 mkrootfs-squash
# these packages should exists for HOSTARCH as well as for ZARCH
# alpine-base, alpine and cross-compilers are dependencies for others
PKGS_HOSTARCH=alpine-base alpine cross-compilers $(PKGS_DOCKER_LOAD)
# Package dependencies auto-generated by the build system
-include pkg-deps.mk
# Top-level targets
all: help
$(QUIET): $@: Succeeded
# just reports the version, without appending qualifies like HVM or such
version:
@echo $(ROOTFS_VERSION)
# makes a link to current
current: $(CURRENT_DIR)
$(CURRENT_DIR): $(BUILD_DIR)
@rm -f $@ && ln -s $(BUILD_DIR) $@
# reports the image version that current points to
# we explicitly do *not* use $(BUILD_DIR), because that is recalculated each time, and it might have changed
# since we last built. We just want to know what current is pointing to *now*, not what it might point to
# if we ran a new build.
currentversion:
#echo $(shell readlink $(CURRENT) | sed -E 's/rootfs-(.*)\.[^.]*$/\1/')
@cat $(CURRENT_DIR)/installer/eve_version
.PHONY: currentversion linuxkit pkg/kernel
test: $(LINUXKIT) test-images-patches | $(DIST)
@echo Running tests on $(GOMODULE)
make -C pkg/pillar test
cp pkg/pillar/results.json $(DIST)/
cp pkg/pillar/results.xml $(DIST)/
make -C eve-tools/bpftrace-compiler test
$(QUIET): $@: Succeeded
test-profiling:
make -C pkg/pillar test-profiling
# wrap command into DOCKER_GO and propagate it to the pillar's Makefile
# for example make pillar-fmt will run docker container based on
# build-tools/src/scripts/Dockerfile
# mount pkg/pillar into it
# and will run make fmt
pillar-%: $(GOBUILDER) | $(DIST)
@echo Running make $* on pillar
$(QUIET)$(DOCKER_GO) "make $*" $(GOTREE)
$(QUIET): $@: Succeeded
clean:
rm -rf $(DIST) images/out pkg-deps.mk
$(DOCKERFILE_FROM_CHECKER): $(DOCKERFILE_FROM_CHECKER_DIR)/*.go $(DOCKERFILE_FROM_CHECKER_DIR)/go.*
make -C $(DOCKERFILE_FROM_CHECKER_DIR)
# this next section checks that the FROM hashes for any image in any dockerfile anywhere here are consistent.
# For example, one Dockerfile has foo:abc and the next has foo:def, it will flag them.
# These are the packages that we are ignoring for now
IGNORE_DOCKERFILE_HASHES_PKGS=alpine
IGNORE_DOCKERFILE_HASHES_EVE_TOOLS=bpftrace-compiler
IGNORE_DOCKERFILE_HASHES_PKGS_ARGS=$(foreach pkg,$(IGNORE_DOCKERFILE_HASHES_PKGS),-i pkg/$(pkg)/Dockerfile)
IGNORE_DOCKERFILE_HASHES_EVE_TOOLS_ARGS=$(foreach tool,$(IGNORE_DOCKERFILE_HASHES_EVE_TOOLS),$(addprefix -i ,$(shell find eve-tools/$(tool) -path '*/vendor' -prune -o -name Dockerfile -print)))
.PHONY: check-docker-hashes-consistency
check-docker-hashes-consistency: $(DOCKERFILE_FROM_CHECKER)
@echo "Checking Dockerfiles for inconsistencies"
$(DOCKERFILE_FROM_CHECKER) ./ $(IGNORE_DOCKERFILE_HASHES_PKGS_ARGS) $(IGNORE_DOCKERFILE_HASHES_EVE_TOOLS_ARGS)
yetus:
@echo Running yetus
mkdir -p yetus-output
docker run --rm -v $(CURDIR):/src:delegated,z ghcr.io/apache/yetus:0.15.0 \
--basedir=/src \
--test-parallel=true \
--dirty-workspace \
--empty-patch \
--plugins=all \
--patch-dir=/src/yetus-output
mini-yetus:
@echo Running mini-yetus
./tools/mini-yetus.sh $(if $(MYETUS_VERBOSE),-f) $(if $(MYETUS_SBRANCH),-s $(MYETUS_SBRANCH)) $(if $(MYETUS_DBRANCH),-d $(MYETUS_DBRANCH))
build-tools: $(LINUXKIT)
@echo Done building $<
$(BUILD_VM_CLOUD_INIT): build-tools/src/scripts/cloud-init.in | $(DIST)
@if [ -z "$(BUILD_VM_SSH_PUB_KEY)" ] || [ -z "$(BUILD_VM_GH_TOKEN)" ]; then \
echo "Must be run as: make BUILD_VM_SSH_PUB_KEY=XXX BUILD_VM_GH_TOKEN=YYY $@" && exit 1 ;\
fi
$(QUIET)sed -e 's#@ZARCH@#$(subst amd64,x64,$(ZARCH))#' -e 's#@SSH_PUB_KEY@#$(BUILD_VM_SSH_PUB_KEY)#g' \
-e 's#@GH_TOKEN@#$(BUILD_VM_GH_TOKEN)#g' < $< | docker run -i alpine:edge sh -c \
'apk add cloud-utils > /dev/null 2>&1 && cloud-localds --disk-format qcow2 _ - && cat _' > $@
$(BUILD_VM).orig: | $(DIST)
@curl -L $(BUILD_VM_SRC) > $@
$(BUILD_VM): $(BUILD_VM_CLOUD_INIT) $(BUILD_VM).orig $(DEVICETREE_DTB) $(BIOS_IMG) $(SWTPM) | $(DIST)
# currently a fulle EVE build *almost* fits into 40Gb -- we need twice as much in a VM
qemu-img resize [email protected] 100G
$(QEMU_SYSTEM) $(QEMU_OPTS) -drive format=qcow2,[email protected] -drive format=qcow2,file=$<
mv [email protected] $@
$(DEVICETREE_DTB): $(BIOS_IMG) | $(DIST)
mkdir $(dir $@) 2>/dev/null || :
# start swtpm to generate dtb
$(MAKE) $(SWTPM)
$(QEMU_SYSTEM) $(QEMU_OPTS) -machine $(QEMU_DEFAULT_MACHINE)dumpdtb=$@
$(QUIET): $@: Succeeded
$(EFI_PART): PKG=grub
$(BOOT_PART): PKG=u-boot
$(INITRD_IMG): PKG=mkimage-raw-efi
$(IPXE_IMG): PKG=ipxe
$(BIOS_IMG): PKG=uefi
$(UBOOT_IMG): PKG=u-boot
$(BSP_IMX_PART): PKG=bsp-imx
$(EFI_PART) $(BOOT_PART) $(INITRD_IMG) $(IPXE_IMG) $(BIOS_IMG) $(UBOOT_IMG) $(BSP_IMX_PART): $(LINUXKIT) | $(INSTALLER)
mkdir -p $(dir $@)
$(LINUXKIT) pkg build --pull --platforms linux/$(ZARCH) pkg/$(PKG) # running linuxkit pkg build _without_ force ensures that we either pull it down or build it.
cd $(dir $@) && $(LINUXKIT) cache export --arch $(DOCKER_ARCH_TAG) --format filesystem --outfile - $(shell $(LINUXKIT) pkg show-tag pkg/$(PKG)) | tar xvf - $(notdir $@)
$(QUIET): $@: Succeeded
# run swtpm if TPM flag defined
# to run it please ensure that https://github.com/stefanberger/swtpm package built/installed in your system
# we use --terminate flag, so swtpm will terminate after qemu disconnection
SWTPM_:
SWTPM_Y:
mkdir -p $(CURRENT_SWTPM)
swtpm socket --daemon --terminate --tpmstate dir=$(CURRENT_SWTPM) --ctrl type=unixio,path=$(CURRENT_SWTPM)/swtpm-sock --log file=$(CURRENT_SWTPM)/swtpm.log,level=20 --pid file=$(CURRENT_SWTPM)/swtpm.pid --tpm2
SWTPM:=SWTPM_$(TPM:%=Y)
# patch /conf/grub.cfg for developer's builds to enable getty
GETTY:
echo "Enabling GETTY in grub.cfg"
if [ ! -f $(CONF_DIR)/grub.cfg ]; then\
cp $(CONF_DIR)/grub.cfg.tmpl $(CONF_DIR)/grub.cfg;\
fi
# run-installer
#
# This creates an image equivalent to live.img (called target.img)
# through the installer. It's the long road to live.img. Good for
# testing.
#
run-installer-iso: $(BIOS_IMG) $(DEVICETREE_DTB) $(SWTPM) GETTY
qemu-img create -f ${IMG_FORMAT} $(TARGET_IMG) ${MEDIA_SIZE}M
$(QEMU_SYSTEM) -drive file=$(TARGET_IMG),format=$(IMG_FORMAT) -cdrom $(INSTALLER).iso -boot d $(QEMU_OPTS)
run-installer-raw: $(BIOS_IMG) $(DEVICETREE_DTB) $(SWTPM) GETTY
qemu-img create -f ${IMG_FORMAT} $(TARGET_IMG) ${MEDIA_SIZE}M
$(QEMU_SYSTEM) -drive file=$(TARGET_IMG),format=$(IMG_FORMAT) -drive file=$(INSTALLER).raw,format=raw $(QEMU_OPTS)
run-installer-net: QEMU_TFTP_OPTS=,tftp=$(dir $(IPXE_IMG)),bootfile=$(notdir $(IPXE_IMG))
run-installer-net: $(BIOS_IMG) $(IPXE_IMG) $(DEVICETREE_DTB) $(SWTPM) GETTY
tar -C $(NETBOOT) -xvf $(INSTALLER).net || :
qemu-img create -f ${IMG_FORMAT} $(TARGET_IMG) ${MEDIA_SIZE}M
$(QEMU_SYSTEM) -drive file=$(TARGET_IMG),format=$(IMG_FORMAT) $(QEMU_OPTS)
# run MUST NOT change the current dir; it depends on the output being correct from a previous build
run-live run: $(BIOS_IMG) $(DEVICETREE_DTB) $(SWTPM) GETTY
$(QEMU_SYSTEM) $(QEMU_OPTS) -drive file=$(CURRENT_IMG),format=$(IMG_FORMAT),id=uefi-disk
run-target: $(BIOS_IMG) $(DEVICETREE_DTB) $(SWTPM) GETTY
$(QEMU_SYSTEM) $(QEMU_OPTS) -drive file=$(TARGET_IMG),format=$(IMG_FORMAT)
run-rootfs: $(BIOS_IMG) $(UBOOT_IMG) $(EFI_PART) $(DEVICETREE_DTB) $(SWTPM) GETTY
(echo 'set devicetree="(hd0,msdos1)/eve.dtb"' ; echo 'set rootfs_root=/dev/vdb' ; echo 'set root=hd1' ; echo 'export rootfs_root' ; echo 'export devicetree' ; echo 'configfile /EFI/BOOT/grub.cfg' ) > $(EFI_PART)/BOOT/grub.cfg
$(QEMU_SYSTEM) $(QEMU_OPTS) -drive file=$(ROOTFS_IMG),format=raw -drive file=fat:rw:$(EFI_PART)/..,label=CONFIG,id=uefi-disk,format=vvfat
$(QUIET): $@: Succeeded
run-grub: $(BIOS_IMG) $(UBOOT_IMG) $(EFI_PART) $(DEVICETREE_DTB) $(SWTPM) GETTY
[ -f $(EFI_PART)/BOOT/grub.cfg ] && mv $(EFI_PART)/BOOT/grub.cfg $(EFI_PART)/BOOT/grub.cfg.$(notdir $(shell mktemp))
$(QEMU_SYSTEM) $(QEMU_OPTS) -drive format=vvfat,id=uefi-disk,label=EVE,file=fat:rw:$(EFI_PART)/..
$(QUIET): $@: Succeeded
run-compose: images/out/version.yml
# we regenerate this on every run, in case things changed
$(PARSE_PKGS) > tmp/images
docker-compose -f docker-compose.yml run storage-init sh -c 'rm -rf /run/* /config/* ; cp -Lr /conf/* /config/ ; echo IMGA > /run/eve.id'
docker-compose -f docker-compose.yml --env-file tmp/images up
run-proxy:
ssh $(SSH_PROXY) -N -i $(SSH_KEY) -p $(SSH_PORT) -o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null root@localhost &
run-build-vm: $(BIOS_IMG) $(DEVICETREE_DTB)
$(QEMU_SYSTEM) $(QEMU_OPTS) -drive format=qcow2,file=$(BUILD_VM)
run-live-vb:
@[ -f "$(LIVE).vdi" ] || { echo "Please run: make live-vdi"; exit 1; }
VBoxManage list vms | grep $(VB_VM_NAME) >/dev/null && VBoxManage controlvm $(VB_VM_NAME) acpipowerbutton & sleep 10 & VBoxManage unregistervm $(VB_VM_NAME) --delete || echo "No VMs with $(VB_VM_NAME) name"
VBoxManage createvm --name $(VB_VM_NAME) --register --basefolder $(DIST)/
VBoxManage modifyvm $(VB_VM_NAME) --cpus $(VB_CPUS) --memory $(VB_MEMORY) --vram 16 --nested-hw-virt on --ostype Ubuntu_64 --mouse usbtablet --graphicscontroller vmsvga --boot1 disk --boot2 net
VBoxManage storagectl $(VB_VM_NAME) --name "SATA Controller" --add SATA --controller IntelAhci --bootable on --hostiocache on
VBoxManage storageattach $(VB_VM_NAME) --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium $(LIVE).vdi
VBoxManage modifyvm $(VB_VM_NAME) --nic1 natnetwork --nat-network1 natnet1 --cableconnected1 on --natpf1 ssh,tcp,,$(SSH_PORT),,22
VBoxManage modifyvm $(VB_VM_NAME) --nic2 natnetwork --nat-network2 natnet2 --cableconnected2 on
VBoxManage startvm $(VB_VM_NAME)
run-live-parallels:
@[ -d "$(LIVE).parallels" ] || { echo "Please run: make live-parallels"; exit 1; }
@prlctl list -a | grep $(PARALLELS_VM_NAME) | grep "invalid" >/dev/null && prlctl unregister $(PARALLELS_VM_NAME) || echo "No invalid $(PARALLELS_VM_NAME) VM"
@if prlctl list --all | grep "$(PARALLELS_VM_NAME)"; then \
prlctl stop $(PARALLELS_VM_NAME) --kill; \
prlctl set $(PARALLELS_VM_NAME) --device-set hdd0 --image $(LIVE).parallels --nested-virt on --adaptive-hypervisor on --hypervisor-type parallels --cpus $(PARALLELS_CPUS) --memsize $(PARALLELS_MEMORY); \
else \
prlctl create $(PARALLELS_VM_NAME) --distribution ubuntu --no-hdd --dst $(DIST)/ ; \
prlctl set $(PARALLELS_VM_NAME) --device-add hdd --image $(LIVE).parallels --nested-virt on --adaptive-hypervisor on --hypervisor-type parallels --cpus $(PARALLELS_CPUS) --memsize $(PARALLELS_MEMORY); \
prlctl set $(PARALLELS_VM_NAME) --device-del net0 ; \
prlctl set $(PARALLELS_VM_NAME) --device-add net --type shared --adapter-type virtio --ipadd 192.168.1.0/24 --dhcp yes ; \
prlctl set $(PARALLELS_VM_NAME) --device-add net --type shared --adapter-type virtio --ipadd 192.168.2.0/24 --dhcp yes ; \
prlsrvctl net set Shared --nat-tcp-add ssh,$(SSH_PORT),$(PARALLELS_VM_NAME),22 ; \
prlctl start $(PARALLELS_VM_NAME) ; \
fi
# alternatively (and if you want greater control) you can replace the first command with
# gcloud auth activate-service-account --key-file=-
# gcloud compute images create $(CLOUD_IMG_NAME) --project=lf-edge-eve
# --source-uri=https://storage.googleapis.com/eve-live/live.img.tar.gz
# --licenses="https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx"
run-live-gcp: $(LINUXKIT)
if gcloud compute images list -$(CLOUD_PROJECT) --filter="name=$(CLOUD_IMG_NAME)" 2>&1 | grep -q 'Listed 0 items'; then \
$^ push gcp -nested-virt -img-name $(CLOUD_IMG_NAME) $(CLOUD_PROJECT) $(CLOUD_BUCKET) $(LIVE).img.tar.gz ;\
fi
$^ run gcp $(CLOUD_PROJECT) $(CLOUD_INSTANCE) $(CLOUD_IMG_NAME)
live-gcp-upload: $(LINUXKIT)
if gcloud compute images list -$(CLOUD_PROJECT) --filter="name=$(CLOUD_IMG_NAME)" 2>&1 | grep -q 'Listed 0 items'; then \
$^ push gcp -nested-virt -img-name $(CLOUD_IMG_NAME) $(CLOUD_PROJECT) $(CLOUD_BUCKET) $(LIVE).img.tar.gz ;\
echo "Uploaded $(CLOUD_IMG_NAME)"; \
else \
echo "Image $(CLOUD_IMG_NAME) already exists in GCP" ;\
fi
# ensure the dist directory exists
$(DIST) $(BUILD_DIR) $(INSTALLER_FIRMWARE_DIR):
mkdir -p $@
# ensure the installer dir exists, and save the version in the directory
# we need to save the version including hypervisor and architecture
$(INSTALLER):
@mkdir -p $@
@cp -r pkg/eve/installer/* $@
# sample output 0.0.0-HEAD-a437e8e4-xen-amd64
@echo $(FULL_VERSION) > $(VERSION_FILE)
$(NETBOOT):
@mkdir -p $@
# convenience targets - so you can do `make config` instead of `make dist/config.img`, and `make installer` instead of `make dist/amd64/installer.img
linuxkit: $(LINUXKIT)
build-vm: $(BUILD_VM)
initrd: $(INITRD_IMG)
config: $(CONFIG_IMG) ; $(QUIET): "$@: Succeeded, CONFIG_IMG=$(CONFIG_IMG)"
ssh-key: $(SSH_KEY)
rootfs: $(ROOTFS_TAR) $(ROOTFS_IMG) current
rootfs.tar: $(ROOTFS_TAR)
rootfstar: $(ROOTFS_TAR)
sbom: $(SBOM)
live: $(LIVE_IMG) $(BIOS_IMG) current ; $(QUIET): "$@: Succeeded, LIVE_IMG=$(LIVE_IMG)"
live-%: $(LIVE).% ; $(QUIET): "$@: Succeeded, LIVE=$(LIVE)"
installer: $(INSTALLER).raw current
installer.tar: $(INSTALLER_TAR)
installertar: $(INSTALLER_TAR)
installer-img: $(INSTALLER_IMG)
installer-%: $(INSTALLER).% current ; @echo "$@: Succeeded, INSTALLER_IMG=$<"
collected_sources: $(COLLECTED_SOURCES)
gosources: $(GOSOURCES)
$(SSH_KEY):
rm -f $@*
ssh-keygen -P "" -f $@
mv [email protected] $(CONF_DIR)/authorized_keys
$(CONFIG_IMG): $(CONF_FILES) | $(INSTALLER)
./tools/makeconfig.sh $@ "$(ROOTFS_VERSION)" $(CONF_FILES)
$(QUIET): $@: Succeeded
$(PERSIST_IMG): | $(INSTALLER)
# 1M of zeroes should be enough to trigger filesystem wipe on first boot
dd if=/dev/zero bs=1048576 count=1 >> $@
$(QUIET): $@: Succeeded
$(ROOTFS)-%.img: $(ROOTFS_IMG)
@rm -f $@ && ln -s $(notdir $<) $@
$(QUIET): $@: Succeeded
$(ROOTFS_TAR): images/out/rootfs-$(HV)-$(PLATFORM).yml | $(INSTALLER)
$(QUIET): $@: Begin
./tools/makerootfs.sh tar $(UPDATE_TAR) -y $< -t $@ -d $(INSTALLER) -a $(ZARCH)
$(QUIET): $@: Succeeded
ifdef KERNEL_IMAGE
# Consider this as a cry from the heart: enormous amount of time is
# wasted during kernel rebuild on every small testing change. Now any
# kernel image can be used by providing path to a file. You heard it
# right: path-to-a-file. No docker. Yay!
$(eval KIMAGE = $$(realpath $(KERNEL_IMAGE)))
@echo "Replace kernel image in \"$@\" with \"$(KIMAGE)\""
# Delete /boot/kernel kernel image
tar --delete -f "$@" boot/kernel
# Append new kernel image and rename
tar -P -u --transform="flags=r;s|$(KIMAGE)|/boot/kernel|" -f "$@" "$(KIMAGE)"
endif
$(INSTALLER_TAR): images/out/installer-$(HV)-$(PLATFORM).yml $(ROOTFS_IMG) $(PERSIST_IMG) $(CONFIG_IMG) | $(INSTALLER)
$(QUIET): $@: Begin
./tools/makerootfs.sh tar $(UPDATE_TAR) -y $< -t $@ -d $(INSTALLER) -a $(ZARCH)
$(QUIET): $@: Succeeded
ifdef LIVE_UPDATE
# Don't regenerate the whole image if tar was changed, but
# do generate if does not exist. qcow2 target will handle
# the rest
$(ROOTFS_IMG): | $(ROOTFS_TAR) $(INSTALLER)
else
$(ROOTFS_IMG): $(ROOTFS_TAR) | $(INSTALLER)
endif
$(QUIET): $@: Begin
./tools/makerootfs.sh imagefromtar -t $(ROOTFS_TAR) -i $@ -f $(ROOTFS_FORMAT) -a $(ZARCH)
@echo "size of $@ is $$(wc -c < "$@")B"
ifeq ($(ROOTFS_FORMAT),squash)
@[ $$(wc -c < "$@") -gt $$(( $(ROOTFS_MAXSIZE_MB) * 1024 * 1024 )) ] && \
echo "ERROR: size of $@ is greater than $(ROOTFS_MAXSIZE_MB)MB (bigger than allocated partition)" && exit 1 || :
endif
$(QUIET): $@: Succeeded
$(GET_DEPS):
$(MAKE) -C $(GET_DEPS_DIR) GOOS=$(LOCAL_GOOS)
sbom_info:
@echo "$(SBOM)"
collected_sources_info:
@echo "$(COLLECTED_SOURCES)"
$(SBOM): $(ROOTFS_TAR) | $(INSTALLER)
$(QUIET): $@: Begin
$(eval TMP_ROOTDIR := $(shell mktemp -d))
# this is a bit of a hack, but we need to extract the rootfs tar to a directory, and it fails if
# we try to extract character devices, block devices or pipes, so we just exclude the dir.
# when syft supports reading straight from a tar archive with duplicate entries,
# this all can go away, and we can read the rootfs.tar
# see https://github.com/anchore/syft/issues/1400
#
# the ROOTFS_TAR includes extended PAX headers, which GNU tar does not support.
# It does not break, but logs two lines of warnings for each file, which is a lot.
# For BSD tar, no need to do anything; for GNU tar, need to add `--warning=no-unknown-keyword`
$(eval TAR_OPTS = $(shell tar --version | grep -qi 'GNU tar' && echo --warning=no-unknown-keyword || echo))
tar $(TAR_OPTS) -xf $< -C $(TMP_ROOTDIR) --exclude "dev/*"
docker run -v $(TMP_ROOTDIR):/rootdir:ro -v $(CURDIR)/.syft.yaml:/syft.yaml:ro $(SYFT_IMAGE) -c /syft.yaml --base-path /rootdir /rootdir > $@
rm -rf $(TMP_ROOTDIR)
$(QUIET): $@: Succeeded
$(GOSOURCES):
$(QUIET): $@: Begin
$(shell GOBIN=$(BUILDTOOLS_BIN) GO111MODULE=on CGO_ENABLED=0 go install $(GOSOURCES_SOURCE)@$(GOSOURCES_VERSION))
@echo Done building packages
$(QUIET): $@: Succeeded
# ensure the installer dir exists, and save the version in the directory
$(SOURCES_DIR):
@mkdir -p $@
$(COLLECTED_SOURCES): $(ROOTFS_TAR) $(GOSOURCES)| $(INSTALLER) $(SOURCES_DIR)
$(QUIET): $@: Begin
bash tools/collect-sources.sh $< $(CURDIR) $@
$(QUIET): $@: Succeeded
$(COMPARESOURCES):
$(QUIET): $@: Begin
cd $(COMPARE_SOURCE) && GOOS=$(LOCAL_GOOS) CGO_ENABLED=0 go build -o $(COMPARESOURCES)
@echo Done building packages
$(QUIET): $@: Succeeded
compare_sbom_collected_sources: $(COLLECTED_SOURCES) $(SBOM) | $(COMPARESOURCES)
$(QUIET): $@: Begin
$(COMPARESOURCES) $(COLLECTED_SOURCES):./collected_sources_manifest.csv $(SBOM)
@echo Done comparing the sbom and collected sources manifest file
$(QUIET): $@: Succeeded
publish_sources: $(COLLECTED_SOURCES)
$(QUIET): $@: Begin
cp pkg/sources/* $(SOURCES_DIR)
$(LINUXKIT) $(DASH_V) pkg $(LINUXKIT_PKG_TARGET) --platforms linux/$(ZARCH) --hash-path $(CURDIR) --hash $(ROOTFS_VERSION)-$(HV) --docker $(if $(strip $(EVE_REL)),--release) $(EVE_REL)$(if $(strip $(EVE_REL)),-$(HV)) $(SOURCES_DIR) $|
$(QUIET)if [ -n "$(EVE_REL)" ] && [ $(HV) = $(HV_DEFAULT) ]; then \
$(LINUXKIT) $(DASH_V) pkg $(LINUXKIT_PKG_TARGET) --platforms linux/$(ZARCH) --hash-path $(CURDIR) --hash $(EVE_REL)-$(HV) --docker --release $(EVE_REL) $(SOURCES_DIR) $| ;\
fi
$(QUIET): $@: Succeeded
$(LIVE).raw: $(BOOT_PART) $(EFI_PART) $(ROOTFS_IMG) $(CONFIG_IMG) $(PERSIST_IMG) $(BSP_IMX_PART) | $(INSTALLER)
./tools/prepare-platform.sh "$(PLATFORM)" "$(BUILD_DIR)" "$(INSTALLER)" || :
./tools/makeflash.sh "mkimage-raw-efi" -C $| $@ $(LIVE_PART_SPEC)
$(QUIET): $@: Succeeded
$(INSTALLER_IMG): $(INSTALLER_TAR) | $(INSTALLER)
$(QUIET): $@: Begin
./tools/makerootfs.sh imagefromtar -t $(INSTALLER_TAR) -i $@ -f $(ROOTFS_FORMAT) -a $(ZARCH)
$(QUIET): $@: Succeeded
$(INSTALLER).raw: $(INSTALLER_IMG) $(EFI_PART) $(BOOT_PART) $(CONFIG_IMG) $(BSP_IMX_PART) | $(INSTALLER)
./tools/prepare-platform.sh "$(PLATFORM)" "$(BUILD_DIR)" "$(INSTALLER)" || :
./tools/makeflash.sh "mkimage-raw-efi" -C $| $@ "efi conf_win installer inventory_win"
$(QUIET): $@: Succeeded
$(INSTALLER).iso: $(INSTALLER_TAR) $(BSP_IMX_PART) | $(INSTALLER)
./tools/makeiso.sh $< $@ installer
$(QUIET): $@: Succeeded
$(INSTALLER).net: $(INSTALLER).iso $(EFI_PART) $(INITRD_IMG) $(CONFIG_IMG) | $(INSTALLER)
./tools/makenet.sh $| $< $@
$(QUIET): $@: Succeeded
$(LIVE).vdi: $(LIVE).raw
qemu-img resize -f raw $< ${MEDIA_SIZE}M
qemu-img convert -O vdi $< $@
$(LIVE).parallels: $(LIVE).raw
rm -rf $@; mkdir $@
qemu-img resize -f raw $< ${MEDIA_SIZE}M
qemu-img convert -O parallels $< $@/live.0.$(PARALLELS_UUID).hds
qemu-img info -f parallels --output json $(LIVE).parallels/live.0.$(PARALLELS_UUID).hds | jq --raw-output '.["virtual-size"]' | xargs ./tools/parallels_disk.sh $(LIVE) $(PARALLELS_UUID)
# top-level linuxkit packages targets, note the one enforcing ordering between packages
pkgs: RESCAN_DEPS=
pkgs: build-tools $(PKGS)
@echo Done building packages
# No-op target for get-deps which looks at
# external-boot-image and sees a dep for eve-kernel
# and attempts to build pkg/kernel, which is in
# lf-edge/eve-kernel and not built here.
pkg/kernel:
$(QUIET): $@: No-op pkg/kernel
pkg/external-boot-image/build.yml: pkg/external-boot-image/build.yml.in
$(QUIET)tools/compose-external-boot-image-yml.sh $< $@ $(shell echo ${KERNEL_TAG} | cut -d':' -f2) $(shell $(LINUXKIT) pkg show-tag pkg/xen-tools | cut -d':' -f2)
eve-external-boot-image: pkg/external-boot-image/build.yml
pkg/kube/external-boot-image.tar: pkg/external-boot-image
$(MAKE) cache-export IMAGE=$(shell $(LINUXKIT) pkg show-tag pkg/external-boot-image) OUTFILE=pkg/kube/external-boot-image.tar
rm -f pkg/external-boot-image/build.yml
pkg/kube: pkg/kube/external-boot-image.tar eve-kube
$(QUIET): $@: Succeeded
pkg/pillar: pkg/dnsmasq pkg/gpt-tools pkg/dom0-ztools eve-pillar
$(QUIET): $@: Succeeded
pkg/xen-tools: pkg/uefi eve-xen-tools
$(QUIET): $@: Succeeded
pkg/%: eve-% FORCE
$(QUIET): $@: Succeeded
$(RUNME) $(BUILD_YML):
cp pkg/eve/$(@F) $@
EVE_ARTIFACTS=$(BIOS_IMG) $(EFI_PART) $(CONFIG_IMG) $(PERSIST_IMG) $(INITRD_IMG) $(ROOTFS_IMG) $(INSTALLER_IMG) $(SBOM) $(BSP_IMX_PART) fullname-rootfs $(BOOT_PART)
eve: $(INSTALLER) $(EVE_ARTIFACTS) current $(RUNME) $(BUILD_YML) | $(BUILD_DIR)
$(QUIET): "$@: Begin: EVE_REL=$(EVE_REL), HV=$(HV), LINUXKIT_PKG_TARGET=$(LINUXKIT_PKG_TARGET)"
cp images/out/*.yml $|
$(PARSE_PKGS) pkg/eve/Dockerfile.in > $|/Dockerfile
$(LINUXKIT) $(DASH_V) pkg $(LINUXKIT_PKG_TARGET) --platforms linux/$(ZARCH) --hash-path $(CURDIR) --hash $(ROOTFS_VERSION)-$(HV) --docker $(if $(strip $(EVE_REL)),--release) $(EVE_REL)$(if $(strip $(EVE_REL)),-$(HV)) $(FORCE_BUILD) $|
$(QUIET)if [ -n "$(EVE_REL)" ] && [ $(HV) = $(HV_DEFAULT) ]; then \
$(LINUXKIT) $(DASH_V) pkg $(LINUXKIT_PKG_TARGET) --platforms linux/$(ZARCH) --hash-path $(CURDIR) --hash $(EVE_REL)-$(HV) --docker --release $(EVE_REL) $(FORCE_BUILD) $| ;\
fi
$(QUIET): $@: Succeeded
.PHONY: image-set outfile-set cache-export cache-export-docker-load cache-export-docker-load-all
image-set:
ifndef IMAGE
$(error IMAGE is not set)
endif
outfile-set:
ifndef OUTFILE
$(error OUTFILE is not set)
endif
## exports an image from the linuxkit cache to stdout
cache-export: image-set outfile-set $(LINUXKIT)
$(eval IMAGE_TAG_OPT := $(if $(IMAGE_NAME),--name $(IMAGE_NAME),))
$(LINUXKIT) $(DASH_V) cache export --format docker --arch $(ZARCH) --outfile $(OUTFILE) $(IMAGE_TAG_OPT) $(IMAGE)
## export an image from linuxkit cache and load it into docker.
cache-export-docker-load: $(LINUXKIT)
$(eval TARFILE := $(shell mktemp))
$(MAKE) cache-export OUTFILE=${TARFILE} && cat ${TARFILE} | docker load
rm -rf ${TARFILE}
%-cache-export-docker-load: $(LINUXKIT)
$(eval IMAGE_TAG := $(shell $(MAKE) $*-show-tag))
$(eval CACHE_CONTENT := $(shell $(LINUXKIT) cache ls 2>&1))
$(if $(filter $(IMAGE_TAG),$(CACHE_CONTENT)),$(MAKE) cache-export-docker-load IMAGE=$(IMAGE_TAG),@echo "Missing image $(IMAGE_TAG) in cache")
## export list of images in PKGS_DOCKER_LOAD from linuxkit cache and load them into docker
## will skip image if not found in cache
cache-export-docker-load-all: $(LINUXKIT) $(addsuffix -cache-export-docker-load,$(PKGS_DOCKER_LOAD))
proto-vendor:
@$(DOCKER_GO) "cd pkg/pillar ; go mod vendor" $(CURDIR) proto
bump-eve-api:
find . -type f -name "go.mod" -exec grep -q 'github.com/lf-edge/eve-api/go' {} \; -execdir go get -u github.com/lf-edge/eve-api/go \; -execdir go mod tidy \; -execdir go mod vendor \;
.PHONY: proto-api-%
rc-release:
./tools/rc-release.sh
lts-release:
./tools/lts-release.sh
release:
@bail() { echo "ERROR: $$@" ; exit 1 ; } ;\
X=`echo $(VERSION) | cut -s -d. -f1` ; Y=`echo $(VERSION) | cut -s -d. -f2` ; Z=`echo $(VERSION) | cut -s -d. -f3` ;\
if echo $$Z | grep -Eq '[0-9]+-lts'; then BRANCH=$$X.$$Y-stable; else BRANCH=$$X.$$Y; fi ;\
[ -z "$$X" -o -z "$$Y" -o -z "$$Z" ] && bail "VERSION missing (or incorrect). Re-run as: make VERSION=x.y.z $@" ;\
(git fetch && [ `git diff origin/master..master | wc -l` -eq 0 ]) || bail "origin/master is different from master" ;\
if git checkout $$BRANCH 2>/dev/null ; then \
echo "WARNING: branch $$BRANCH already exists: you may want to run make patch instead" ;\
git merge origin/master ;\
else \
git checkout master -b $$BRANCH && echo zedcloud.zededa.net > conf/server &&\
git commit -m"Setting default server to prod" conf/server ;\
fi || bail "Can't create $$BRANCH branch" ;\
git tag -a -m"Release $$X.$$Y.$$Z" $$X.$$Y.$$Z &&\
echo "Done tagging $$X.$$Y.$$Z release. Check the branch with git log and then run" &&\
echo " git push origin $$BRANCH $$X.$$Y.$$Z"
shell: $(GOBUILDER)
$(QUIET)DOCKER_GO_ARGS=-t ; $(DOCKER_GO) bash $(GOTREE) $(GOMODULE)
#
# Utility targets in support of our Dockerized build infrastrucutre
#
# check to make sure linuxkit version is correct
# if it does not exist, version is incorrect, or it cannot report `version --short`, download it
$(LINUXKIT): FORCE
$(eval ACTUAL_LINUXKIT_VERSION := $(strip $(shell $@ version --short 2>/dev/null || echo "unknown")))
$(if $(filter $(LINUXKIT_VERSION),$(ACTUAL_LINUXKIT_VERSION)),,$(QUIET) curl -L -o $@ $(LINUXKIT_SOURCE)/releases/download/$(LINUXKIT_VERSION)/linuxkit-$(LOCAL_GOOS)-$(HOSTARCH) && chmod +x $@)
$(QUIET): $@: Succeeded
$(GOBUILDER):
$(QUIET): "$@: Begin: GOBUILDER=$(GOBUILDER)"
ifneq ($(BUILD),local)
@echo "Creating go builder image for user $(USER)"
$(QUIET)docker build --build-arg GOVER=$(GOVER) --build-arg USER=$(USER) --build-arg GROUP=$(GROUP) \
--build-arg UID=$(UID) --build-arg GID=$(GID) \
$(DOCKER_HTTP_PROXY) $(DOCKER_HTTPS_PROXY) $(DOCKER_NO_PROXY) $(DOCKER_ALL_PROXY) \
-t $@ build-tools/src/scripts > /dev/null
@echo "$@ docker container is ready to use"
endif
$(QUIET): $@: Succeeded
#
# Common, generalized rules
#
%.gcp: %.raw | $(DIST)
cp $< $@
dd of=$@ bs=1 seek=$$(($(MEDIA_SIZE) * 1024 * 1024)) count=0
rm -f $(dir $@)/disk.raw ; ln -s $(notdir $@) $(dir $@)/disk.raw
$(DOCKER_GO) "tar --mode=644 --owner=root --group=root -S -h -czvf $(notdir $*).img.tar.gz disk.raw" $(dir $@) dist
rm -f $(dir $@)/disk.raw
$(QUIET): $(dir $@)/$(notdir $*).img.tar.gz: Succeeded
ifdef LIVE_UPDATE
# Target depends on rootfs tarbar directly, which gives possibility to
# detect when qcow2 should be updated with a tarball and when it should
# be recreated from scratch.
%.qcow2: %.raw $(ROOTFS_TAR) | $(DIST)
# Detect if the first %.raw ($<) prerequisite is in the "$?" list,
# which means qcow has to be fully recreated. If not - just update
# with the existing tar.
$(eval RECREATE := $(if $(filter $<,$?),1,0))
# Convert raw to qcow or update rootfs with all files from tar:
# guestfish one line magic.
$(QUIET)if [ "$(RECREATE)" = "1" ]; then \
echo "Recreate $@:"; \
echo " qemu-img convert ..."; \
qemu-img convert -c -f raw -O qcow2 $< $@; \
echo " qemu-img resize ..."; \
qemu-img resize $@ ${MEDIA_SIZE}M; \
else \
echo "Update $@ with generated tarball:"; \
echo " guestfish ..."; \
guestfish -a $@ run : mount /dev/sda2 / : tar-in $(ROOTFS_TAR) /; \
fi
$(QUIET): $@: Succeeded
else
%.qcow2: %.raw | $(DIST)
qemu-img convert -c -f raw -O qcow2 $< $@
qemu-img resize $@ ${MEDIA_SIZE}M
$(QUIET): $@: Succeeded
endif