Skip to content
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

Allow the user to use wrap as part of the bootstrap process #479

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions .github/workflows/bwrap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later

name: Run under bubblewrap
name: Run under (bubble)wrap

on:
workflow_dispatch:
Expand All @@ -13,10 +13,15 @@ on:

jobs:
pass1:
name: Run up to Linux build under bubblewrap
name: Run up to Linux build under (bubble)wrap
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
virt-tool: [bwrap, wrap]
steps:
- name: Install bubblewrap
if: matrix.virt-tool == 'bwrap'
run: sudo apt install bubblewrap
- name: Checkout repo
uses: actions/checkout@v3
Expand All @@ -43,7 +48,7 @@ jobs:
distfiles
key: cache-${{ hashFiles('steps/*/sources') }}
- name: Run bootstrap
run: ./rootfs.py --bwrap --external-sources --build-kernels --cores 2 --internal-ci pass1
run: ./rootfs.py --${{matrix.virt-tool}} --external-sources --build-kernels --cores 2 --internal-ci pass1
- name: Archive created packages
if: failure() # archive failed builds progress
uses: actions/upload-artifact@v3
Expand All @@ -55,15 +60,20 @@ jobs:
- name: Archive pass1_image
uses: actions/upload-artifact@v3
with:
name: internal_pass1_image
name: internal_pass1_image_${{matrix.virt-tool}}
path: pass1_image.tar

pass2:
name: Run up to Python bootstrap under bubblewrap
name: Run up to Python bootstrap under (bubble)wrap
needs: pass1
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
virt-tool: [bwrap, wrap]
steps:
- name: Install bubblewrap
if: matrix.virt-tool == 'bwrap'
run: sudo apt install bubblewrap
- name: Checkout repo
uses: actions/checkout@v3
Expand All @@ -75,7 +85,7 @@ jobs:
- name: Get pass1_image
uses: actions/download-artifact@v3
with:
name: internal_pass1_image
name: internal_pass1_image_${{matrix.virt-tool}}
- name: Extract pass1_image
run: tar -xf pass1_image.tar
- name: Query cache for sources
Expand All @@ -96,7 +106,7 @@ jobs:
distfiles
key: cache-${{ hashFiles('steps/*/sources') }}
- name: Run bootstrap
run: ./rootfs.py --bwrap --external-sources --build-kernels --cores 2 --internal-ci pass2
run: ./rootfs.py --${{matrix.virt-tool}} --external-sources --build-kernels --cores 2 --internal-ci pass2
- name: Archive created packages
if: failure() # archive failed builds progress
uses: actions/upload-artifact@v3
Expand All @@ -108,15 +118,20 @@ jobs:
- name: Archive pass2_image
uses: actions/upload-artifact@v3
with:
name: internal_pass2_image
name: internal_pass2_image_${{matrix.virt-tool}}
path: pass2_image.tar

pass3:
name: Run remaining builds under bubblewrap
name: Run remaining builds under (bubble)wrap
needs: pass2
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
virt-tool: [bwrap, wrap]
steps:
- name: Install bubblewrap
if: matrix.virt-tool == 'bwrap'
run: sudo apt install bubblewrap
- name: Checkout repo
uses: actions/checkout@v3
Expand All @@ -128,7 +143,7 @@ jobs:
- name: Get pass2_image
uses: actions/download-artifact@v3
with:
name: internal_pass2_image
name: internal_pass2_image_${{matrix.virt-tool}}
- name: Extract pass2_image
run: tar -xf pass2_image.tar
- name: Query cache for sources
Expand All @@ -149,10 +164,10 @@ jobs:
distfiles
key: cache-${{ hashFiles('steps/*/sources') }}
- name: Run bootstrap
run: ./rootfs.py --bwrap --external-sources --build-kernels --cores 2 --internal-ci pass3
run: ./rootfs.py --${{matrix.virt-tool}} --external-sources --build-kernels --cores 2 --internal-ci pass3
- name: Archive created packages
if: always() # archive both failed and successful builds
uses: actions/upload-artifact@v3
with:
name: packages
name: packages_${{matrix.virt-tool}}
path: target/external/repo/**
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ Source: https://github.com/fosslinux/live-bootstrap
# Copyright: $YEAR $NAME <$CONTACT>
# License: ...

Files: steps/*/sources steps/*/*.checksums steps/SHA256SUMS.pkgs steps/*/simple-patches/* seed/*.checksums
Files: steps/*/sources steps/*/*.checksums steps/SHA256SUMS.pkgs steps/*/simple-patches/* seed/*.checksums seed/wrap-bootstrap.cfg
Copyright: none
License: MIT
17 changes: 14 additions & 3 deletions lib/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ def reuse(self, target):
self.external_dir = os.path.join(self.target_dir, 'external')
self.distfiles()

def prepare(self, target, using_kernel=False, kernel_bootstrap=False, target_size=0):
# pylint: disable=too-many-arguments
def prepare(self,
target,
using_kernel=False,
kernel_bootstrap=False,
wrap=False,
target_size=0):
"""
Prepare basic media of live-bootstrap.
/steps -- contains steps to be built
Expand Down Expand Up @@ -82,7 +88,7 @@ def prepare(self, target, using_kernel=False, kernel_bootstrap=False, target_siz
os.path.join(self.target_dir, 'kaem.x86'))
else:
self.stage0_posix(kernel_bootstrap)
self.seed()
self.seed(wrap)

os.makedirs(self.external_dir)

Expand Down Expand Up @@ -134,12 +140,17 @@ def stage0_posix(self, kernel_bootstrap=False):
'kaem-optional-seed')
shutil.copy2(kaem_optional_seed, os.path.join(self.target_dir, 'init'))

def seed(self):
def seed(self, wrap):
"""Copy in extra seed files"""
seed_dir = os.path.join(self.git_dir, 'seed')
for entry in os.listdir(seed_dir):
if os.path.isfile(os.path.join(seed_dir, entry)):
shutil.copy2(os.path.join(seed_dir, entry), os.path.join(self.target_dir, entry))
if wrap:
shutil.copy2(os.path.join(seed_dir, 'after-wrap.kaem'),
os.path.join(self.target_dir, 'after.kaem'))
shutil.copy2(os.path.join(seed_dir, 'after.kaem'),
os.path.join(self.target_dir, 'after-wrapped.kaem'))
Comment on lines +149 to +153
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to try to avoid having conditional logic in generator.py. Is there some reason this needs to be here, and can't occur within the live-bootstrap environment?

Ie, there would be conditional logic in after.kaem for wrap mode, by adding in some kind of WRAP=True into bootstrap.cfg, rather than replacing the kaem files like this.


def distfiles(self):
"""Copy in distfiles"""
Expand Down
24 changes: 20 additions & 4 deletions rootfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def create_configuration_file(args):
config.write(f"ARCH={args.arch}\n")
config.write(f"ARCH_DIR={stage0_arch_map.get(args.arch, args.arch)}\n")
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.wrap}\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")
Expand Down Expand Up @@ -63,6 +63,8 @@ def main():
default="x86")
parser.add_argument("-c", "--chroot", help="Run inside chroot",
action="store_true")
parser.add_argument("-w", "--wrap", help="Run inside a minimal sandbox",
action="store_true")
parser.add_argument("-bw", "--bwrap", help="Run inside a bwrap sandbox",
action="store_true")
parser.add_argument("-t", "--target", help="Target directory",
Expand Down Expand Up @@ -127,15 +129,18 @@ def check_types():
count += 1
if args.bwrap:
count += 1
if args.wrap:
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"
"may be used.")
raise ValueError("No more than one of qemu, chroot, bwrap, wrap, 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, wrap, or bare metal must"
" be selected.")

# Arch validation
if args.arch != "x86":
Expand Down Expand Up @@ -237,6 +242,17 @@ def bootstrap(args, generator, target, size):
'--tmpfs', '/tmp',
init)

elif args.wrap:
arch = stage0_arch_map.get(args.arch, args.arch)
if not args.internal_ci or args.internal_ci == "pass1":
generator.prepare(target, wrap = True)
arg_list = [os.path.join('bootstrap-seeds', 'POSIX', arch, 'kaem-optional-seed')]
else:
generator.reuse(target)
arg_list = [os.path.join(arch, 'bin', 'wrap'), '/init']

run(*arg_list, cwd = generator.target_dir)

elif args.bare_metal:
if args.kernel:
generator.prepare(target, using_kernel=True, target_size=size)
Expand Down
19 changes: 19 additions & 0 deletions seed/after-wrap.kaem
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

# SPDX-FileCopyrightText: 2024 Max Hearnden maxoscarhearnden@gmail.com
#
# SPDX-License-Identifier: GPL-3.0-or-later

set -ex

# detect wether we are in a rootfs.py environment
if ./${ARCH_DIR}/bin/catm steps/env-saved steps/env; then
./${ARCH_DIR}/bin/wrap /${ARCH_DIR}/bin/kaem --file after-wrapped.kaem
else
# leave seed/stage0-posix
cd ../..

ARCH_DIR=seed/stage0-posix/${ARCH_DIR}

./${ARCH_DIR}/bin/wrap /${ARCH_DIR}/bin/kaem --file seed/after.kaem
fi
15 changes: 14 additions & 1 deletion seed/after.kaem
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,18 @@ set -ex

PATH=/${ARCH_DIR}/bin

catm seed-full.kaem /steps/bootstrap.cfg /steps/env seed.kaem
if catm seed-full.kaem /steps/bootstrap.cfg /steps/env seed.kaem; then
else
replace --file /steps/env --output /steps/env --match-on /external/distfiles --replace-with /distfiles
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is /distfiles being reintroduced?

cp /seed/wrap-bootstrap.cfg /steps/bootstrap.cfg
catm seed-full.kaem /steps/bootstrap.cfg /steps/env /seed/seed.kaem
cp /seed/configurator.c configurator.c
cp /seed/configurator.${ARCH}.checksums configurator.${ARCH}.checksums

cp /seed/script-generator.c script-generator.c
cp /seed/script-generator.${ARCH}.checksums script-generator.${ARCH}.checksums
# placeholder value
FINAL_JOBS=1
fi

kaem --file seed-full.kaem
7 changes: 6 additions & 1 deletion seed/seed.kaem
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ MES_PKG=mes-0.27
MES_PREFIX=${SRCDIR}/${MES_PKG}/build/${MES_PKG}
GUILE_LOAD_PATH=${MES_PREFIX}/mes/module:${MES_PREFIX}/module:${SRCDIR}/${MES_PKG}/build/${NYACC_PKG}/module

M2-Mesoplanet --architecture ${ARCH} -f configurator.c -o configurator
if M2-Mesoplanet --architecture ${ARCH} -f configurator.c -o configurator; then
else
# using lightweight wrapper
M2LIBC_PATH=/seed/stage0-posix/M2libc
M2-Mesoplanet --architecture ${ARCH} -f configurator.c -o configurator
fi
# Checksums
if match x${UPDATE_CHECKSUMS} xTrue; then
sha256sum -o configurator.${ARCH}.checksums configurator
Expand Down
5 changes: 5 additions & 0 deletions seed/wrap-bootstrap.cfg
fosslinux marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CHROOT=True
DISK=sda1
KERNEL_BOOTSTRAP=False
BUILD_KERNELS=False
JOBS=${FINAL_JOBS}
4 changes: 4 additions & 0 deletions steps/improve/merged_usr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
# Add the rest of the FHS that we will use and is not created pre-boot
ln -s bin /usr/sbin
for d in bin lib sbin; do
if [ -d "/${d}" ] && ! [ -L "/${d}" ]; then
# Move the non symlink directory out of the way
mv "/${d}" "/${d}-saved"
fi
Comment on lines +9 to +12
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm reading the commit description where this was introduced but still cannot figure out why this was added.

If I'm understanding the commit, my best guess is because the entire git repository is being copied into target, but I'm not sure why that is desirable either (not a supported running method)

ln -s "usr/${d}" "/${d}" || true # these might exist if rerunning
done
2 changes: 1 addition & 1 deletion steps/improve/setup_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
#
mkdir -p /external/repo

tar -cf - --exclude='/external/repo/*' --exclude='/external/repo-preseeded/*' --exclude='/external/distfiles/*' --exclude='/dev/*' --exclude='/proc/*' --exclude='/sys/*' --exclude='/tmp/*' / | bzip2 --best > /external/repo/base.tar.bz2
tar -cf - --exclude='/external/repo/*' --exclude='/external/repo-preseeded/*' --exclude='/external/distfiles/*' --exclude='/distfiles/*' --exclude='/dev/*' --exclude='/proc/*' --exclude='/sys/*' --exclude='/tmp/*' / | bzip2 --best > /external/repo/base.tar.bz2
Loading