Skip to content

Commit 5f69e4f

Browse files
committed
feat: image-factory can create lxc image
1 parent f8eb995 commit 5f69e4f

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎image-factory/create_image.sh‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,36 @@ OS_IMAGE="$(image_url "${OS_ARCH}" || image_url "os")" || \
7979
action_on_failure "cuos:updater:os_image_not_defined" "OS image not defined"
8080
OS_DIGEST="$(jq -r --arg arch "${OS_ARCH}" '.[$arch+"_image_digest"] // .os_image_digest // empty' "${CONFIG_PATH}")"
8181

82+
if [[ "${OS_ARCH}" == "lxc" ]]; then
83+
IMAGE="${IMAGE/img/tar.gz}"
84+
85+
docker image pull "${OS_IMAGE}" || raise "Faild to fetch image"
86+
IMAGE_DIGEST="$(docker inspect --format='{{index .RepoDigests 0}}' "${OS_IMAGE}" 2>/dev/null | cut -d '@' -f 2)"
87+
if [[ -n "${OS_DIGEST}" && "${OS_DIGEST}" != "${IMAGE_DIGEST}" ]]; then
88+
echo "Image digest mismatch: ${OS_DIGEST} != ${IMAGE_DIGEST}"
89+
exit 1
90+
fi
91+
92+
CONTAINER_NAME="cuos-lxc-$$"
93+
docker run -it -d \
94+
--pull=never \
95+
--name "${CONTAINER_NAME}" \
96+
"${OS_IMAGE}" || raise "Failed to run container"
97+
docker exec "${CONTAINER_NAME}" /usr/local/cuos/first-run.sh "${PARTITION}" "${OS_IMAGE}" "${IMAGE_DIGEST}" \
98+
|| raise "Failed to run first-run script in container"
99+
100+
docker cp "${CONFIG_PATH}" "${CONTAINER_NAME}:/system_init.json" \
101+
|| raise "Failed to copy system.json"
102+
103+
if ! docker export "${CONTAINER_NAME}" | gzip >"${IMAGE}"; then
104+
raise "Failed to export the container"
105+
fi
106+
docker rm -f "${CONTAINER_NAME}" \
107+
|| raise "Failed to remove the container"
108+
109+
echo "Image created at ${IMAGE}"
110+
exit 0
111+
fi
82112

83113
SIZE_MB="$(jq --arg size_mb "${SIZE_MB}" -r '.image_size_mb // $size_mb' "${CONFIG_PATH}")"
84114

‎system/cuos/init.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ensure_system_config() {
2424
return
2525
fi
2626
if [[ "${VIRT_TYPE}" == "lxc" ]]; then
27-
cat "${SCRIPT_DIR}/system-default.json" >"${CONFIG_PATH}"
27+
cat "/system-init.json" >"${CONFIG_PATH}"
2828
else
2929
mkdir -p "/mnt/boot"
3030
mount -o ro -t vfat LABEL=boot "/mnt/boot"

0 commit comments

Comments
 (0)