Skip to content

Commit e920104

Browse files
committed
choe: update build script
修改构建脚本,判断容器与物理机运行,让 Workflows 也可以直接用 deepin 的 docker 构建根文件系统。
1 parent ca0f059 commit e920104

File tree

3 files changed

+65
-20
lines changed

3 files changed

+65
-20
lines changed

.github/workflows/build-rootfs.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@ jobs:
3636
- name: Checkout repository
3737
uses: actions/checkout@v4
3838

39-
- name: update source and add binfmts # 更新源到 noble
39+
- name: update source and add binfmts
4040
run: |
41-
curl https://community-packages.deepin.com/deepin/beige/pool/main/d/deepin-keyring/deepin-keyring_2024.01.16_all.deb --output deepin-keyring.deb
42-
sudo apt install ./deepin-keyring.deb && rm ./deepin-keyring.deb
43-
echo "deb https://community-packages.deepin.com/beige/ beige main commercial community" | sudo tee -a /etc/apt/sources.list
44-
45-
sudo sed -i 's/jammy/noble/g' /etc/apt/sources.list
46-
sudo apt update -y && sudo apt install mmdebstrap qemu-user-static usrmerge qemu-user systemd
47-
sudo apt-mark hold usrmerge
48-
sudo cp -v /usr/lib/arch-test/riscv64 /usr/lib/arch-test/loong64
49-
sudo sed -i "/riscv64 => 'riscv64',/a\ loong64 => 'loongarch64'," /usr/bin/mmdebstrap
41+
sudo apt update -y && sudo apt install qemu-user-static qemu-user arch-test systemd
5042
sudo systemctl restart systemd-binfmt
5143
44+
- name: pull deepin docker
45+
run: docker pull linuxdeepin/deepin:beige
46+
5247
- name: Run build.sh
5348
run: |
54-
sudo bash build.sh
49+
docker run --rm \
50+
--privileged \
51+
-v "${{ github.workspace }}:/workspace" \
52+
-w /workspace \
53+
linuxdeepin/deepin \
54+
/bin/bash -c "./build.sh"
5555
5656
- name: Read version
5757
id: read_version

build.sh

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,31 @@ SOURCES_FILE=config/apt/sources.list
1313
readarray -t REPOS < $SOURCES_FILE
1414
OUT_DIR=rootfs
1515

16-
mkdir -p $OUT_DIR
1716

18-
sudo apt update -y && sudo apt install -y curl git mmdebstrap qemu-user-static usrmerge systemd-container usrmerge
19-
# 开启异架构支持
20-
sudo systemctl start systemd-binfmt
17+
# 检测容器环境
18+
is_docker() {
19+
# 是否存在 /.dockerenv 文件(Docker 特有)
20+
if [[ -f /.dockerenv ]]; then
21+
return 1 # 是容器
22+
fi
23+
return 0
24+
}
25+
26+
27+
sudo apt update -y && sudo apt install -y curl git mmdebstrap qemu-user-static usrmerge
28+
if [[ ! is_docker ]];
29+
then
30+
# 开启异架构支持
31+
sudo systemctl restart systemd-binfmt
32+
33+
fi
34+
35+
if [[ is_docker ]];
36+
then
37+
# 让 mmdebstrap 的 loong64 指向 loongarch64
38+
sudo sed -i "/riscv64 => 'riscv64',/a\ loong64 => 'loongarch64'," /usr/bin/mmdebstrap
39+
sudo mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc
40+
fi
2141

2242
function build_rootfs() {
2343
sudo mmdebstrap \
@@ -40,6 +60,11 @@ systemd=true
4060
EOF
4161
fi
4262

63+
if [[ is_docker ]];
64+
then
65+
sudo umount /proc/sys/fs/binfmt_misc
66+
fi
67+
4368
# 生成压缩包
4469
pushd $OUT_DIR
4570
rm -rf $dist_name-$TARGET-rootfs-$arch.tar.gz
@@ -49,6 +74,8 @@ EOF
4974
popd
5075
}
5176

77+
mkdir -p $OUT_DIR
78+
5279
TARGET=wsl
5380
PACKAGES=`cat config/packages.list/$TARGET-packages.list | grep -v "^-" | xargs | sed -e 's/ /,/g'`
5481
for arch in amd64 arm64; do

config/hooks.chroot/second-stage

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,24 @@
33
rootdir="$1"
44

55
# 执行命令的辅助函数
6-
run_in_chroot() {
7-
systemd-nspawn -D "$rootdir" bash -c "$@"
6+
setup_chroot_environment() {
7+
sudo mount --bind /dev "$rootdir/dev"
8+
sudo mount -t proc chproc "$rootdir/proc"
9+
sudo mount -t sysfs chsys "$rootdir/sys"
10+
sudo mount -t tmpfs -o "size=99%" tmpfs "$rootdir/tmp"
11+
sudo mount -t tmpfs -o "size=99%" tmpfs "$rootdir/var/tmp"
812
}
913

14+
run_command_in_chroot()
15+
{
16+
command="$1"
17+
sudo chroot "$rootdir" /usr/bin/env -i DEBIAN_FRONTEND=noninteractive bash -e -o pipefail -c "$command"
18+
}
19+
20+
setup_chroot_environment
21+
1022
# 设置语言
11-
run_in_chroot "
23+
run_command_in_chroot "
1224
sed -i -E 's/#[[:space:]]?(en_US.UTF-8[[:space:]]+UTF-8)/\1/g' /etc/locale.gen
1325
sed -i -E 's/#[[:space:]]?(zh_CN.UTF-8[[:space:]]+UTF-8)/\1/g' /etc/locale.gen
1426
@@ -17,10 +29,16 @@ DEBIAN_FRONTEND=noninteractive dpkg-reconfigure locales
1729
"
1830

1931
# 微软提供的 wsl 启动器会调用adduser,需要将 USERS_GID 和 USERS_GROUP 注释。
20-
run_in_chroot "sed -i -e 's/USERS_GID=100/#USERS_GID=100/' -e 's/USERS_GROUP=users/#USERS_GROUP=users/' /etc/adduser.conf"
32+
run_command_in_chroot "sed -i -e 's/USERS_GID=100/#USERS_GID=100/' -e 's/USERS_GROUP=users/#USERS_GROUP=users/' /etc/adduser.conf"
2133

2234
# 清理缓存
23-
run_in_chroot "
35+
run_command_in_chroot "
2436
apt clean
2537
rm -rf /var/cache/apt/archives/*
2638
"
39+
40+
sudo umount $rootdir/tmp
41+
sudo umount $rootdir/var/tmp
42+
sudo umount $rootdir/proc
43+
sudo umount $rootdir/sys
44+
sudo umount $rootdir/dev

0 commit comments

Comments
 (0)