summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruce Ashfield <bruce.ashfield@gmail.com>2024-10-29 15:18:40 +0000
committerBruce Ashfield <bruce.ashfield@gmail.com>2024-11-15 19:50:00 +0000
commit1a87aca209b614d865246acb7701175e19866b5a (patch)
tree701f8146ad63bdbe20e20382559af3c8be55f1fa
parent30647f3d94a4229646aabf74e640b5c564480388 (diff)
downloadmeta-virtualization-1a87aca209b614d865246acb7701175e19866b5a.tar.gz
images: add systemd reference container
Extends container-base to create a systemd enabled container that is an appropriate starting point if a systemd applciation is being run or a mulit-user style environment is required. The application specified in SYSTEMD_CONTAINER_APP will be installed and be available to be executed. The rootfs of this container type is post processed to enable and disable services as specified by the containeer definition. This allows service that are not appropriate in a containerized environemnt to be disabled (i.e. getty login) The list of services can be found in the recipes themselves. This container enables ssh by default, so that it can be executed in the background and then accessed as a full environment. Note: this is currently a priviledged container if run under docker. There are multiple ways to add/remove permissions from the container, and most are configurable during launch: % root@qemuarm64-54:~# docker run -d --rm --name systemd_test --privileged --cap-add SYS_ADMIN \ --security-opt seccomp=unconfined --cgroup-parent=docker.slice --cgroupns private \ --tmpfs /tmp --tmpfs /run --tmpfs /run/lock zeddii/systemd-container-base or % docker run -d --rm --name systemd_test --privileged --cgroup-parent=docker.slice \ --cgroupns private zeddii/c3-systemd-container % root@qemuarm64-54:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4b07cc907e26 zeddii/c3-systemd-container "/sbin/init" 5 minutes ago Up 5 minutes systemd_test % podman run -d --name systemd_test --privileged --cgroupns=host --tmpfs /tmp --tmpfs /run --tmpfs /run/lock \ -v /sys/fs/cgroup:/sys/fs/cgroup:ro zeddii/systemd-container-base % ctr container create --privileged --runtime="io.containerd.runc.v2" \ --mount type=bind,src=/sys/fs/cgroup,dst=/sys/fs/cgroup,options=rbind:rw \ docker.io/zeddii/systemd-container-base:latest my_systemd_container /sbin/init % ctr task start --detach my_systemd_container % ctr task ls TASK PID STATUS my_systemd_container 690 RUNNING Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
-rw-r--r--recipes-extended/images/container-systemd-base.bb17
-rw-r--r--recipes-extended/images/container-systemd-base.inc72
2 files changed, 89 insertions, 0 deletions
diff --git a/recipes-extended/images/container-systemd-base.bb b/recipes-extended/images/container-systemd-base.bb
new file mode 100644
index 00000000..96ef4667
--- /dev/null
+++ b/recipes-extended/images/container-systemd-base.bb
@@ -0,0 +1,17 @@
1SUMMARY = "Systemd system container for ${SYSTEMD_CONTAINER_APP}"
2DESCRIPTION = "A small systemd system container which will run \
3 ${SYSTEMD_CONTAINER_APP}."
4
5SYSTEMD_CONTAINER_APP ?= ""
6
7# Use local.conf to specify the application(s) to install
8IMAGE_INSTALL += "${SYSTEMD_CONTAINER_APP}"
9
10# Use local.conf to specify additional systemd services to disable. To overwrite
11# the default list use SERVICES_TO_DISABLE:pn-systemd-container in local.conf
12SERVICES_TO_DISABLE:append = " ${SYSTEMD_CONTAINER_DISABLE_SERVICES}"
13
14# Use local.conf to enable systemd services
15SERVICES_TO_ENABLE += "${SYSTEMD_CONTAINER_ENABLE_SERVICES}"
16
17require container-systemd-base.inc
diff --git a/recipes-extended/images/container-systemd-base.inc b/recipes-extended/images/container-systemd-base.inc
new file mode 100644
index 00000000..0b856e83
--- /dev/null
+++ b/recipes-extended/images/container-systemd-base.inc
@@ -0,0 +1,72 @@
1SUMMARY ?= "Sample systemd system container"
2DESCRIPTION ?= "A small systemd system container which will run \
3 the application defined in IMAGE_INSTALL."
4
5LICENSE ?= "MIT"
6LIC_FILES_CHKSUM ?= "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
7
8# Some commands of interest:
9# % docker run -d --rm --name systemd_test --privileged \
10# --cap-add SYS_ADMIN --security-opt seccomp=unconfined --cgroup-parent=docker.slice \
11# --cgroupns private --tmpfs /tmp --tmpfs /run --tmpfs /run/lock zeddii/systemd-container-base
12#
13# % docker run -d --rm --name systemd_test --privileged \
14# --cgroup-parent=docker.slice --cgroupns private zeddii/c3-systemd-container
15#
16# % docker inspect systemd_test
17# % docker inspect systemd_test | grep \"IPAddress\":
18# % docker exec systemd_test bash -c "echo 'testuser:password' | chpasswd"
19# % ssh testuser@172.17.0.2
20
21require container-base.bb
22
23OCI_IMAGE_ENTRYPOINT = "/sbin/init"
24
25IMAGE_INSTALL:append = " systemd"
26IMAGE_INSTALL:append = " packagegroup-core-base-utils"
27IMAGE_INSTALL:append = " packagegroup-core-ssh-openssh"
28IMAGE_INSTALL:append = " busybox"
29
30IMAGE_FEATURES ?= ""
31
32NO_RECOMMENDATIONS = "1"
33
34SERVICES_TO_DISABLE ?= " \
35 systemd-udevd.service \
36 systemd-udevd-control.socket \
37 systemd-udevd-kernel.socket \
38 proc-sys-fs-binfmt_misc.automount \
39 sys-fs-fuse-connections.mount \
40 sys-kernel-debug.mount \
41 systemd-hwdb-update.service \
42 serial-getty@ttyS0.service \
43 dev-ttyS0.device \
44 console-getty.service \
45 serial-getty@.service \
46"
47
48SERVICES_TO_ENABLE ?= ""
49
50disable_systemd_services () {
51 SERVICES_TO_DISABLE="${SERVICES_TO_DISABLE}"
52 if [ -n "$SERVICES_TO_DISABLE" ]; then
53 echo "Disabling systemd services:"
54 for service in $SERVICES_TO_DISABLE; do
55 echo " $service"
56 systemctl --root="${IMAGE_ROOTFS}" mask $service > /dev/null >1
57 done
58 fi
59}
60
61enable_systemd_services () {
62 SERVICES_TO_ENABLE="${SERVICES_TO_ENABLE}"
63 if [ -n "$SERVICES_TO_ENABLE" ]; then
64 echo "Enabling additional systemd services:"
65 for service in $SERVICES_TO_ENABLE; do
66 echo " $service"
67 systemctl --root="${IMAGE_ROOTFS}" enable $service > /dev/null >1
68 done
69 fi
70}
71
72ROOTFS_POSTPROCESS_COMMAND += "disable_systemd_services; enable_systemd_services;"