Skip to content

Commit bb18707

Browse files
authored
refactor(builder): simplify builder code logic (#52)
This PR reduces the complexity of the builder (with 364 additions and 811 deletions)
1 parent 49c91f7 commit bb18707

File tree

17 files changed

+364
-811
lines changed

17 files changed

+364
-811
lines changed

.github/workflows/build_macos-x86_64.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ on:
1616
- '*.md'
1717
- '*.txt'
1818
- '*.yaml'
19+
env:
20+
CI_ENV: IN_CI
1921

2022
jobs:
2123
build:

.github/workflows/build_macos.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ on:
1717
- '*.txt'
1818
- '*.yaml'
1919

20+
env:
21+
CI_ENV: IN_CI
22+
2023
jobs:
2124
build:
2225
runs-on: ubuntu-24.04

.github/workflows/build_wsl2.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
branches:
99
- 'main'
1010
- 'dev'
11+
env:
12+
CI_ENV: IN_CI
1113

1214
jobs:
1315
build:

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
[![Build Intel MacOS Profile](https://github.com/ihexon/ovm-builder/actions/workflows/build_macos-x86_64.yaml/badge.svg)](https://github.com/ihexon/ovm-builder/actions/workflows/build_macos-x86_64.yaml) [![Build ARM64 MacOS Profile](https://github.com/ihexon/ovm-builder/actions/workflows/build_macos.yaml/badge.svg)](https://github.com/ihexon/ovm-builder/actions/workflows/build_macos.yaml) [![Build WSL2 Profile](https://github.com/ihexon/ovm-builder/actions/workflows/build_wsl2.yaml/badge.svg)](https://github.com/ihexon/ovm-builder/actions/workflows/build_wsl2.yaml)
12
# `make` commands
23
- `macos_arm64` : make ovm bootable image for macos arm64
34
- `wsl2_amd64` : make ovm wsl2 rootfs distribute
5+
NOTE: Only one profile can be built at a time
46

57

68

layers/macos_amd64/etc/init.d/ovmservice

100644100755
File mode changed.

layers/macos_arm64/etc/init.d/ovmservice

100644100755
File mode changed.

make

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
#!/usr/bin/bash
2+
# Get current work directory
3+
script="$(realpath "$0")"
4+
script_path="$(dirname "$script")"
5+
cd "${script_path}" || {
6+
echo "initialize work dir failed"
7+
exit 1
8+
}
9+
10+
workspace="$script_path"
11+
212
check_distro() {
3-
echo "== /etc/lsb-release =="
4-
grep DISTRIB_ID=Ubuntu /etc/lsb-release && grep DISTRIB_RELEASE=24.04 /etc/lsb-release || {
13+
lsb_file="/etc/lsb-release"
14+
grep "DISTRIB_ID=Ubuntu" "$lsb_file" && grep "DISTRIB_RELEASE=24.04" "$lsb_file" || {
515
echo "Only support build on ubuntu 24.04"
616
exit 100
717
}
8-
echo "======================"
918
}
1019

1120
parse_profile() {
12-
echo "=== Parse $target_profile ==="
13-
14-
if [[ ! -f ./target_builder/$target_profile ]]; then
15-
echo "Error: profile $target_profile not support! "
21+
target_profile="$workspace/target_builder/$target_profile"
22+
if [[ -f "$target_profile" ]]; then
23+
echo "Target profile: $target_profile"
24+
else
25+
echo "Error: $target_profile not find! "
1626
exit 100
1727
fi
1828

19-
HOST_ARCH=$(uname -p)
29+
# normalization the host arch field
30+
HOST_ARCH="$(uname -p)"
2031
if [[ "${HOST_ARCH}" == 'aarch64' ]]; then
2132
HOST_ARCH=arm64
2233
fi
@@ -26,74 +37,77 @@ parse_profile() {
2637

2738
echo "HOST_ARCH: $HOST_ARCH"
2839

29-
TARGET_ARCH=$(echo "${target_profile}" | cut -d '_' -f 2)
40+
# normalization the target arch field
41+
TARGET_ARCH="$(basename "${target_profile}" | cut -d '_' -f 2)"
3042
if [[ "${TARGET_ARCH}" == 'aarch64' ]]; then
3143
TARGET_ARCH=arm64
3244
fi
3345
if [[ "${TARGET_ARCH}" == 'x86_64' ]]; then
3446
TARGET_ARCH=amd64
3547
fi
3648

37-
echo TARGET_ARCH: $TARGET_ARCH # only support arm64
38-
39-
echo "Build ${TARGET_ARCH} on ${HOST_ARCH}"
49+
echo TARGET_ARCH: "$TARGET_ARCH" # only support arm64
4050

41-
if [[ $SKIP_BUILD_PROOT == "true" ]]; then
42-
echo '$SKIP_BUILD_PROOT == true, skip build proot'
51+
# Build Proot
52+
if [[ "$SKIP_BUILD_PROOT" == "true" ]]; then
53+
echo 'env SKIP_BUILD_PROOT == true, skip build proot'
4354
else
44-
bash +x ${workspace}/subfunc/build_proot.sh || {
55+
workspace="$workspace" output="$output" bash "${workspace}/subfunc/build_proot.sh" || {
4556
echo "Error: Build proot failed"
4657
exit 100
4758
}
4859
fi
4960

50-
if [[ $SKIP_INSTALL_QEMU == "true" ]]; then
51-
echo "SKIP_INSTALL_QEMU set true, skip install qemu"
61+
# Install qemu
62+
if [[ "$SKIP_INSTALL_QEMU" == "true" ]]; then
63+
echo "env SKIP_INSTALL_QEMU set true, skip install qemu"
5264
else
53-
output=$output workspace=$workspace bash +x ${workspace}/subfunc/install_qemu.sh || {
65+
output="$output" workspace="$workspace" bash +x "${workspace}/subfunc/install_qemu.sh" || {
5466
echo "Error: Install qemu failed"
5567
exit 100
5668
}
5769
fi
5870

5971
if [[ "${HOST_ARCH}" == "${TARGET_ARCH}" ]]; then
60-
export NATIVE_BUILD=true
61-
echo "current we do native build..."
72+
export BUILD_TYPE=native
73+
echo "current we do native build"
6274
else
63-
export CROSS_BUILD=true
64-
echo "current we do cross build, building proot...."
75+
export BUILD_TYPE=cross
76+
echo "current we do cross build"
6577
fi
6678

67-
bash +x $workspace/target_builder/$target_profile || {
68-
echo "Error: run $workspace/target_builder/$target_profile failed"
79+
workspace="$workspace" output="$output" target_profile="$target_profile" bash "$target_profile" || {
80+
echo "Error: run $target_profile failed"
6981
exit 100
7082
}
7183
}
7284

7385
usage() {
74-
cat ./docs/help
86+
help_file="docs/help"
87+
cat "$help_file"
7588
}
7689

7790
main() {
78-
cd "$(dirname $0)"
79-
if [[ $1 == help ]] || [[ $# -ne 1 ]]; then
80-
usage
81-
exit 100
82-
fi
91+
SKIP_BUILD_PROOT="${SKIP_BUILD_PROOT:-false}"
92+
SKIP_APT_GET_INSTALL="${SKIP_APT_GET_INSTALL:-false}"
93+
VM_PROVIDER="${VM_PROVIDER:-applehv}"
94+
export SKIP_BUILD_PROOT
95+
export SKIP_APT_GET_INSTALL
96+
export VM_PROVIDER
8397

84-
export workspace="$(pwd)"
85-
export output=${workspace}/output
86-
87-
echo "- workspace: $workspace"
88-
echo "- output : ${output}"
89-
mkdir -p ${output}
98+
check_distro
9099

91-
if [[ $# -eq 1 ]]; then
92-
target_profile=$1
93-
export target_profile
100+
if [[ "$1" == help ]] || [[ "$#" -ne 1 ]]; then
101+
usage
102+
exit 0
94103
fi
95104

96-
check_distro
105+
output="${workspace}/output"
106+
mkdir -p "${output}"
107+
echo "==> workspace: $workspace"
108+
echo "==> output : ${output}"
109+
110+
target_profile="$1"
97111
parse_profile
98112
}
99113

shellcheck.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! /usr/bin/env bash
2+
shellcheck subfunc/*.sh
3+
shellcheck make target_builder/*

subfunc/boot_raw_disk.sh

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)