-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
144 lines (121 loc) · 5.03 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
# Variables
ENDPOINT ?=
API_ADDRESS ?= $(ENDPOINT)
TOKEN ?=
CERTHASH ?=
NODE_LABELS ?= net.mcserverhosting.node/ephemeral=true,kubernetes.io/os=MCSH
NTP_SERVER_IP = 192.168.67.1
# Kernel version to use
LINUX ?= linux
# Feature levels
FEATURE_LEVELS = x86-64-v3
# Kubernetes version
K8S_VERSION ?= $(shell curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt | tr -d 'v')
# Packages
NVIDIA_PACKAGES_LIST = nvidia-dkms nvidia-container-toolkit
AMD_PACKAGES_LIST = amdgpu-pro-installer-debug rocm-hip-sdk rocm-opencl-sdk radeontop
UNIX_TOOLS_LIST = openssh nano vim vi curl wget htop bpytop btop
ENABLE_NVIDIA ?= 0
ENABLE_AMD ?= 0
# Kernel modules to load
KERNEL_MODULES = br_netfilter ip6_tables ip_tables ip6table_mangle ip6table_raw ip6table_filter xt_socket erofs
# Paths
OUTPUT_DIR = baseline/airootfs/usr/local/bin
INCLUDE_OPENSSH = $(shell grep -w 'openssh' baseline/packages.x86_64 >/dev/null && echo 1 || echo 0)
all: template-linux template-kubeadm ssh-keys package-list init-script ntp-conf $(addprefix build-iso-,$(FEATURE_LEVELS))
# Process kubeadm.conf.yaml.template
template-kubeadm:
@echo "Templating kubeadm.conf.yaml with provided variables."
@cp baseline/airootfs/etc/kubeadm/kubeadm.conf.yaml.template baseline/airootfs/etc/kubeadm/kubeadm.conf.yaml
@if [ -n "$(API_ADDRESS)" ]; then \
sed -i 's|{{API_ADDRESS}}|$(API_ADDRESS)|g' baseline/airootfs/etc/kubeadm/kubeadm.conf.yaml; \
else \
echo "No API_ADDRESS provided; leaving placeholder for runtime substitution."; \
fi
@if [ -n "$(TOKEN)" ]; then \
sed -i 's|{{TOKEN}}|$(TOKEN)|g' baseline/airootfs/etc/kubeadm/kubeadm.conf.yaml; \
else \
echo "No TOKEN provided; leaving placeholder for runtime substitution."; \
fi
@if [ -n "$(CERTHASH)" ]; then \
sed -i 's|{{CERT_HASH}}|$(CERTHASH)|g' baseline/airootfs/etc/kubeadm/kubeadm.conf.yaml; \
else \
echo "No CERTHASH provided; leaving placeholder for runtime substitution."; \
fi
@sed -i 's|{{NODE_LABELS}}|$(NODE_LABELS)|g' baseline/airootfs/etc/kubeadm/kubeadm.conf.yaml
# Generate package list based on enabled features
package-list:
@echo "Generating package list..."
@( \
export LINUX="$(LINUX)"; \
if [ "$(ENABLE_NVIDIA)" -eq "1" ]; then \
NVIDIA_PACKAGES="$$(printf '%s\n' $(NVIDIA_PACKAGES_LIST))"; \
else \
NVIDIA_PACKAGES=""; \
fi; \
if [ "$(ENABLE_AMD)" -eq "1" ]; then \
AMD_PACKAGES="$$(printf '%s\n' $(AMD_PACKAGES_LIST))"; \
else \
AMD_PACKAGES=""; \
fi; \
UNIX_TOOLS="$$(printf '%s\n' $(UNIX_TOOLS_LIST))"; \
export NVIDIA_PACKAGES; \
export AMD_PACKAGES; \
export UNIX_TOOLS; \
envsubst < baseline/packages.x86_64.template > baseline/packages.x86_64; \
)
# Ensure SSH keys have correct permissions
ssh-keys:
@if [ -d baseline/airootfs/root/.ssh ]; then \
chmod 700 baseline/airootfs/root/.ssh; \
if [ -f baseline/airootfs/root/.ssh/authorized_keys ]; then \
chmod 600 baseline/airootfs/root/.ssh/authorized_keys; \
fi; \
fi
# Generate init.sh with modprobe commands and conditional SSH
init-script:
@echo "Generating init.sh with modprobe commands and SSH configuration..."
@cp baseline/airootfs/root/init.sh.template baseline/airootfs/root/init.sh
@sed -i '/# Load Kernel modules/a \
$(foreach module,$(KERNEL_MODULES),modprobe $(module);)' baseline/airootfs/root/init.sh
@if [ "$(INCLUDE_OPENSSH)" -eq "1" ]; then \
echo "Enabling SSH in init script..."; \
sed -i 's|#ENABLE_SSH||' baseline/airootfs/root/init.sh; \
else \
echo "SSH will not be enabled as openssh is not included."; \
sed -i '/#ENABLE_SSH/d' baseline/airootfs/root/init.sh; \
fi
@chmod +x baseline/airootfs/root/init.sh
# Update ntp.conf with the specified NTP server IP
ntp-conf:
@echo "Configuring ntp.conf..."
@sed -i 's|^server .*|server $(NTP_SERVER_IP)|' baseline/airootfs/etc/ntp.conf
# Process all .template files
template-linux:
@echo "Templating files with LINUX=$(LINUX) and FEATURE_LEVEL=$(FEATURE_LEVEL)"
@find baseline -type f -name "*.template" | while read template; do \
target="$${template%.template}"; \
echo "Processing $$template -> $$target"; \
sed 's|{{LINUX}}|$(LINUX)|g; s|{{FEATURE_LEVEL}}|$(FEATURE_LEVEL)|g' "$$template" > "$$target"; \
done
# Process pacman.conf.template to generate pacman.conf
pacman-conf:
@echo "Templating pacman.conf with FEATURE_LEVEL=$(FEATURE_LEVEL)"
@sed 's|{{FEATURE_LEVEL}}|$(FEATURE_LEVEL)|g' baseline/pacman.conf.template > baseline/pacman.conf
# Build ISO for each feature level
$(addprefix build-iso-,$(FEATURE_LEVELS)):
@echo "Building ISO for feature level: $(@:build-iso-%=%)"
@$(MAKE) build-iso FEATURE_LEVEL=$(@:build-iso-%=%)
# Build the ISO using Docker
build-iso: pacman-conf
@echo "Building ISO for FEATURE_LEVEL=$(FEATURE_LEVEL)"
@mkdir -p baseline/out/tmp
@mkarchiso -v -w /tmp/mkarchiso -o baseline/out/tmp baseline -quiet=y
@mv baseline/out/tmp/*.iso baseline/out/MCSHOS-$(K8S_VERSION)-$(FEATURE_LEVEL).iso
@rm -rf /tmp/mkarchiso/*
@rm -rf /var/cache/pacman
# Clean target
clean:
rm -rf baseline/out/*.iso
# Phony targets
.PHONY: all clean build-iso $(addprefix build-iso-,$(FEATURE_LEVELS))