-
Notifications
You must be signed in to change notification settings - Fork 44
docker build support #413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
docker build support #413
Changes from all commits
7cfeddf
4ebd0b6
fc6eeb6
7b1a775
fc1dcac
2408b8e
87c6fcc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# SPDX-FileCopyrightText: 2024 Lance Vick <lance@vick.house> | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
|
||
!target |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# SPDX-FileCopyrightText: 2024 Lance Vick <lance@vick.house> | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
FROM scratch as build | ||
ADD target/ / | ||
RUN ["/bootstrap-seeds/POSIX/x86/kaem-optional-seed"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass "arch" from bootstrap() here, if possible, rather than hardcoding "x86". |
||
|
||
FROM build as install | ||
ENV PATH=/bin:/usr/sbin:/usr/bin | ||
RUN set -eux; \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the inclusion of the "x" flag intentional here, or just leftover from debugging? |
||
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$ " |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
# SPDX-FileCopyrightText: 2021 Melg Eight <public.melg8@gmail.com> | ||
# SPDX-FileCopyrightText: 2021-23 fosslinux <fosslinux@aussies.space> | ||
# SPDX-FileCopyrightText: 2023-24 Gábor Stefanik <netrolller.3d@gmail.com> | ||
# SPDX-FileCopyrightText: 2024 Lance Vick <lance@vick.house> | ||
|
||
import argparse | ||
import os | ||
|
@@ -29,14 +30,15 @@ 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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not something that needs changing in this PR, but in the future, we might want to rename this variable to something more descriptive, like USERSPACE_ONLY (especially if/when I go through with adding the WSL bootstrap mode I'm planning). |
||
config.write(f"UPDATE_CHECKSUMS={args.update_checksums}\n") | ||
config.write(f"JOBS={args.cores}\n") | ||
config.write(f"SWAP_SIZE={args.swap}\n") | ||
config.write(f"FINAL_JOBS={args.cores}\n") | ||
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") | ||
|
@@ -62,6 +64,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 +125,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": | ||
|
@@ -152,6 +158,9 @@ def check_types(): | |
else: | ||
args.target_size = 0 | ||
|
||
if args.docker: | ||
args.external_sources = True | ||
|
||
Comment on lines
+161
to
+163
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this? |
||
# Swap file size validation | ||
if args.qemu or args.bare_metal: | ||
args.swap = (int(str(args.swap).rstrip('gGmM')) * | ||
|
@@ -202,6 +211,20 @@ 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leftover debug print |
||
run('env', '-i', 'DOCKER_BUILDKIT=1', 'SOURCE_DATE_EPOCH=1', | ||
'docker', 'build', | ||
'--build-arg=SOURCE_DATE_EPOCH=1', | ||
'--progress=plain', | ||
'--platform=linux/amd64', | ||
'--target=package', | ||
'--tag', 'local/live-bootstrap', | ||
'.') | ||
|
||
elif args.bwrap: | ||
init = '/init' | ||
if not args.internal_ci or args.internal_ci == "pass1": | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass target directory from bootstrap() here, if possible, rather than hardcoding "target".