-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
163 lines (128 loc) · 3.96 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
#!/usr/bin/make -f
##
# Makefile for Teckhost systems
# See env[TH_SRC] and env[TH_CKSUM] for ISO building
##
export WORKSPACE ?= $(abspath $(PWD)/)
##
# ISO
##
# Version Table
debian12_src ?= https://cdimage.debian.org/cdimage/archive/12.6.0/amd64/iso-cd/debian-12.6.0-amd64-netinst.iso
debian12_sha ?= ade3a4acc465f59ca2496344aab72455945f3277a52afc5a2cae88cdc370fa12
ubuntu2204_src ?= https://releases.ubuntu.com/20.04.6/ubuntu-20.04.6-desktop-amd64.iso
ubuntu2204_sha ?= 510ce77afcb9537f198bc7daa0e5b503b6e67aaed68146943c231baeaab94df1
# Default release
teckhost.iso: teckhost_debian12.iso
cp teckhost_debian12.iso teckhost.iso
# Remaster an upstream ISO with teckhost bootstrapping
teckhost_%.iso: upstream_%.iso
./iso/build_iso $(ISOARGS) -d iso/$* \
-i upstream_$*.iso -o teckhost_$*.iso
# Grab an upstream ISO and validate checksum
upstream_%.iso:
# Copy iso from parent directory or download fresh copy
cp "../$($*_sha).iso" ./ || wget --quiet -O "$($*_sha).iso" "$($*_src)"
# Verify checksum of pristine iso
echo "$($*_sha) $($*_sha).iso" | sha256sum -c
# Move into location to verify success
mv "$($*_sha).iso" "upstream_$*.iso"
##
# Default Test [Debian 12, Container]
##
test: testpod-debian
##
# Test/Dev - Container (packer)
##
# Run tests inside container
testpod-%: tpod_%
podman run --rm -it -h testpc1 \
-v "$(PWD):/srv/salt" \
-e BS_gitfs_base="$(shell git rev-parse HEAD)" \
tpod_$* /srv/salt/test/Dockertest.sh
# Log in to container (pre-dockertest.sh)
playpod-%: tpod_%
podman run --rm -it -h testpc1 \
-v "$(PWD):/srv/salt" \
tpod_$* /bin/bash
##
# Containers (test pods)
##
# Build a container for testing
# Dockerfile pre-installs many desktop files and requires 8+GB in /var/tmp.
tpod_%:
@current_size=$$(df -m /var/tmp | awk 'NR==2 {print $$2}'); \
if [ "$$current_size" -lt 10240 ]; then \
mount -o remount,size=10G /var/tmp; \
fi
podman build -t tpod_$* \
-f test/Dockerfile.$*
##
# Test/Dev - Full VM (virtualbox)
##
# Apply minimum patches (hostname, confirmation, etc.) to preseed
iso/%/testseed.cfg: iso/%/preseed.cfg iso/%/preseed_test.patch
cp iso/$*/preseed.cfg iso/$*/testseed.cfg
patch iso/$*/testseed.cfg iso/$*/preseed_test.patch
# File modes in git are not reliable
testprep:
chmod 0700 test/.ssh
chmod 0600 test/.ssh/id_ed25519
# Create testpc1 and run all {admin,user} tests
full-test: testpc1_debian12 pytest-testpc1-user pytest-testpc1-admin
# Run user-only tests against a host as user:testuser
pytest-%-user:
python3 -m pytest \
--ssh-config=test/.ssh/config \
--ssh-identity-file=test/.ssh/id_ed25519 \
--hosts=ssh://testuser@$* \
--type user
# Run root-required tests against a host as user:testadmin
pytest-%-admin:
python3 -m pytest \
--ssh-config=test/.ssh/config \
--ssh-identity-file=test/.ssh/id_ed25519 \
--hosts=ssh://testadmin@$* \
--type admin
# Connect to a host using ssh as user:testadmin
ssh-%-user: testprep
ssh -F test/.ssh/config -i test/.ssh/id_ed25519 \
ssh://testuser@$*
# Connect to a host using ssh as user:testadmin
ssh-%-admin: testprep
ssh -F test/.ssh/config -i test/.ssh/id_ed25519 \
ssh://testadmin@$*
##
# Virtual Machines
##
# Create a testpc1 image using the specified iso
testpc1_%: teckhost_%.iso
ifneq (,$(findstring testpc1,$(shell VBoxManage list vms)))
echo 'VM already exists: testpc1'
else
./test/vbox_create \
-i $(WORKSPACE)/teckhost_$*.iso \
-n testpc1 -p 4222
endif
##
# Cleanup
##
clean: clean-testpc1 cleanpod-debian
$(RM) iso/*/testseed.cfg teckhost*.iso
podman system prune -f || true
# Delete a Container if it exists
cleanpod-%:
@if [ -n "$(findstring tpod_$*,$(shell podman images))" ]; then \
podman rmi tpod_$*; \
else \
echo "No container exists for $*; skipping"; \
fi
# Delete a VM if it exists
clean-%:
@if [ -n "$(findstring $*,$(shell VBoxManage list vms))" ]; then \
VBoxManage controlvm $* poweroff || true; \
VBoxManage unregistervm $* --delete; \
else \
echo "No VMs could match $*; skipping"; \
fi
.PHONY: testprep test clean