Skip to content

Commit 95f7f2c

Browse files
committed
Added docker bootstrap
1 parent b35ce0d commit 95f7f2c

File tree

7 files changed

+100
-96
lines changed

7 files changed

+100
-96
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ COMMANDS:
4848
-m - mount the container before start
4949
stop [-u] [NAME ...] - stop all included or only specified components
5050
-u - unmount the container after stop
51-
sync URL - synchronize with the operating environment with server
5251
status [NAME ...] - display the status of the container and components
5352
help [NAME ...] - show this help or help of components
5453

cli.sh

+4-88
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77
################################################################################
88

9-
VERSION="2.4.1"
9+
VERSION="2.5.0"
1010

1111
################################################################################
1212
# Common
@@ -57,24 +57,6 @@ get_platform()
5757
esac
5858
}
5959

60-
get_qemu()
61-
{
62-
local arch="$1"
63-
local qemu=""
64-
local host_platform=$(get_platform)
65-
local guest_platform=$(get_platform "${arch}")
66-
if [ "${host_platform}" != "${guest_platform}" ]; then
67-
case "${guest_platform}" in
68-
arm) qemu="qemu-arm-static" ;;
69-
arm_64) qemu="qemu-aarch64-static" ;;
70-
x86) qemu="qemu-i386-static" ;;
71-
x86_64) qemu="qemu-x86_64-static" ;;
72-
*) qemu="" ;;
73-
esac
74-
fi
75-
echo ${qemu}
76-
}
77-
7860
get_uuid()
7961
{
8062
cat /proc/sys/kernel/random/uuid
@@ -241,9 +223,6 @@ chroot_exec()
241223
mounts="${mounts} -b ${MOUNTS// / -b }"
242224
fi
243225
local emulator
244-
if [ -z "${EMULATOR}" ]; then
245-
EMULATOR=$(get_qemu ${ARCH})
246-
fi
247226
if [ -n "${EMULATOR}" ]; then
248227
emulator="-q ${EMULATOR}"
249228
fi
@@ -260,16 +239,6 @@ chroot_exec()
260239
esac
261240
}
262241

263-
sync_env()
264-
{
265-
local env_url="$1"
266-
[ -n "${env_url}" ] || return 1
267-
msg -n "Synchronization with server ... "
268-
[ -e "${ENV_DIR}" ] || mkdir -p "${ENV_DIR}"
269-
wget -q -O - "${env_url}" | tar xz -C "${ENV_DIR}" 1>&2
270-
is_ok "fail" "done"
271-
}
272-
273242
################################################################################
274243
# Params
275244
################################################################################
@@ -944,8 +913,6 @@ container_status()
944913
local supported_fs=$(printf '%s ' $(grep -v nodev /proc/filesystems | sort))
945914
msg "${supported_fs}"
946915
947-
[ -n "${CHROOT_DIR}" ] || return 0
948-
949916
msg -n "Installed system: "
950917
local linux_version=$([ -r "${CHROOT_DIR}/etc/os-release" ] && . "${CHROOT_DIR}/etc/os-release"; [ -n "${PRETTY_NAME}" ] && echo "${PRETTY_NAME}" || echo "unknown")
951918
msg "${linux_version}"
@@ -955,53 +922,11 @@ container_status()
955922
component_exec "${INCLUDE}"
956923
957924
msg "Mounted parts: "
958-
local is_mnt=0
959925
local item
960926
for item in $(grep "${CHROOT_DIR%/}" /proc/mounts | awk '{print $2}' | sed "s|${CHROOT_DIR%/}/*|/|g")
961927
do
962928
msg "* ${item}"
963-
local is_mnt=1
964-
done
965-
[ "${is_mnt}" -ne 1 ] && msg " ...nothing mounted"
966-
967-
msg "Available mount points: "
968-
local is_mountpoints=0
969-
local mp
970-
for mp in $(grep -v "${CHROOT_DIR%/}" /proc/mounts | grep ^/ | awk '{print $2":"$3}')
971-
do
972-
local part=$(echo ${mp} | awk -F: '{print $1}')
973-
local fstype=$(echo ${mp} | awk -F: '{print $2}')
974-
local block_size=$(stat -c '%s' -f ${part})
975-
local available=$(stat -c '%a' -f ${part} | awk '{printf("%.1f",$1*'${block_size}'/1024/1024/1024)}')
976-
local total=$(stat -c '%b' -f ${part} | awk '{printf("%.1f",$1*'${block_size}'/1024/1024/1024)}')
977-
if [ -n "${available}" -a -n "${total}" ]; then
978-
msg "* ${part} ${available}/${total} GB (${fstype})"
979-
is_mountpoints=1
980-
fi
981-
done
982-
[ "${is_mountpoints}" -ne 1 ] && msg " ...no mount points"
983-
984-
msg "Available partitions: "
985-
local is_partitions=0
986-
local dev
987-
for dev in /sys/block/*/dev
988-
do
989-
if [ -f ${dev} ]; then
990-
local devname=$(echo ${dev} | sed -e 's@/dev@@' -e 's@.*/@@')
991-
[ -e "/dev/${devname}" ] && local devpath="/dev/${devname}"
992-
[ -e "/dev/block/${devname}" ] && local devpath="/dev/block/${devname}"
993-
[ -n "${devpath}" ] && local parts=$(fdisk -l ${devpath} 2>/dev/null | grep ^/dev/ | awk '{print $1}')
994-
local part
995-
for part in ${parts}
996-
do
997-
local size=$(fdisk -l ${part} 2>/dev/null | grep 'Disk.*bytes' | awk '{ sub(/,/,""); print $3" "$4}')
998-
local type=$(fdisk -l ${devpath} 2>/dev/null | grep ^${part} | tr -d '*' | awk '{str=$6; for (i=7;i<=10;i++) if ($i!="") str=str" "$i; printf("%s",str)}')
999-
msg "* ${part} ${size} (${type})"
1000-
local is_partitions=1
1001-
done
1002-
fi
1003929
done
1004-
[ "${is_partitions}" -ne 1 ] && msg " ...no available partitions"
1005930
}
1006931
1007932
helper()
@@ -1041,7 +966,6 @@ COMMANDS:
1041966
-m - mount the container before start
1042967
stop [-u] [NAME ...] - stop all included or only specified components
1043968
-u - unmount the container after stop
1044-
sync URL - synchronize with the operating environment with server
1045969
status [NAME ...] - display the status of the container and components
1046970
help [NAME ...] - show this help or help of components
1047971
@@ -1086,6 +1010,9 @@ fi
10861010
if [ -z "${CHROOT_DIR}" ]; then
10871011
CHROOT_DIR="${ENV_DIR}/mnt"
10881012
fi
1013+
if [ -z "${METHOD}" ]; then
1014+
METHOD="chroot"
1015+
fi
10891016
10901017
# parse options
10911018
OPTIND=1
@@ -1133,14 +1060,6 @@ WITHOUT_CHECK="false"
11331060
WITHOUT_DEPENDS="false"
11341061
REVERSE_DEPENDS="false"
11351062
EXCLUDE_COMPONENTS=""
1136-
case "${METHOD}" in
1137-
proot)
1138-
CHROOT_DIR="${TARGET_PATH}"
1139-
;;
1140-
*)
1141-
METHOD="chroot"
1142-
;;
1143-
esac
11441063
11451064
# make dirs
11461065
[ -d "${CONFIG_DIR}" ] || mkdir "${CONFIG_DIR}"
@@ -1314,9 +1233,6 @@ stop)
13141233
container_umount
13151234
fi
13161235
;;
1317-
sync)
1318-
sync_env "$@"
1319-
;;
13201236
status)
13211237
if [ $# -gt 0 ]; then
13221238
DO_ACTION='do_status'

include/bootstrap/docker/deploy.conf

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Linux Deploy Component
2+
# (c) Anton Skshidlevsky <[email protected]>, GPLv3
3+
4+
NAME="docker"
5+
DESC="Bootstrap for Docker containers"
6+
DEPENDS="bootstrap"

include/bootstrap/docker/deploy.sh

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/sh
2+
# Linux Deploy Component
3+
# (c) Anton Skshidlevsky <[email protected]>, GPLv3
4+
5+
[ -n "${SUITE}" ] || SUITE="linux"
6+
7+
if [ -z "${ARCH}" ]
8+
then
9+
case "$(get_platform)" in
10+
x86) ARCH="386" ;;
11+
x86_64) ARCH="amd64" ;;
12+
arm) ARCH="arm" ;;
13+
arm_64) ARCH="arm64" ;;
14+
esac
15+
fi
16+
17+
[ -n "${SOURCE_PATH}" ] || SOURCE_PATH="library/ubuntu:18.04"
18+
19+
do_install()
20+
{
21+
msg ":: Installing ${COMPONENT} ... "
22+
23+
local image="${SOURCE_PATH%%:*}"
24+
local tag="${SOURCE_PATH##*:}"
25+
msg -n "Authorization in Docker repository ... "
26+
local token=$(wget -q -O - "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${image}:pull" | grep -oE '"token":"[.a-zA-Z0-9_-]+"' | tr -d '"' | awk -F':' '{print $2}')
27+
test -n "${token}"
28+
is_ok "fail" "done" || return 1
29+
msg -n "Fetching manifests from the repository ... "
30+
local manifest=$(wget -q -O - --header "Authorization: Bearer ${token}" --header "Accept: application/vnd.docker.distribution.manifest.list.v2+json" "https://registry-1.docker.io/v2/${image}/manifests/${tag}" | sed 's/},{/\n/g' | grep "\"${ARCH}\".*\"${SUITE}\"" | grep -oE 'sha256:[a-f0-9]{64}')
31+
test -n "${manifest}"
32+
is_ok "fail" "done" || return 1
33+
msg "Retrieving rootfs blobs: "
34+
wget -q -O - --header "Authorization: Bearer ${token}" "https://registry-1.docker.io/v2/${image}/manifests/${manifest}" | tr '\n' ' ' | tr '{}' '\n' | grep 'tar.gzip.*digest' | grep -oE 'sha256:[0-9a-f]{64}' | while read digest
35+
do
36+
msg -n " * ${digest} ... "
37+
wget -q -O - --header "Authorization: Bearer ${token}" "https://registry-1.docker.io/v2/${image}/blobs/${digest}" | tar xz -C "${CHROOT_DIR}"
38+
is_ok "fail" "done"
39+
done
40+
41+
return 0
42+
}
43+
44+
do_help()
45+
{
46+
cat <<EOF
47+
--arch="${ARCH}"
48+
Architecture of the container, supported "arm", "arm64", "386" and "amd64".
49+
50+
--suite="${SUITE}"
51+
OS of the container, supported "linux".
52+
53+
--source-path="${SOURCE_PATH}"
54+
Installation source, can specify name and version of the container.
55+
56+
EOF
57+
}

include/bootstrap/fedora/deploy.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ then
1414
esac
1515
fi
1616

17-
[ -n "${SOURCE_PATH}" ] || SOURCE_PATH="http://dl.fedoraproject.org/pub/archive"
17+
[ -n "${SOURCE_PATH}" ] || SOURCE_PATH="http://dl.fedoraproject.org/pub/archive/"
1818

1919
dnf_install()
2020
{

include/bootstrap/rootfs/deploy.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ rootfs_make()
8787
fi
8888

8989
if [ "${TARGET_TYPE}" = "ram" ]; then
90+
if [ ! -e "${TARGET_PATH}" ]; then
91+
mkdir "${TARGET_PATH}"
92+
fi
9093
umount "${TARGET_PATH}"
9194
if [ -z "${DISK_SIZE}" -o "${DISK_SIZE}" -le 0 ]; then
9295
local ram_free=$(grep ^MemFree /proc/meminfo | awk '{print $2}')
9396
let DISK_SIZE="${ram_free}/1024"
9497
fi
9598
msg -n "Making new disk image (${DISK_SIZE} MB) ... "
96-
if [ ! -e "${TARGET_PATH}" ]; then
97-
mkdir "${TARGET_PATH}"
98-
fi
9999
mount -t tmpfs -o size="${DISK_SIZE}M" tmpfs "${TARGET_PATH}"
100100
is_ok "fail" "done" || return 1
101101
fi

include/core/emulator/deploy.sh

+29-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22
# Linux Deploy Component
33
# (c) Anton Skshidlevsky <[email protected]>, GPLv3
44

5+
get_qemu()
6+
{
7+
local arch="$1"
8+
local qemu=""
9+
local host_platform=$(get_platform)
10+
local guest_platform=$(get_platform "${arch}")
11+
if [ "${host_platform}" != "${guest_platform}" ]; then
12+
case "${guest_platform}" in
13+
arm) qemu="qemu-arm-static" ;;
14+
arm_64) qemu="qemu-aarch64-static" ;;
15+
x86) qemu="qemu-i386-static" ;;
16+
x86_64) qemu="qemu-x86_64-static" ;;
17+
*) qemu="" ;;
18+
esac
19+
fi
20+
echo ${qemu}
21+
}
22+
523
[ -n "${EMULATOR}" ] || EMULATOR=$(get_qemu ${ARCH})
624

725
do_configure()
@@ -90,6 +108,14 @@ do_stop()
90108
msg "skip"
91109
fi
92110
;;
111+
qemu-x86_64*)
112+
if [ -e "/proc/sys/fs/binfmt_misc/qemu-x86_64" ]; then
113+
echo -1 > /proc/sys/fs/binfmt_misc/qemu-x86_64
114+
is_ok "fail" "done"
115+
else
116+
msg "skip"
117+
fi
118+
;;
93119
qemu-arm*)
94120
if [ -e "/proc/sys/fs/binfmt_misc/qemu-arm" ]; then
95121
echo -1 > /proc/sys/fs/binfmt_misc/qemu-arm
@@ -98,9 +124,9 @@ do_stop()
98124
msg "skip"
99125
fi
100126
;;
101-
qemu-mipsel*)
102-
if [ -e "/proc/sys/fs/binfmt_misc/qemu-mipsel" ]; then
103-
echo -1 > /proc/sys/fs/binfmt_misc/qemu-mipsel
127+
qemu-aarch64*)
128+
if [ -e "/proc/sys/fs/binfmt_misc/qemu-aarch64" ]; then
129+
echo -1 > /proc/sys/fs/binfmt_misc/qemu-aarch64
104130
is_ok "fail" "done"
105131
else
106132
msg "skip"

0 commit comments

Comments
 (0)