forked from bottlerocket-os/bottlerocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
118 lines (99 loc) · 3.68 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
.DEFAULT_GOAL := all
OS := thar
RECIPE ?= aws-eks-ami
TOPDIR := $(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))
DEP4SPEC ?= $(TOPDIR)/bin/dep4spec
SPEC2VAR ?= $(TOPDIR)/bin/spec2var
SPEC2PKG ?= $(TOPDIR)/bin/spec2pkg
FETCH_UPSTREAM ?= $(TOPDIR)/bin/fetch-upstream
UPLOAD_SOURCES ?= $(TOPDIR)/bin/upload-sources
export ALLOW_ARBITRARY_SOURCE_URL ?= true
SPECS = $(wildcard packages/*/*.spec)
DEPS = $(SPECS:.spec=.makedep)
VARS = $(SPECS:.spec=.makevar)
PKGS = $(SPECS:.spec=.makepkg)
OUTPUT ?= $(TOPDIR)/build
OUTVAR := $(shell mkdir -p $(OUTPUT))
DATE := $(shell date --rfc-3339=date)
ARCH ?= $(shell uname -m)
DOCKER ?= docker
BUILDKIT_VER = v0.4.0
BUILDKITD_ADDR ?= tcp://127.0.0.1:1234
BUILDCTL_DOCKER_RUN = $(DOCKER) run --rm -t --entrypoint /usr/bin/buildctl --user $(shell id -u):$(shell id -g) --volume $(TOPDIR):$(TOPDIR) --workdir $(TOPDIR) --network host moby/buildkit:$(BUILDKIT_VER)
BUILDCTL ?= $(BUILDCTL_DOCKER_RUN) --addr $(BUILDKITD_ADDR)
BUILDCTL_ARGS := --progress=plain
BUILDCTL_ARGS += --frontend=dockerfile.v0
BUILDCTL_ARGS += --local context=.
BUILDCTL_ARGS += --local dockerfile=.
define build_rpm
$(eval HASH:= $(shell sha1sum $3 /dev/null | sha1sum - | awk '{printf $$1}'))
$(eval RPMS:= $(shell echo $3 | tr ' ' '\n' | awk '/.rpm$$/' | tr '\n' ' '))
@$(BUILDCTL) build \
--opt target=rpm \
--opt build-arg:PACKAGE=$(1) \
--opt build-arg:ARCH=$(2) \
--opt build-arg:HASH=$(HASH) \
--opt build-arg:RPMS="$(RPMS)" \
--opt build-arg:DATE=$(DATE) \
--output type=local,dest=$(OUTPUT) \
$(BUILDCTL_ARGS)
endef
define build_image
$(eval HASH:= $(shell sha1sum $(2) /dev/null | sha1sum - | awk '{print $$1}'))
@$(BUILDCTL) build \
--opt target=builder \
--opt build-arg:PACKAGE=$(OS)-$(1)-$(RECIPE) \
--opt build-arg:ARCH=$(1) \
--opt build-arg:HASH=$(HASH) \
--opt build-arg:DATE=$(DATE) \
--output type=docker,name=$(OS)-builder:$(1),dest=build/$(OS)-$(1)-builder.tar \
$(BUILDCTL_ARGS)
@$(DOCKER) load < build/$(OS)-$(1)-builder.tar
@$(DOCKER) run -t -v /dev:/dev -v $(OUTPUT):/local/output \
$(OS)-builder:$(1) \
--disk-image-name=$(OS)-$(1).img \
--boot-image-name=$(OS)-$(1)-boot.ext4.lz4 \
--verity-image-name=$(OS)-$(1)-root.verity.lz4 \
--root-image-name=$(OS)-$(1)-root.ext4.lz4 \
--package-dir=/local/rpms \
--output-dir=/local/output
endef
# `makedep` files are a hook to provide additional dependencies when
# building `makevar` and `makepkg` files. The intended use case is
# to generate source files that must be in place before parsing the
# spec file.
%.makedep : %.spec $(DEP4SPEC)
@$(DEP4SPEC) --spec=$< --arch=$(ARCH) > [email protected]
@mv [email protected] $@
# `makevar` files generate variables that the `makepkg` files for
# other packages can refer to. All `makevar` files must be evaluated
# before any `makepkg` files, or else empty values could be added to
# the dependency list.
%.makevar : %.spec %.makedep $(SPEC2VAR)
@$(SPEC2VAR) --spec=$< --arch=$(ARCH) > [email protected]
@mv [email protected] $@
# `makepkg` files define the package outputs obtained by building
# the spec file, as well as the dependencies needed to build that
# package.
%.makepkg : %.spec %.makedep %.makevar $(SPEC2PKG)
@$(SPEC2PKG) --spec=$< --arch=$(ARCH) > [email protected]
@mv [email protected] $@
include $(DEPS)
include $(VARS)
include $(PKGS)
.PHONY: all $(ARCH)
.SECONDEXPANSION:
$(ARCH): $$($(OS)-$(ARCH)-$(RECIPE))
$(eval PKGS:= $(wildcard $(OUTPUT)/$(OS)-$(ARCH)-*.rpm))
$(call build_image,$@,$(PKGS))
all: $(ARCH)
.PHONY: clean
clean:
@rm -f $(OUTPUT)/*.rpm $(OUTPUT)/*.tar $(OUTPUT)/*.lz4 $(OUTPUT)/*.img
@find $(TOPDIR) -name '*.make*' -delete
.PHONY: sources
sources: $(SOURCES)
.PHONY: upload-sources
upload-sources: $(SOURCES)
@$(UPLOAD_SOURCES) $^
include $(TOPDIR)/hack/rules.mk