Skip to content

Commit b03a72d

Browse files
committed
WIP: trying to run in a VM
1 parent 7597445 commit b03a72d

File tree

4 files changed

+430
-0
lines changed

4 files changed

+430
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@ on-prem/build/config/ca
66
on-prem/build/config/repositories
77
service_images_built.info
88
onprem_images_built.info
9+
vm_defined.info
10+
vm_image_built.info
911

12+
*.qcow2
13+
osbuild-getting-started-*.toml
14+
osbuild-getting-started-*.xml

Makefile

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ wipe-config:
110110
clean: $(COMMON_SRC_DEPS_ORIGIN) $(SERVICE_SRC_DEPS_ORIGIN) $(ONPREM_SRC_DEPS_ORIGIN) wipe-config
111111
rm -f service_images_built.info
112112
rm -f onprem_images_built.info
113+
rm -f vm_image_built.info
114+
rm -f vm_defined.info
113115
for DIR in $*; do $(MAKE_SUB_CALL) -C $$DIR clean; done
114116
$(CONTAINER_COMPOSE_EXECUTABLE) -f service/docker-compose.yml rm
115117
$(CONTAINER_COMPOSE_EXECUTABLE) -f service/docker-compose-onprem.yml rm
@@ -175,3 +177,78 @@ else
175177
sudo -u ${SUDO_USER} ./git_stack.sh fetch --all
176178
endif
177179
@./git_stack.sh
180+
181+
182+
BLUEPRINT = osbuild-getting-started-fedora39.toml
183+
# patch the BLUEPRINT with the current user ID
184+
# we need this because the user in the VM directly writes to
185+
# the mapped source directory
186+
$(BLUEPRINT): $(BLUEPRINT:.toml=.toml.template)
187+
cp $< $@
188+
sed -i -E "s|(uid *= *)(.+)|\1$$(id -u)|g" $@
189+
sed -i -E "s|(gid *= *)(.+)|\1$$(id -g)|g" $@
190+
191+
.ONESHELL:
192+
.SILENT:
193+
vm_image_built.info: $(BLUEPRINT) osbuild-getting-started-fedora39.xml.template
194+
echo "Pushing blueprint '$(BLUEPRINT)' to composer to create a virtual machine for development"
195+
composer-cli blueprints push $(BLUEPRINT)
196+
# start building
197+
export COMPOSE_ID="$$(composer-cli compose start osbuild-getting-started-fedora-39 qcow2|awk 'NR==1 {print $$2}')"
198+
199+
echo "Compose id: $${COMPOSE_ID} started"
200+
echo "Waiting for osbuild to create our virtual machine"
201+
sleep 2
202+
while true; do \
203+
export STATUS="$$(composer-cli compose info $${COMPOSE_ID}| awk 'NR==1 {print $$2}')" ; \
204+
if [[ "$$STATUS" != "RUNNING" && "$$STATUS" != "WAITING" ]]; then echo " $$STATUS"; break; fi; \
205+
echo -n "."; sleep 1; \
206+
done ;
207+
208+
echo "Getting qcow2 image"
209+
composer-cli compose image "$${COMPOSE_ID}"
210+
211+
echo "$${COMPOSE_ID}" > $@
212+
213+
VM_XML = osbuild-getting-started-fedora39.xml
214+
$(VM_XML): $(VM_XML:.xml=.xml.template) vm_image_built.info
215+
cp $< $@
216+
sed -i -E "s|REPLACEME_QCOW2|$$(pwd)/$$(cat vm_image_built.info)-disk.qcow2|" osbuild-getting-started-fedora39.xml
217+
sed -i -E "s|REPLACEME_HOST_DATA|$$(readlink -f ..)|" osbuild-getting-started-fedora39.xml
218+
sed -i -E "s|REPLACEME_HOST_GO_CACHE|$$(readlink -f $${GOPATH:-$$HOME/go})|" osbuild-getting-started-fedora39.xml
219+
220+
.ONESHELL:
221+
.SILENT:
222+
vm_defined.info: $(VM_XML)
223+
echo "Using 'virsh' as root to define the virtual machine"
224+
-sudo virsh destroy osbuild-getting-started-fedora39
225+
-sudo virsh undefine osbuild-getting-started-fedora39
226+
sudo virsh define osbuild-getting-started-fedora39.xml
227+
228+
echo "VM last defined on" > $@
229+
date >> $@
230+
231+
.PHONY: start-vm
232+
.ONESHELL:
233+
start-vm: vm_defined.info
234+
@echo "Starting the virtual machine"
235+
sudo virsh start osbuild-getting-started-fedora39
236+
export MAC=$$(awk -F '"' '/mac address/{print $$2}' osbuild-getting-started-fedora39.xml)
237+
export IP="$$(sudo virsh net-dhcp-leases default | awk "/$$MAC/ {split(\$$5, a, \"/\"); print a[1]}")"
238+
@echo -e "\nYou can now login with:"
239+
@echo "ssh -o \"UserKnownHostsFile=/dev/null\" -o \"StrictHostKeyChecking=no\" -o \"LogLevel=ERROR\" osbuild@$$IP"
240+
241+
.PHONY: stop-vm
242+
.ONESHELL:
243+
stop-vm:
244+
sudo virsh destroy osbuild-getting-started-fedora39
245+
246+
.PHONY: recompile
247+
.ONESHELL:
248+
recompile:
249+
export MAC=$$(awk -F '"' '/mac address/{print $$2}' osbuild-getting-started-fedora39.xml)
250+
export IP="$$(sudo virsh net-dhcp-leases default | awk "/$$MAC/ {split(\$$5, a, \"/\"); print a[1]}")"
251+
export CMD="ssh -o \"UserKnownHostsFile=/dev/null\" -o \"StrictHostKeyChecking=no\" -o \"LogLevel=ERROR\" osbuild@$$IP"
252+
echo "Installing osbuild"
253+
bash -c "$$CMD 'cd /workspaces/osbuild ; make rpm-devel'"
254+
bash -c "$$CMD 'sudo rpm -i /workspaces/osbuild/rpmbuild/RPMS/*.rpm' || echo 'OK, already installed'"
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
name = "osbuild-getting-started-fedora-39"
2+
distro = "fedora-39"
3+
version = "0.0.5"
4+
5+
# CUDACXX=/usr/local/cuda-12/bin/nvcc CMAKE_ARGS="-DLLAMA_CUBLAS=on -DCMAKE_CUDA_ARCHITECTURES=native" pip install --force-reinstall --no-cache-dir llama-cpp-python
6+
7+
packages = [
8+
{ name = "bash-completion" },
9+
{ name = "btrfs-progs-devel" },
10+
{ name = "cmake" },
11+
{ name = "cryptsetup" },
12+
{ name = "delve" },
13+
{ name = "device-mapper-devel" },
14+
{ name = "device-mapper-devel" },
15+
{ name = "device-mapper-libs" },
16+
{ name = "g++" },
17+
{ name = "gdisk" },
18+
{ name = "git" },
19+
{ name = "golang" },
20+
{ name = "gpgme" },
21+
{ name = "gpgme-devel" },
22+
{ name = "libassuan" },
23+
{ name = "libassuan-devel" },
24+
{ name = "openssh-server" },
25+
{ name = "ostree" },
26+
{ name = "podman" },
27+
{ name = "policycoreutils-python-utils" },
28+
{ name = "procps-ng" },
29+
{ name = "python3-devel" },
30+
{ name = "python3-dnf" },
31+
{ name = "python3-docutils" },
32+
{ name = "python3-pip" },
33+
{ name = "python3-rich" },
34+
{ name = "python3-tomli" },
35+
{ name = "python3-typer" },
36+
{ name = "python3.11" },
37+
{ name = "qemu-img" },
38+
{ name = "rpm-build" },
39+
{ name = "rpm-ostree" },
40+
{ name = "rsync" },
41+
{ name = "selinux-policy-devel" },
42+
{ name = "skopeo" },
43+
{ name = "tmux" },
44+
{ name = "vim" },
45+
]
46+
47+
[customizations]
48+
hostname = "osbuild-getting-started-vm"
49+
50+
[[customizations.filesystem]]
51+
mountpoint = "/"
52+
# 10GB
53+
minsize = 10737418240
54+
# 20GB
55+
#minsize = 21474836480
56+
# 25GB
57+
#minsize = 26843545600
58+
# 50GB
59+
#minsize = 53687091200
60+
61+
[customizations.locale]
62+
languages = ["en_US.UTF-8"]
63+
keyboard = "de"
64+
65+
[customizations.timezone]
66+
timezone = "Europe/Vienna"
67+
68+
[customizations.services]
69+
enabled = ["firstboot-tasks"]
70+
71+
[[customizations.files]]
72+
path = "/etc/systemd/system/firstboot-tasks.service"
73+
data = """[Unit]
74+
Description=Do all kinds of firstboot tasks
75+
ConditionPathExists=/etc/firstboot-tasks.touch
76+
Wants=network-online.target
77+
After=network-online.target
78+
79+
[Service]
80+
Type=oneshot
81+
User=root
82+
83+
ExecStart=/bin/bash -c 'echo "host_data /workspaces virtiofs defaults,user 0 0" | tee -a /etc/fstab'
84+
ExecStart=/bin/bash -c 'echo "host_go_cache /home/osbuild/go virtiofs defaults,user 0 0" | tee -a /etc/fstab'
85+
ExecStart=/usr/bin/systemctl daemon-reload
86+
ExecStart=/usr/bin/mount /workspaces
87+
ExecStart=/usr/bin/mount /home/osbuild/go
88+
89+
ExecStart=/bin/bash -c 'echo "cd /workspaces" >> /home/osbuild/.bashrc'
90+
91+
ExecStart=/usr/bin/rm /etc/firstboot-tasks.touch
92+
93+
[Install]
94+
WantedBy=multi-user.target
95+
"""
96+
97+
# Indicate that we never did firstboot tasks
98+
[[customizations.files]]
99+
path = "/etc/firstboot-tasks.touch"
100+
data = """ Trigger to firstboot tasks - file is removed after first run
101+
"""
102+
103+
[[customizations.directories]]
104+
path = "/home/osbuild/go"
105+
mode = "0755"
106+
user = "osbuild"
107+
group = "osbuild"
108+
109+
[[customizations.directories]]
110+
path = "/workspaces"
111+
mode = "0755"
112+
user = "osbuild"
113+
group = "osbuild"
114+
115+
[[customizations.files]]
116+
path = "/workspaces/init.sh"
117+
data = """#!/usr/bin/bash
118+
# This should be hidden by mounting your local host directory
119+
# but it's also possible to get all the sources in the VM
120+
git clone [email protected]:osbuild/community-gateway.git
121+
git clone [email protected]:osbuild/image-builder-frontend.git
122+
git clone [email protected]:osbuild/image-builder.git
123+
git clone [email protected]:osbuild/images.git
124+
git clone [email protected]:osbuild/osbuild-composer.git
125+
git clone [email protected]:osbuild/osbuild-getting-started.git
126+
git clone [email protected]:osbuild/osbuild.git
127+
git clone [email protected]:osbuild/pulp-client.git
128+
"""
129+
130+
# no password needed for sudo
131+
[[customizations.files]]
132+
path = "/etc/sudoers.d/%wheel"
133+
data = """%wheel ALL=(ALL) NOPASSWD: ALL
134+
"""
135+
136+
[[customizations.sshkey]]
137+
user = "root"
138+
key = "REPLACEME_KEY_ROOT"
139+
140+
[[customizations.group]]
141+
name = "osbuild"
142+
gid = 1000
143+
144+
[[customizations.user]]
145+
name = "osbuild"
146+
description = "Administrator account and runner for the containers"
147+
password = "REPLACEME_PASSWORD_USER"
148+
key = "REPLACEME_KEY_USER"
149+
home = "/home/osbuild"
150+
shell = "/bin/bash"
151+
groups = [ "users", "wheel"]
152+
uid = 1000
153+
gid = 1000
154+
155+

0 commit comments

Comments
 (0)