From 7cfeddf82d86759ce6ef37d9b41c40d19c8a5fa3 Mon Sep 17 00:00:00 2001 From: "Lance R. Vick" Date: Sat, 13 Jan 2024 12:36:12 -0800 Subject: [PATCH 1/5] initial docker build support --- Dockerfile | 13 +++++++++++++ rootfs.py | 20 +++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..8215dc19 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM local/stage0 as stage0 + +FROM debian as fetch +RUN apt update && apt install -y curl gcc +ADD . live-bootstrap +WORKDIR live-bootstrap +RUN ./download-distfiles.sh +RUN mv target/ /rootfs/ + +FROM scratch as build +COPY --from=fetch /rootfs . +ENV PATH=/bin +RUN ["/bootstrap-seeds/POSIX/x86/kaem-optional-seed"] diff --git a/rootfs.py b/rootfs.py index a6e2419f..2369d201 100755 --- a/rootfs.py +++ b/rootfs.py @@ -29,7 +29,7 @@ def create_configuration_file(args): config_path = os.path.join('steps', 'bootstrap.cfg') with open(config_path, "w", encoding="utf_8") as config: config.write(f"FORCE_TIMESTAMPS={args.force_timestamps}\n") - config.write(f"CHROOT={args.chroot or args.bwrap}\n") + config.write(f"CHROOT={args.chroot or args.bwrap or args.docker}\n") config.write(f"UPDATE_CHECKSUMS={args.update_checksums}\n") config.write(f"JOBS={args.cores}\n") config.write(f"SWAP_SIZE={args.swap}\n") @@ -62,6 +62,8 @@ def main(): action="store_true") parser.add_argument("-bw", "--bwrap", help="Run inside a bwrap sandbox", action="store_true") + parser.add_argument("-do", "--docker", help="Run inside a docker build", + action="store_true") parser.add_argument("-t", "--target", help="Target directory", default="target") parser.add_argument("--tmpfs", help="Use a tmpfs on target", @@ -121,15 +123,17 @@ def check_types(): count += 1 if args.bwrap: count += 1 + if args.docker: + count += 1 if args.bare_metal: count += 1 return count if check_types() > 1: - raise ValueError("No more than one of qemu, chroot, bwrap, bare metal" + raise ValueError("No more than one of qemu, chroot, bwrap, docker, bare metal" "may be used.") if check_types() == 0: - raise ValueError("One of qemu, chroot, bwrap, or bare metal must be selected.") + raise ValueError("One of qemu, chroot, bwrap, docker, or bare metal must be selected.") # Arch validation if args.arch != "x86": @@ -199,6 +203,16 @@ def bootstrap(args, generator, target, size): init = os.path.join(os.sep, 'bootstrap-seeds', 'POSIX', arch, 'kaem-optional-seed') run_as_root('env', '-i', 'PATH=/bin', chroot_binary, generator.target_dir, init) + elif args.docker: + generator.prepare(target, using_kernel=False) + arch = stage0_arch_map.get(args.arch, args.arch) + init = os.path.join(os.sep, 'bootstrap-seeds', 'POSIX', arch, 'kaem-optional-seed') + print(generator.target_dir, init) + run('env', '-i', 'DOCKER_BUILDKIT=1', 'docker', 'build', + '--progress=plain', + '-t', 'local/live', + '.') + elif args.bwrap: init = '/init' if not args.internal_ci or args.internal_ci == "pass1": From 4ebd0b605c8e5878438357f54e3de6e0db6d7eff Mon Sep 17 00:00:00 2001 From: fosslinux Date: Sat, 13 Jan 2024 18:27:36 -0800 Subject: [PATCH 2/5] external sources arg --- rootfs.py | 1 + steps/improve/finalize_fhs.sh | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/rootfs.py b/rootfs.py index 2369d201..074169c5 100755 --- a/rootfs.py +++ b/rootfs.py @@ -37,6 +37,7 @@ def create_configuration_file(args): config.write(f"INTERNAL_CI={args.internal_ci or False}\n") config.write(f"INTERACTIVE={args.interactive}\n") config.write(f"BARE_METAL={args.bare_metal}\n") + config.write(f"EXTERNAL_SOURCES={args.external_sources}\n") if (args.bare_metal or args.qemu) and not args.kernel: if args.repo or args.external_sources: config.write("DISK=sdb1\n") diff --git a/steps/improve/finalize_fhs.sh b/steps/improve/finalize_fhs.sh index e2a238d8..517cddab 100755 --- a/steps/improve/finalize_fhs.sh +++ b/steps/improve/finalize_fhs.sh @@ -23,6 +23,8 @@ mount | grep '/sys' &> /dev/null || (mkdir -p /sys; mount -t sysfs sysfs /sys) mount | grep '/tmp' &> /dev/null || (mkdir -p /tmp; mount -t tmpfs tmpfs /tmp) mount | grep '/dev/shm' &> /dev/null || (mkdir -p /dev/shm; mount -t tmpfs tmpfs /dev/shm) -# Add /etc/resolv.conf -echo 'nameserver 1.1.1.1' > /etc/resolv.conf -echo 'nameserver 1.1.1.1' > /etc/resolv.conf.head +if [ "${EXTERNAL_SOURCES}" = "False" ]; then + # Add /etc/resolv.conf + echo 'nameserver 1.1.1.1' > /etc/resolv.conf + echo 'nameserver 1.1.1.1' > /etc/resolv.conf.head +fi From fc6eeb6bd75ea0d0025a79ea9fe45614bd60ba14 Mon Sep 17 00:00:00 2001 From: "Lance R. Vick" Date: Mon, 15 Jan 2024 22:16:40 -0800 Subject: [PATCH 3/5] deterministic docker support --- .dockerignore | 2 ++ Dockerfile | 33 ++++++++++++++++++++++----------- rootfs.py | 11 +++++++++-- 3 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..50365994 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +* +!target diff --git a/Dockerfile b/Dockerfile index 8215dc19..1d47d90f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,24 @@ -FROM local/stage0 as stage0 - -FROM debian as fetch -RUN apt update && apt install -y curl gcc -ADD . live-bootstrap -WORKDIR live-bootstrap -RUN ./download-distfiles.sh -RUN mv target/ /rootfs/ - FROM scratch as build -COPY --from=fetch /rootfs . -ENV PATH=/bin +ADD target/ / RUN ["/bootstrap-seeds/POSIX/x86/kaem-optional-seed"] + +FROM build as install +ENV PATH=/bin:/usr/sbin:/usr/bin +RUN set -eux; \ + rm -rf /usr/lib/python*/__pycache__; \ + mkdir -p /rootfs/etc /rootfs/home/user; \ + cp -R $(ls -d /etc/* | grep -v '\(resolv.conf\|hosts\)') /rootfs/etc/; \ + cp -R lib usr bin var /rootfs/; \ + echo "user:x:1000:" > /rootfs/etc/group; \ + echo "user:x:1000:1000::/home/user:/bin/bash" > /rootfs/etc/passwd; \ + find /rootfs -exec touch -hcd "@0" "{}" + + +FROM scratch as package +COPY --from=install /rootfs / +USER 1000:1000 +ENTRYPOINT ["/bin/bash"] +ENV TZ=UTC +ENV LANG=C.UTF-8 +ENV SOURCE_DATE_EPOCH=1 +ENV KCONFIG_NOTIMESTAMP=1 +ENV PS1="bootstrap$ " diff --git a/rootfs.py b/rootfs.py index 074169c5..d620d5ac 100755 --- a/rootfs.py +++ b/rootfs.py @@ -157,6 +157,9 @@ def check_types(): else: args.target_size = 0 + if args.docker: + args.external_sources = True + # Swap file size validation if args.qemu or args.bare_metal: args.swap = (int(str(args.swap).rstrip('gGmM')) * @@ -209,9 +212,13 @@ def bootstrap(args, generator, target, size): arch = stage0_arch_map.get(args.arch, args.arch) init = os.path.join(os.sep, 'bootstrap-seeds', 'POSIX', arch, 'kaem-optional-seed') print(generator.target_dir, init) - run('env', '-i', 'DOCKER_BUILDKIT=1', 'docker', 'build', + run('env', '-i', 'DOCKER_BUILDKIT=1', 'SOURCE_DATE_EPOCH=1', + 'docker', 'build', + '--build-arg=SOURCE_DATE_EPOCH=1', '--progress=plain', - '-t', 'local/live', + '--platform=linux/amd64', + '--target=package', + '-t', 'local/live-bootstrap', '.') elif args.bwrap: From fc1dcacd6e550b0741241ff3b25607e277c33c2d Mon Sep 17 00:00:00 2001 From: "Lance R. Vick" Date: Wed, 24 Jan 2024 16:02:54 -0800 Subject: [PATCH 4/5] use long options for docker --- rootfs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootfs.py b/rootfs.py index d620d5ac..42d624e3 100755 --- a/rootfs.py +++ b/rootfs.py @@ -218,7 +218,7 @@ def bootstrap(args, generator, target, size): '--progress=plain', '--platform=linux/amd64', '--target=package', - '-t', 'local/live-bootstrap', + '--tag', 'local/live-bootstrap', '.') elif args.bwrap: From 2408b8e6418008568134d7b1c8c334cf226fc216 Mon Sep 17 00:00:00 2001 From: "Lance R. Vick" Date: Wed, 24 Jan 2024 16:58:46 -0800 Subject: [PATCH 5/5] License headers --- .dockerignore | 6 +++++- Dockerfile | 4 ++++ rootfs.py | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index 50365994..69dc4014 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,6 @@ -* +# SPDX-FileCopyrightText: 2024 Lance Vick +# +# SPDX-License-Identifier: GPL-3.0-or-later + + !target diff --git a/Dockerfile b/Dockerfile index 1d47d90f..4742fdba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2024 Lance Vick +# +# SPDX-License-Identifier: GPL-3.0-or-later + FROM scratch as build ADD target/ / RUN ["/bootstrap-seeds/POSIX/x86/kaem-optional-seed"] diff --git a/rootfs.py b/rootfs.py index 42d624e3..fc910835 100755 --- a/rootfs.py +++ b/rootfs.py @@ -13,6 +13,7 @@ # SPDX-FileCopyrightText: 2021 Melg Eight # SPDX-FileCopyrightText: 2021-23 fosslinux # SPDX-FileCopyrightText: 2023-24 Gábor Stefanik +# SPDX-FileCopyrightText: 2024 Lance Vick import argparse import os