-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathocboot.sh
executable file
·81 lines (63 loc) · 2.01 KB
/
ocboot.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
set -e
DEFAULT_REPO=registry.cn-beijing.aliyuncs.com/yunionio
IMAGE_REPOSITORY=${IMAGE_REPOSITORY:-$DEFAULT_REPO}
VERSION=${VERSION:-v4-k3s.4}
OCBOOT_IMAGE="$IMAGE_REPOSITORY/ocboot:$VERSION"
CUR_DIR="$(pwd)"
CONTAINER_NAME="buildah-ocboot"
ensure_buildah() {
if ! [ -x "$(command -v buildah)" ]; then
echo "Installing buildah ..."
./scripts/install-buildah.sh
fi
}
buildah_from_image() {
if buildah ps | grep $CONTAINER_NAME; then
buildah rm $CONTAINER_NAME
fi
local img="$1"
echo "Using buildah pull $img"
buildah from --name $CONTAINER_NAME "$img"
}
ensure_buildah
buildah_from_image "$OCBOOT_IMAGE"
mkdir -p "$HOME/.ssh"
ROOT_DIR='/ocboot'
CMD=""
is_ocboot_subcmd() {
local subcmds="install upgrade add-node add-lbagent backup restore setup-container-env switch-edition clickhouse"
for subcmd in $subcmds; do
if [[ "$1" == "$subcmd" ]]; then
return 0
fi
done
return 1
}
if is_ocboot_subcmd "$1"; then
CMD="$ROOT_DIR/ocboot.py"
fi
buildah_version=$(buildah --version | awk '{print $3}')
buildah_version_major=$(echo "$buildah_version" | awk -F. '{print $1}')
buildah_version_minor=$(echo "$buildah_version" | awk -F. '{print $2}')
buildah_extra_args=()
# buildah accept --env since 1.23
echo "buildah version: $buildah_version"
if [[ $buildah_version_major -eq 1 ]] && [[ "$buildah_version_minor" -gt 23 ]]; then
buildah_extra_args+=(-e ANSIBLE_VERBOSITY="${ANSIBLE_VERBOSITY:-0}")
fi
cmd_extra_args=""
origin_args="$@"
if [[ "$1" == "run.py" ]]; then
if [[ "$IMAGE_REPOSITORY" != "$DEFAULT_REPO" ]]; then
cmd_extra_args="$cmd_extra_args -i $IMAGE_REPOSITORY"
fi
origin_args="$ROOT_DIR/$origin_args"
fi
buildah run --isolation chroot --user $(whoami) \
-t "${buildah_extra_args[@]}" \
--net=host \
-v "$HOME/.ssh:$HOME/.ssh" \
-v "$(pwd):$ROOT_DIR" \
-v "$(pwd)/airgap_assets/k3s-install.sh:/airgap_assets/k3s-install.sh:ro" \
"$CONTAINER_NAME" $CMD $origin_args $cmd_extra_args