forked from rancher/elemental
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
142 lines (131 loc) · 5.21 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
GIT_COMMIT?=$(shell git rev-parse HEAD)
GIT_COMMIT_SHORT?=$(shell git rev-parse --short HEAD)
GIT_TAG?=$(shell git describe --abbrev=0 --tags 2>/dev/null || echo "v0.0.0" )
TAG?=${GIT_TAG}-${GIT_COMMIT_SHORT}
REPO?=ttl.sh/elemental-ci
CLOUD_CONFIG_FILE?="iso/config"
MANIFEST_FILE?="iso/manifest.yaml"
# This are the default images already in the dockerfile but we want to be able to override them
OPERATOR_IMAGE?=quay.io/costoolkit/elemental-operator-ci:latest
REGISTER_IMAGE?=quay.io/costoolkit/elemental-register-ci:latest
SYSTEM_AGENT_IMAGE?=rancher/system-agent:v0.2.9
TOOL_IMAGE?=quay.io/costoolkit/elemental-cli-ci:latest
# Used to know if this is a release or just a normal dev build
RELEASE_TAG?=false
# Set tag based on release status for ease of use
ifeq ($(RELEASE_TAG), "true")
FINAL_TAG:=$(GIT_TAG)
else
FINAL_TAG:=$(TAG)
endif
# Set ISO variable
ISO?=build/elemental-${FINAL_TAG}.iso
.PHONY: clean
clean:
rm -rf build
# Build elemental docker images
.PHONY: build
build:
@DOCKER_BUILDKIT=1 docker build -f Dockerfile.image \
--target default \
--build-arg IMAGE_TAG=${FINAL_TAG} \
--build-arg IMAGE_COMMIT=${GIT_COMMIT} \
--build-arg IMAGE_REPO=${REPO} \
--build-arg OPERATOR_IMAGE=${OPERATOR_IMAGE} \
--build-arg REGISTER_IMAGE=${REGISTER_IMAGE} \
--build-arg SYSTEM_AGENT_IMAGE=${SYSTEM_AGENT_IMAGE} \
--build-arg TOOL_IMAGE=${TOOL_IMAGE} \
-t ${REPO}:${FINAL_TAG} \
.
@DOCKER_BUILDKIT=1 docker push ${REPO}:${FINAL_TAG}
.PHONY: dump_image
dump_image:
@mkdir -p build
@docker save ${REPO}:${FINAL_TAG} -o build/elemental-${FINAL_TAG}.tar
# Build iso with the elemental image as base
.PHONY: iso
iso:
ifeq ($(CLOUD_CONFIG_FILE),"iso/config")
@echo "No CLOUD_CONFIG_FILE set, using the default one at ${CLOUD_CONFIG_FILE}"
else
@cp ${CLOUD_CONFIG_FILE} iso/config
endif
ifeq ($(MANIFEST_FILE),"iso/manifest.yaml")
@echo "No MANIFEST_FILE set, using the default one at ${MANIFEST_FILE}"
else
@cp ${MANIFEST_FILE} iso/config
endif
@mkdir -p build
@DOCKER_BUILDKIT=1 docker build -f Dockerfile.iso \
--target default \
--build-arg OS_IMAGE=${REPO}:${FINAL_TAG} \
--build-arg TOOL_IMAGE=${TOOL_IMAGE} \
--build-arg ELEMENTAL_VERSION=${FINAL_TAG} \
--build-arg CLOUD_CONFIG_FILE=${CLOUD_CONFIG_FILE} \
--build-arg MANIFEST_FILE=${MANIFEST_FILE} \
-t iso:${FINAL_TAG} .
@DOCKER_BUILDKIT=1 docker run --rm -v $(PWD)/build:/mnt \
iso:${FINAL_TAG} \
--config-dir . \
--debug build-iso \
-o /mnt \
-n elemental-${FINAL_TAG} \
--overlay-iso overlay dir:rootfs
@echo "INFO: ISO available at ${ISO}"
# Build an iso with the OBS base containers
.PHONY: remote_iso
proper_iso:
ifeq ($(CLOUD_CONFIG_FILE),"iso/config")
@echo "No CLOUD_CONFIG_FILE set, using the default one at ${CLOUD_CONFIG_FILE}"
endif
ifeq ($(MANIFEST_FILE),"iso/manifest.yaml")
@echo "No MANIFEST_FILE set, using the default one at ${MANIFEST_FILE}"
else
@cp ${MANIFEST_FILE} iso/config
endif
@mkdir -p build
@DOCKER_BUILDKIT=1 docker build -f Dockerfile.iso \
--target default \
--build-arg CLOUD_CONFIG_FILE=${CLOUD_CONFIG_FILE} \
--build-arg MANIFEST_FILE=${MANIFEST_FILE} \
-t iso:latest .
@DOCKER_BUILDKIT=1 docker run --rm -v $(PWD)/build:/mnt \
iso:latest \
--config-dir . \
--debug build-iso \
-o /mnt \
-n elemental-${FINAL_TAG} \
--overlay-iso overlay dir:rootfs
@echo "INFO: ISO available at ${ISO}"
.PHONY: extract_kernel_init_squash
extract_kernel_init_squash:
@VAR='$(ISO)'; \
INITRD_FILE=$$(isoinfo -R -i ${ISO} -find -type f -name initrd -print 2>/dev/null); \
KERNEL_FILE=$$(isoinfo -R -i ${ISO} -find -type f -name kernel -print 2>/dev/null); \
[[ -z "$${KERNEL_FILE}" ]] && KERNEL_FILE=$$(isoinfo -R -i ${ISO} -find -type f -name linux -print 2>/dev/null); \
isoinfo -x /rootfs.squashfs -R -i ${ISO} > $${VAR/\.iso/.squashfs} 2>/dev/null; \
isoinfo -x $${INITRD_FILE} -R -i ${ISO} > $${VAR/\.iso/-initrd} 2>/dev/null; \
isoinfo -x $${KERNEL_FILE} -R -i ${ISO} > $${VAR/\.iso/-kernel} 2>/dev/null
.PHONY: ipxe
ipxe:
@mkdir -p build
@echo "#!ipxe" > build/elemental-${FINAL_TAG}.ipxe
@echo "set arch amd64" >> build/elemental-${FINAL_TAG}.ipxe
ifeq ($(RELEASE_TAG), "true")
@echo "set url https://github.com/rancher/elemental/releases/download/${FINAL_TAG}" >> build/elemental-${FINAL_TAG}.ipxe
else
@echo "set url tftp://10.0.2.2/${TAG}" >> build/elemental-${FINAL_TAG}.ipxe
endif
@echo "set kernel elemental-${FINAL_TAG}-kernel" >> build/elemental-${FINAL_TAG}.ipxe
@echo "set initrd elemental-${FINAL_TAG}-initrd" >> build/elemental-${FINAL_TAG}.ipxe
@echo "set rootfs elemental-${FINAL_TAG}.squashfs" >> build/elemental-${FINAL_TAG}.ipxe
@echo "# set config http://example.com/machine-config" >> build/elemental-${FINAL_TAG}.ipxe
@echo "# set cmdline extra.values=1" >> build/elemental-${FINAL_TAG}.ipxe
@echo "initrd \$${url}/\$${initrd}" >> build/elemental-${FINAL_TAG}.ipxe
@echo "chain --autofree --replace \$${url}/\$${kernel} initrd=\$${initrd} ip=dhcp rd.cos.disable root=live:\$${url}/\$${rootfs} stages.initramfs[0].commands[0]=\"curl -k \$${config} > /run/initramfs/live/livecd-cloud-config.yaml\" console=tty1 console=ttyS0 \$${cmdline}" >> build/elemental-${FINAL_TAG}.ipxe
.PHONY: build_all
build_all: build iso extract_kernel_init_squash ipxe
.PHONY: docs
docs:
@yarn install --frozen-lockfile
@yarn build