Skip to content

Commit d0d95b7

Browse files
committed
feat: Run LXC system in docker
1 parent 9cf7ae8 commit d0d95b7

7 files changed

Lines changed: 21 additions & 14 deletions

File tree

‎image-factory/create_image.sh‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ export DOCKER_CONTEXT=default
5959

6060
IMAGE="/output/image.img"
6161
#IMAGE_QCOW="/output/image.qcow2"
62-
#SIZE_MB=2048
63-
SIZE_MB=4096
64-
SIZE_MB=1636
65-
66-
PARTITION="B"
6762

6863
if [[ ! -d "/output" ]]; then
6964
echo "Output dir not mounted"
@@ -83,6 +78,7 @@ OS_DIGEST="$(jq -r --arg arch "${OS_ARCH}" '.[$arch+"_image_digest"] // .os_imag
8378

8479
if [[ "${OS_ARCH}" == "lxc" ]]; then
8580
IMAGE="${IMAGE/img/tar.gz}"
81+
PARTITION="A"
8682

8783
docker image pull "${OS_IMAGE}" || raise "Faild to fetch image"
8884
IMAGE_DIGEST="$(docker inspect --format='{{index .RepoDigests 0}}' "${OS_IMAGE}" 2>/dev/null | cut -d '@' -f 2)"
@@ -112,6 +108,12 @@ if [[ "${OS_ARCH}" == "lxc" ]]; then
112108
exit 0
113109
fi
114110

111+
PARTITION="B"
112+
113+
#SIZE_MB=2048
114+
SIZE_MB=4096
115+
SIZE_MB=1636
116+
115117
SIZE_MB="$(jq --arg size_mb "${SIZE_MB}" -r '.image_size_mb // $size_mb' "${CONFIG_PATH}")"
116118

117119
# Create empty image

‎system/cuos/dialog-failed.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
66

77
export DIALOGRC="${SCRIPT_DIR}/dialog.rc"
88
VIRT_TYPE="$(systemd-detect-virt)"
9-
if [[ "${VIRT_TYPE}" = "lxc" ]]; then
9+
if [[ "${VIRT_TYPE}" == "lxc" || "${VIRT_TYPE}" == "docker" ]]; then
1010
# Dont show dialogs for lxc
1111
exit 0
1212
fi

‎system/cuos/do-rollback.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if [[ ! -f "/system_next.json" ]]; then
1010
fi
1111

1212
VIRT_TYPE="$(systemd-detect-virt)"
13-
if [[ "${VIRT_TYPE}" = "lxc" ]]; then
13+
if [[ "${VIRT_TYPE}" == "lxc" || "${VIRT_TYPE}" == "docker" ]]; then
1414
"${SCRIPT_DIR}/do-rollback-lxc.sh" "$@"
1515
exit "$?"
1616
fi

‎system/cuos/do-update.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -x
55
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
66

77
VIRT_TYPE="$(systemd-detect-virt)"
8-
if [[ "${VIRT_TYPE}" = "lxc" ]]; then
8+
if [[ "${VIRT_TYPE}" == "lxc" || "${VIRT_TYPE}" == "docker" ]]; then
99
"${SCRIPT_DIR}/do-update-lxc.sh" "$@"
1010
exit "$?"
1111
fi

‎system/cuos/init.sh‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ ensure_docker_config_json() {
2020
}
2121

2222
ensure_system_config() {
23+
# Exec first-run if not yet started. E.g. for testing in docker containers.
24+
if [[ ! -f "/etc/partition_mode" ]]; then
25+
"${SCRIPT_DIR}/first-run.sh" "A" "unknown" "unknown"
26+
fi
27+
2328
if [[ -f "${CONFIG_PATH}" ]]; then
2429
return
2530
fi
26-
if [[ "${VIRT_TYPE}" == "lxc" ]]; then
27-
cat "/system-init.json" >"${CONFIG_PATH}"
31+
if [[ "${VIRT_TYPE}" == "lxc" || "${VIRT_TYPE}" == "docker" ]]; then
32+
cat "/system_init.json" >"${CONFIG_PATH}"
2833
else
2934
mkdir -p "/mnt/boot"
3035
mount -o ro -t vfat LABEL=boot "/mnt/boot"
@@ -177,7 +182,7 @@ mask_to_prefix() {
177182
configure_network() {
178183
local interfaces_file="/etc/network/interfaces"
179184

180-
if [[ "${VIRT_TYPE}" == "lxc" ]]; then
185+
if [[ "${VIRT_TYPE}" == "lxc" || "${VIRT_TYPE}" == "docker" ]]; then
181186
# For lxc the network is configured from outside
182187
return
183188
fi
@@ -376,7 +381,7 @@ import_custom_ca_certs() {
376381
}
377382

378383
create_swap_and_resize_fs() {
379-
if [[ "${VIRT_TYPE}" == "lxc" ]]; then
384+
if [[ "${VIRT_TYPE}" == "lxc" || "${VIRT_TYPE}" == "docker" ]]; then
380385
# For lxc we do not manage disks or swap
381386
return
382387
fi

‎system/cuos/lib-dialog.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
export DIALOGRC="${SCRIPT_DIR}/dialog.rc"
44

55
VIRT_TYPE="$(systemd-detect-virt)"
6-
if [[ "${VIRT_TYPE}" == "lxc" ]]; then
6+
if [[ "${VIRT_TYPE}" == "lxc" || "${VIRT_TYPE}" == "docker" ]]; then
77
exit 0
88
fi
99

‎system/cuos/resources.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mem_available="$(free -b | awk '/Mem:/ {print $7}')"
1111

1212
load_average="$(awk '{print $1}' /proc/loadavg)"
1313
cpu_cores="$(nproc)"
14-
if [[ "${virt_type}" = "lxc" ]]; then
14+
if [[ "${virt_type}" == "lxc" || "${virt_type}" == "docker" ]]; then
1515
cpu_usage="$(awk '/^some/ {for(i=1;i<=NF;i++){split($i,a,"="); if(a[1]=="avg60"){print a[2]; exit}}}' /sys/fs/cgroup/cpu.pressure)"
1616
else
1717
cpu_usage="$(awk -v load="$load_average" -v cores="$cpu_cores" 'BEGIN {printf "%.2f", (load * 100) / cores}')"

0 commit comments

Comments
 (0)