Skip to content

Commit 81790a3

Browse files
authored
Merge pull request #361 from Googulator/fix-bwrap
Fix bubblewrap support & CI workflows after simplify
2 parents 3fd101e + fe9cb12 commit 81790a3

File tree

6 files changed

+124
-93
lines changed

6 files changed

+124
-93
lines changed

.github/workflows/bwrap.yml

Lines changed: 71 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ on:
1212
- master
1313

1414
jobs:
15-
sysa:
16-
name: Run sysa under bubblewrap
15+
pass1:
16+
name: Run up to Linux build under bubblewrap
1717
runs-on: ubuntu-latest
1818
steps:
1919
- name: Install bubblewrap
@@ -30,9 +30,8 @@ jobs:
3030
uses: actions/cache/restore@v3
3131
with:
3232
path: |
33-
sysa/distfiles
34-
sysc/distfiles
35-
key: cache-${{ hashFiles('sys*/*/sources') }}
33+
distfiles
34+
key: cache-${{ hashFiles('steps/*/sources') }}
3635
- name: Get sources
3736
if: steps.cache.outputs.cache-hit != 'true'
3837
run: ./download-distfiles.sh
@@ -41,28 +40,27 @@ jobs:
4140
uses: actions/cache/save@v3
4241
with:
4342
path: |
44-
sysa/distfiles
45-
sysc/distfiles
46-
key: cache-${{ hashFiles('sys*/*/sources') }}
43+
distfiles
44+
key: cache-${{ hashFiles('steps/*/sources') }}
4745
- name: Run bootstrap
4846
run: ./rootfs.py --bwrap --external-sources --build-kernels --preserve --cores 2 --internal-ci pass1
4947
- name: Archive created packages
5048
if: failure() # archive failed builds progress
5149
uses: actions/upload-artifact@v3
5250
with:
5351
name: packages
54-
path: tmp/sysa/usr/src/repo/**
55-
- name: Tar sysc_image
56-
run: tar -cf sysc_image.tar tmp/sysa/sysc_image/
57-
- name: Archive sysc_image
52+
path: tmp/external/repo/**
53+
- name: Tar pass1 image
54+
run: tar -cf pass1_image.tar tmp
55+
- name: Archive pass1_image
5856
uses: actions/upload-artifact@v3
5957
with:
60-
name: internal_sysc_image
61-
path: sysc_image.tar
58+
name: internal_pass1_image
59+
path: pass1_image.tar
6260

63-
sysc1:
64-
name: Run sysc (part 1) under bubblewrap
65-
needs: sysa
61+
pass2:
62+
name: Run up to Python bootstrap under bubblewrap
63+
needs: pass1
6664
runs-on: ubuntu-latest
6765
steps:
6866
- name: Install bubblewrap
@@ -74,24 +72,48 @@ jobs:
7472
# There is a strange bug(?) in nongnu, when you clone a git repository
7573
# against a commit != HEAD with depth=1, it errors out.
7674
fetch-depth: 0
77-
- name: Get sysc_image
75+
- name: Get pass1_image
7876
uses: actions/download-artifact@v3
7977
with:
80-
name: internal_sysc_image
81-
- name: Extract sysc_image
82-
run: tar -xf sysc_image.tar
78+
name: internal_pass1_image
79+
- name: Extract pass1_image
80+
run: tar -xf pass1_image.tar
81+
- name: Query cache for sources
82+
id: cache
83+
uses: actions/cache/restore@v3
84+
with:
85+
path: |
86+
distfiles
87+
key: cache-${{ hashFiles('steps/*/sources') }}
88+
- name: Get sources
89+
if: steps.cache.outputs.cache-hit != 'true'
90+
run: ./download-distfiles.sh
91+
- name: Cache sources
92+
if: steps.cache.outputs.cache-hit != 'true'
93+
uses: actions/cache/save@v3
94+
with:
95+
path: |
96+
distfiles
97+
key: cache-${{ hashFiles('steps/*/sources') }}
8398
- name: Run bootstrap
8499
run: ./rootfs.py --bwrap --external-sources --build-kernels --preserve --cores 2 --internal-ci pass2
85100
- name: Archive created packages
86-
if: always() # archive failed builds progress
101+
if: failure() # archive failed builds progress
87102
uses: actions/upload-artifact@v3
88103
with:
89-
name: internal_packages_sysc1
90-
path: tmp/sysa/sysc_image/usr/src/repo/**
104+
name: internal_packages_pass2
105+
path: tmp/external/repo/**
106+
- name: Tar pass2 image
107+
run: tar -cf pass2_image.tar tmp
108+
- name: Archive pass2_image
109+
uses: actions/upload-artifact@v3
110+
with:
111+
name: internal_pass2_image
112+
path: pass2_image.tar
91113

92-
sysc2:
93-
name: Run sysc (part 2) under bubblewrap
94-
needs: sysc1
114+
pass3:
115+
name: Run remaining builds under bubblewrap
116+
needs: pass2
95117
runs-on: ubuntu-latest
96118
steps:
97119
- name: Install bubblewrap
@@ -103,23 +125,34 @@ jobs:
103125
# There is a strange bug(?) in nongnu, when you clone a git repository
104126
# against a commit != HEAD with depth=1, it errors out.
105127
fetch-depth: 0
106-
- name: Get sysc_image
128+
- name: Get pass2_image
107129
uses: actions/download-artifact@v3
108130
with:
109-
name: internal_sysc_image
110-
- name: Extract sysc_image
111-
run: tar -xf sysc_image.tar
112-
# By doing this, all packages that have already been compiled will come from the preseed.
113-
- name: Get packages repo progress
114-
uses: actions/download-artifact@v3
131+
name: internal_pass2_image
132+
- name: Extract pass2_image
133+
run: tar -xf pass2_image.tar
134+
- name: Query cache for sources
135+
id: cache
136+
uses: actions/cache/restore@v3
137+
with:
138+
path: |
139+
distfiles
140+
key: cache-${{ hashFiles('steps/*/sources') }}
141+
- name: Get sources
142+
if: steps.cache.outputs.cache-hit != 'true'
143+
run: ./download-distfiles.sh
144+
- name: Cache sources
145+
if: steps.cache.outputs.cache-hit != 'true'
146+
uses: actions/cache/save@v3
115147
with:
116-
name: internal_packages_sysc1
117-
path: tmp/sysa/sysc_image/usr/src/repo-preseeded/
148+
path: |
149+
distfiles
150+
key: cache-${{ hashFiles('steps/*/sources') }}
118151
- name: Run bootstrap
119152
run: ./rootfs.py --bwrap --external-sources --build-kernels --preserve --cores 2 --internal-ci pass3
120153
- name: Archive created packages
121-
if: always() # archive failed builds
154+
if: always() # archive both failed and successful builds
122155
uses: actions/upload-artifact@v3
123156
with:
124157
name: packages
125-
path: tmp/sysa/sysc_image/usr/src/repo/**
158+
path: tmp/external/repo/**

lib/generator.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ def __init__(self, arch, external_sources, early_preseed, repo_path):
3232
self.tmp_dir = None
3333
self.external_dir = None
3434

35+
def reuse(self, tmpdir):
36+
"""
37+
Reuse a previously prepared bwrap environment for further stages.
38+
"""
39+
self.tmp_dir = tmpdir.path
40+
self.external_dir = os.path.join(self.tmp_dir, 'external')
41+
self.distfiles()
42+
3543
def prepare(self, tmpdir, using_kernel=False, kernel_bootstrap=False, target_size=0):
3644
"""
3745
Prepare basic media of live-bootstrap.
@@ -166,11 +174,11 @@ def copy_no_network_distfiles(out):
166174
main_distfile_dir = os.path.join(self.external_dir, 'distfiles')
167175

168176
if early_distfile_dir != main_distfile_dir:
169-
os.makedirs(early_distfile_dir)
177+
os.makedirs(early_distfile_dir, exist_ok=True)
170178
copy_no_network_distfiles(early_distfile_dir)
171179

172180
if self.external_sources:
173-
shutil.copytree(self.distfiles_dir, main_distfile_dir)
181+
shutil.copytree(self.distfiles_dir, main_distfile_dir, dirs_exist_ok=True)
174182
else:
175183
os.mkdir(main_distfile_dir)
176184
copy_no_network_distfiles(main_distfile_dir)

rootfs.py

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import argparse
1717
import os
18-
import shutil
1918

2019
from lib.utils import run, run_as_root
2120
from lib.tmpdir import Tmpdir
@@ -32,7 +31,7 @@ def create_configuration_file(args):
3231
config.write(f"CHROOT={args.chroot or args.bwrap}\n")
3332
config.write(f"UPDATE_CHECKSUMS={args.update_checksums}\n")
3433
config.write(f"JOBS={args.cores}\n")
35-
config.write(f"INTERNAL_CI={args.internal_ci}\n")
34+
config.write(f"INTERNAL_CI={args.internal_ci or False}\n")
3635
config.write(f"BARE_METAL={args.bare_metal}\n")
3736
if (args.bare_metal or args.qemu) and not args.kernel:
3837
if args.repo or args.external_sources:
@@ -187,50 +186,33 @@ def bootstrap(args, generator, tmpdir, size):
187186
run_as_root('env', '-i', 'PATH=/bin', chroot_binary, generator.tmp_dir, init)
188187

189188
elif args.bwrap:
189+
init = '/init'
190190
if not args.internal_ci or args.internal_ci == "pass1":
191191
generator.prepare(tmpdir, using_kernel=False)
192192

193193
arch = stage0_arch_map.get(args.arch, args.arch)
194194
init = os.path.join(os.sep, 'bootstrap-seeds', 'POSIX', arch, 'kaem-optional-seed')
195-
run('bwrap', '--unshare-user',
196-
'--uid', '0',
197-
'--gid', '0',
198-
'--unshare-net',
199-
'--clearenv',
200-
'--setenv', 'PATH', '/usr/bin',
201-
'--bind', generator.tmp_dir, '/',
202-
'--dir', '/dev',
203-
'--dev-bind', '/dev/null', '/dev/null',
204-
'--dev-bind', '/dev/zero', '/dev/zero',
205-
'--dev-bind', '/dev/random', '/dev/random',
206-
'--dev-bind', '/dev/urandom', '/dev/urandom',
207-
'--dev-bind', '/dev/ptmx', '/dev/ptmx',
208-
'--dev-bind', '/dev/tty', '/dev/tty',
209-
init)
195+
else:
196+
generator.reuse(tmpdir)
210197

211-
if not args.internal_ci or args.internal_ci == "pass2" or args.internal_ci == "pass3":
212-
os.makedirs(os.path.join(generator.tmp_dir, 'stage2', 'steps'), exist_ok=True)
213-
shutil.copy2(os.path.join('steps', 'bootstrap.cfg'),
214-
os.path.join(generator.tmp_dir, 'stage2', 'steps', 'bootstrap.cfg'))
215-
run('bwrap', '--unshare-user',
216-
'--uid', '0',
217-
'--gid', '0',
218-
'--unshare-net' if args.external_sources else None,
219-
'--clearenv',
220-
'--setenv', 'PATH', '/usr/bin',
221-
'--bind', os.path.join(generator.tmp_dir, "stage2"), '/',
222-
'--dir', '/dev',
223-
'--dev-bind', '/dev/null', '/dev/null',
224-
'--dev-bind', '/dev/zero', '/dev/zero',
225-
'--dev-bind', '/dev/random', '/dev/random',
226-
'--dev-bind', '/dev/urandom', '/dev/urandom',
227-
'--dev-bind', '/dev/ptmx', '/dev/ptmx',
228-
'--dev-bind', '/dev/tty', '/dev/tty',
229-
'--tmpfs', '/dev/shm',
230-
'--proc', '/proc',
231-
'--bind', '/sys', '/sys',
232-
'--tmpfs', '/tmp',
233-
'/init')
198+
run('env', '-i', 'bwrap', '--unshare-user',
199+
'--uid', '0',
200+
'--gid', '0',
201+
'--unshare-net' if args.external_sources else None,
202+
'--setenv', 'PATH', '/usr/bin',
203+
'--bind', generator.tmp_dir, '/',
204+
'--dir', '/dev',
205+
'--dev-bind', '/dev/null', '/dev/null',
206+
'--dev-bind', '/dev/zero', '/dev/zero',
207+
'--dev-bind', '/dev/random', '/dev/random',
208+
'--dev-bind', '/dev/urandom', '/dev/urandom',
209+
'--dev-bind', '/dev/ptmx', '/dev/ptmx',
210+
'--dev-bind', '/dev/tty', '/dev/tty',
211+
'--tmpfs', '/dev/shm',
212+
'--proc', '/proc',
213+
'--bind', '/sys', '/sys',
214+
'--tmpfs', '/tmp',
215+
init)
234216

235217
elif args.bare_metal:
236218
if args.kernel:

steps/improve/populate_device_nodes.sh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,6 @@ test -c "/dev/urandom" || mknod -m 444 "/dev/urandom" c 1 9
1515
test -c "/dev/ptmx" || mknod -m 666 "/dev/ptmx" c 5 2
1616
test -c "/dev/tty" || mknod -m 666 "/dev/tty" c 5 0
1717

18-
test -b "/dev/sda" || mknod -m 600 "/dev/sda" b 8 0
19-
test -b "/dev/sda1" || mknod -m 600 "/dev/sda1" b 8 1
20-
test -b "/dev/sda2" || mknod -m 600 "/dev/sda2" b 8 2
21-
test -b "/dev/sda3" || mknod -m 600 "/dev/sda3" b 8 3
22-
test -b "/dev/sdb" || mknod -m 600 "/dev/sdb" b 8 16
23-
test -b "/dev/sdb1" || mknod -m 600 "/dev/sdb1" b 8 17
24-
test -b "/dev/sdb2" || mknod -m 600 "/dev/sdb2" b 8 18
25-
test -b "/dev/sdb2" || mknod -m 600 "/dev/sdb3" b 8 19
26-
test -b "/dev/sdc" || mknod -m 600 "/dev/sdc" b 8 32
27-
test -b "/dev/sdc1" || mknod -m 600 "/dev/sdc1" b 8 33
28-
test -b "/dev/sdc2" || mknod -m 600 "/dev/sdc2" b 8 34
29-
test -b "/dev/sdc3" || mknod -m 600 "/dev/sdc3" b 8 35
30-
3118
test -e "/dev/stdout" || ln -s "/proc/self/fd/1" "/dev/stdout"
3219

3320
if mount --version >/dev/null 2>&1; then
@@ -37,4 +24,16 @@ fi
3724

3825
if [ "${CHROOT}" = False ]; then
3926
test -c "/dev/console" || mknod -m 666 "/dev/console" c 5 1
27+
test -b "/dev/sda" || mknod -m 600 "/dev/sda" b 8 0
28+
test -b "/dev/sda1" || mknod -m 600 "/dev/sda1" b 8 1
29+
test -b "/dev/sda2" || mknod -m 600 "/dev/sda2" b 8 2
30+
test -b "/dev/sda3" || mknod -m 600 "/dev/sda3" b 8 3
31+
test -b "/dev/sdb" || mknod -m 600 "/dev/sdb" b 8 16
32+
test -b "/dev/sdb1" || mknod -m 600 "/dev/sdb1" b 8 17
33+
test -b "/dev/sdb2" || mknod -m 600 "/dev/sdb2" b 8 18
34+
test -b "/dev/sdb2" || mknod -m 600 "/dev/sdb3" b 8 19
35+
test -b "/dev/sdc" || mknod -m 600 "/dev/sdc" b 8 32
36+
test -b "/dev/sdc1" || mknod -m 600 "/dev/sdc1" b 8 33
37+
test -b "/dev/sdc2" || mknod -m 600 "/dev/sdc2" b 8 34
38+
test -b "/dev/sdc3" || mknod -m 600 "/dev/sdc3" b 8 35
4039
fi

steps/jump/break.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
#
3+
# SPDX-FileCopyrightText: 2023 Gábor Stefanik <[email protected]>
4+
#
5+
# SPDX-License-Identifier: GPL-3.0-or-later
6+
7+
exit 0

steps/manifest

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ define: BUILD_LINUX = ( CHROOT == False || BUILD_KERNELS == True )
115115
build: kexec-linux-1.0.0 ( BUILD_LINUX == True )
116116
build: kexec-tools-2.0.22 ( BUILD_LINUX == True )
117117
build: linux-4.9.10 ( BUILD_LINUX == True )
118+
jump: break ( INTERNAL_CI == pass1 )
118119
jump: linux ( CHROOT == False )
119120
improve: finalize_fhs
120121
build: musl-1.2.4
@@ -174,6 +175,7 @@ build: python-3.3.7
174175
build: python-3.4.10
175176
build: python-3.8.16
176177
build: python-3.11.1
178+
jump: break ( INTERNAL_CI == pass1 ) # scripts are generated in pass1
177179
build: gcc-10.4.0
178180
build: binutils-2.41
179181
build: gcc-13.1.0

0 commit comments

Comments
 (0)