Skip to content

Commit 08049f6

Browse files
author
Thomas Roos
committed
aws-iot-greengrass-lite-container-demo-image: make it smaller 43MB
1 parent a82ea33 commit 08049f6

3 files changed

Lines changed: 213 additions & 10 deletions

File tree

meta-aws-demos/recipes-core/images/aws-iot-greengrass-lite-container-demo-image/README.md

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,97 @@
22

33
This image is similar to [aws-iot-greengrass-lite-demo-image](../aws-iot-greengrass-lite-demo-image/README.md)
44

5-
It will create a container image with greengrass lite installed.
5+
It will create a 43MB systemd libmusl container image with greengrass lite installed.
6+
7+
8+
## BUILDING
9+
10+
Init build environment
11+
12+
```bash
13+
. init-build-env
14+
```
15+
16+
Configure this image
17+
18+
```bash
19+
export IMAGE=aws-iot-greengrass-lite-container-demo-image
20+
```
21+
22+
Configure a device e.g. qemuarm64
23+
24+
```bash
25+
export DEVICE=qemuarm64
26+
```
27+
28+
Build
29+
30+
```bash
31+
bitbake $IMAGE
32+
```
33+
34+
You can run an interactive terminal like this - password root:root :
35+
36+
```bash
37+
podman run -it --arch arm64 oci:/home/ubuntu/data/meta-aws-demos/build/tmp/deploy/images/qemuarm64/aws-iot-greengrass-lite-container-demo-image-latest-oci/ /bin/bash
38+
```
39+
40+
This also works with fleetprovisioning, if certs are not in the docker image, you can mount them into the container e.g.:
41+
42+
```bash
43+
podman run -it --arch arm64 -v /host/path:/container/path oci:/home/ubuntu/data/meta-aws-demos/build/tmp/deploy/images/qemuarm64/aws-iot-greengrass-lite-container-demo-image-latest-oci/ /bin/bash
44+
```
45+
46+
To start and stop multiple instances of a container
47+
48+
```bash
49+
# Start 20 instances (see hitting a limit on issues):
50+
for i in {1..20}; do podman run -d --name greengrass-$i --arch arm64 oci:/home/ubuntu/data/meta-aws-demos/build/tmp/deploy/images/qemuarm64/aws-iot-greengrass-lite-container-demo-image-latest-oci/; done
51+
52+
# Stop all instances:
53+
podman stop $(podman ps -q --filter name=greengrass-)
54+
55+
# Remove all instances:
56+
podman rm $(podman ps -aq --filter name=greengrass-)
57+
58+
# attach to a instance a terminal
59+
podman exec -it greengrass-1 /bin/bash
60+
61+
# List all instances:
62+
podman ps --filter name=greengrass-
63+
64+
# Get detailed info with resource usage:
65+
podman stats --no-stream --filter name=greengrass-
66+
67+
# Show all container details:
68+
podman inspect greengrass-1
69+
70+
# Quick health check all instances:
71+
for i in {1..10}; do echo "=== greengrass-$i ==="; podman exec greengrass-$i ps aux | head -5; done
72+
73+
```
74+
75+
### how to detach from a instance?
76+
Press Ctrl+P then Ctrl+Q to detach from the container without stopping it.
77+
78+
79+
### hitting a limit in starting containers
80+
81+
```
82+
# Defines the maximum number of inotify listeners.
83+
# By default, this value is 128, which is quickly exhausted when using
84+
# systemd-based LXC containers (15 containers are enough).
85+
# When the limit is reached, systemd becomes mostly unusable, throwing
86+
# "Too many open files" all around (both on the host and in containers).
87+
# See https://kdecherf.com/blog/2015/09/12/systemd-and-the-fd-exhaustion/
88+
# Increase the user inotify instance limit to allow for about
89+
# 100 containers to run before the limit is hit again
90+
fs.inotify.max_user_instances = 1024
91+
So you should do the same by creating this file on the host. For immediate effect (on the host):
92+
93+
sysctl -w fs.inotify.max_user_instances=1024
94+
95+
or permanently add or change here: /etc/sysctl.conf
96+
fs.inotify.max_user_instances = 1024
97+
98+
```

meta-aws-demos/recipes-core/images/aws-iot-greengrass-lite-container-demo-image/aws-iot-greengrass-lite-container-demo-image.bb

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
SUMMARY = "A demo image for gg-lite as a container"
22
DESCRIPTION = "A small systemd system container which will run greengrass-lite."
33

4-
IMAGE_INSTALL += "packagegroup-core-boot ${CORE_IMAGE_EXTRA_INSTALL}"
5-
64
LICENSE = "MIT"
75
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
86

9-
IMAGE_FEATURES += "empty-root-password allow-empty-password allow-root-login serial-autologin-root"
7+
IMAGE_FEATURES += "empty-root-password allow-empty-password allow-root-login read-only-rootfs"
8+
IMAGE_FEATURES:remove = "package-management doc-pkgs"
9+
10+
# Remove locale data
11+
IMAGE_LINGUAS = ""
12+
13+
PACKAGE_CLASSES = "package_ipk"
14+
15+
IMAGE_INSTALL:append = " libcgroup"
16+
IMAGE_INSTALL:remove = " packagegroup-core-base-utils shadow shadow-base"
17+
IMAGE_INSTALL:remove = "openssh vim gawk iproute2 coreutils e2fsprogs-e2fsck e2fsprogs-mke2fs e2fsprogs-tune2fs perl"
18+
19+
# Force exclude packages
20+
PACKAGE_EXCLUDE += "coreutils vim gawk iproute2 e2fsprogs-e2fsck e2fsprogs-mke2fs e2fsprogs-tune2fs packagegroup-core-ssh-openssh"
1021

11-
IMAGE_INSTALL:append = " python3-misc python3-venv python3-tomllib python3-ensurepip libcgroup python3-pip"
22+
# Use minimal providers
23+
PREFERRED_PROVIDER_coreutils = "busybox"
24+
PREFERRED_PROVIDER_util-linux = "busybox"
1225
# Use local.conf to specify additional systemd services to disable. To overwrite
1326
# the default list use SERVICES_TO_DISABLE:pn-systemd-container in local.conf
1427
SERVICES_TO_DISABLE = "systemd-userdbd.service"
@@ -22,9 +35,13 @@ require container-systemd-base.inc
2235
SYSTEMD_CONTAINER_DISABLE_SERVICES += " \
2336
systemd-resolved.service \
2437
var-volatile.mount \
38+
systemd-udevd.service \
39+
systemd-hwdb-update.service \
40+
systemd-modules-load.service \
41+
systemd-vconsole-setup.service \
2542
"
2643

27-
IMAGE_INSTALL:append = " systemd-serialgetty systemd-extra-utils systemd-conf"
44+
IMAGE_INSTALL:append = " systemd-serialgetty systemd-conf"
2845
# resolvconf
2946

3047
OCI_IMAGE_ENTRYPOINT = "/sbin/init systemd.unified_cgroup_hierarchy=1"
@@ -36,3 +53,22 @@ IMAGE_INSTALL:append = " greengrass-lite"
3653

3754
# disable fleetprovisioning
3855
PACKAGECONFIG:pn-greengrass-lite = ""
56+
57+
# Disable unnecessary systemd features for containers
58+
PACKAGECONFIG:pn-systemd:remove = "backlight hibernate hostnamed localed machined networkd resolved rfkill timesyncd timedated vconsole"
59+
60+
# Set root password to "root"
61+
ROOTFS_POSTPROCESS_COMMAND += "set_root_passwd; remove_extra_files;"
62+
set_root_passwd() {
63+
echo 'root:root' | chpasswd -R ${IMAGE_ROOTFS}
64+
}
65+
66+
# Remove unnecessary files to reduce image size
67+
remove_extra_files() {
68+
rm -rf ${IMAGE_ROOTFS}/usr/share/common-licenses
69+
rm -rf ${IMAGE_ROOTFS}/usr/share/keymaps
70+
rm -rf ${IMAGE_ROOTFS}/usr/share/misc
71+
}
72+
73+
74+
IMAGE_INSTALL:append = " systemd systemd-serialgetty"
Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,80 @@
1-
DISTRO = "poky-altcfg"
1+
DISTRO = "poky"
22

3-
DISTRO_FEATURES:append = " virtualization"
3+
# note it is a hard overwrite
4+
DISTRO_FEATURES = "virtualization systemd usrmerge"
45

5-
# we do not want to have ptests in demo images enabled
6-
DISTRO_FEATURES:remove = " ptest"
6+
# OSPO license compliance
7+
BB_GENERATE_MIRROR_TARBALLS = "1"
8+
BB_GIT_SHALLOW = "1"
9+
BB_GENERATE_SHALLOW_TARBALLS = "1"
10+
INHERIT += "create-spdx"
11+
12+
TCLIBC = "musl"
13+
14+
FULL_OPTIMIZATION="-Os -pipe ${DEBUG_FLAGS}"
15+
16+
PACKAGE_CLASSES ?= "package_ipk"
17+
18+
VIRTUAL-RUNTIME_init_manager = "systemd"
19+
VIRTUAL-RUNTIME_initscripts = "systemd-compat-units"
20+
21+
# Disable wide char support for ncurses as we don't include it in
22+
# in the LIBC features below.
23+
# Leave native enable to avoid build failures
24+
ENABLE_WIDEC = "false"
25+
ENABLE_WIDEC:class-native = "true"
26+
27+
# Drop native language support. This removes the
28+
# eglibc->bash->gettext->libc-posix-clang-wchar dependency.
29+
USE_NLS="no"
30+
# As we don't have native language support, don't install locales into images
31+
IMAGE_LINGUAS = ""
32+
33+
# Drop v86d from qemu dependency list (we support serial)
34+
# Drop grub from meta-intel BSPs
35+
# FIXME: A different mechanism is needed here. We could define -tiny
36+
# variants of all compatible machines, but that leads to a lot
37+
# more machine configs to maintain long term.
38+
MACHINE_ESSENTIAL_EXTRA_RDEPENDS = ""
39+
40+
# The mtrace script included by eglibc is a perl script. ThPACKAGE_EXCLUDEis means the system
41+
# will build perl in case this package is installed. Since we don't care about
42+
# this script for the purposes of tiny, remove the dependency from here.
43+
RDEPENDS:${PN}-mtrace:pn-eglibc = ""
44+
45+
SKIP_RECIPE[build-appliance-image] = "not buildable with poky-tiny"
46+
SKIP_RECIPE[core-image-rt] = "not buildable with poky-tiny"
47+
SKIP_RECIPE[core-image-rt-sdk] = "not buildable with poky-tiny"
48+
SKIP_RECIPE[core-image-sato] = "not buildable with poky-tiny"
49+
SKIP_RECIPE[core-image-sato-dev] = "not buildable with poky-tiny"
50+
SKIP_RECIPE[core-image-sato-sdk] = "not buildable with poky-tiny"
51+
SKIP_RECIPE[core-image-x11] = "not buildable with poky-tiny"
52+
SKIP_RECIPE[core-image-weston] = "not buildable with poky-tiny"
53+
54+
# Disable python usage in opkg-utils since it won't build with tiny config
55+
PACKAGECONFIG:remove:pn-opkg-utils = "python"
56+
57+
NO_RECOMMENDATIONS = "1"
58+
59+
require conf/distro/include/gcsections.inc
60+
61+
# Distro config is evaluated after the machine config, so we have to explicitly
62+
# set the kernel provider to override a machine config.
63+
PREFERRED_PROVIDER_virtual/kernel = "linux-yocto-tiny"
64+
PREFERRED_VERSION_linux-yocto-tiny ?= "6.6%"
65+
66+
# We can use packagegroup-core-boot, but in the future we may need a new packagegroup-core-tiny
67+
#POKY_DEFAULT_EXTRA_RDEPENDS += "packagegroup-core-boot"
68+
# Drop kernel-module-af-packet from RRECOMMENDS
69+
POKY_DEFAULT_EXTRA_RRECOMMENDS = ""
70+
71+
# FIXME: what should we do with this?
72+
TCLIBCAPPEND = ""
73+
74+
# Drop native language support. This removes the
75+
# eglibc->bash->gettext->libc-posix-clang-wchar dependency.
76+
USE_NLS="no"
77+
78+
# remove
79+
# We need debug symbols so that SPDX license manifests for the kernel work
80+
KERNEL_EXTRA_FEATURES:remove = "features/debug/debug-kernel.scc"

0 commit comments

Comments
 (0)