-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathquickstart.sh
More file actions
executable file
·116 lines (100 loc) · 3.83 KB
/
quickstart.sh
File metadata and controls
executable file
·116 lines (100 loc) · 3.83 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
set -euo pipefail
OWNER=${OWNER:-microshift-io}
REPO=${REPO:-microshift}
IMAGE=${IMAGE:-"ghcr.io/${OWNER}/${REPO}"}
TAG=${TAG:-latest}
LVM_DISK="/var/lib/microshift-okd/lvmdisk.image"
VG_NAME="${VG_NAME:-myvg1}"
SPARE_GB="${SPARE_GB:-10}"
function pull_bootc_image() {
local -r image_ref="$1"
# Skip pulling the local container images
if [[ "${image_ref}" == localhost/* ]]; then
echo "Skipping pull of local container image: ${image_ref}"
return 0
fi
echo "Pulling '${image_ref}'"
podman pull "${image_ref}"
}
function prepare_lvm_disk() {
local -r lvm_disk="$1"
local -r vg_name="$2"
if [ -f "${lvm_disk}" ]; then
echo "INFO: '${lvm_disk}' already exists. Clearing and reusing it."
dd if=/dev/zero of="${lvm_disk}" bs=1M count=100 >/dev/null
return 0
fi
mkdir -p "$(dirname "${lvm_disk}")"
truncate --size=1G "${lvm_disk}"
local -r device_name="$(losetup --find --show --nooverlap "${lvm_disk}")"
vgcreate -f -y "${vg_name}" "${device_name}"
}
function run_bootc_image() {
local -r image_ref="$1"
# Prerequisites for running the MicroShift container:
# - If the OVN-K CNI driver is used (`WITH_KINDNET=0` non-default image build
# option), the `openvswitch` module must be loaded on the host.
# - If the TopoLVM CSI driver is used (`WITH_TOPOLVM=1` default image build
# option), the /dev/dm-* device must be shared with the container.
echo "Running '${image_ref}'"
modprobe openvswitch || true
# Share the /dev directory with the container to enable TopoLVM CSI driver.
# Mask the devices that may conflict with the host by sharing them on a
# temporary file system. Note that a pseudo-TTY is also allocated to
# prevent the container from using host consoles.
local vol_opts="--tty --volume /dev:/dev"
for device in input snd dri; do
[ -d "/dev/${device}" ] && vol_opts="${vol_opts} --tmpfs /dev/${device}"
done
# shellcheck disable=SC2086
podman run --privileged --rm -d \
--replace \
${vol_opts} \
-e VG_NAME="${VG_NAME}" \
-e SPARE_GB="${SPARE_GB}" \
--name microshift-okd \
--hostname 127.0.0.1.nip.io \
"${image_ref}"
echo "Waiting for MicroShift to start"
local -r kubeconfig="/var/lib/microshift/resources/kubeadmin/kubeconfig"
while true ; do
if podman exec microshift-okd /bin/test -f "${kubeconfig}" &>/dev/null ; then
break
fi
sleep 1
done
}
# Check if the script is running as root
if [ "$(id -u)" -ne 0 ]; then
echo "ERROR: This script must be run as root (use sudo)"
exit 1
fi
# For remote images with the 'latest' tag, update the tag to the latest released version
if [[ "${IMAGE}" != localhost/* ]] && [ "${TAG}" == "latest" ]; then
TAG="$(curl -s --max-time 60 "https://api.github.com/repos/${OWNER}/${REPO}/releases/latest" | jq -r .tag_name)"
if [ -z "${TAG}" ] || [ "${TAG}" == "null" ] ; then
echo "ERROR: Could not determine the latest release tag from GitHub"
exit 1
fi
fi
# Run the procedures
pull_bootc_image "${IMAGE}:${TAG}"
prepare_lvm_disk "${LVM_DISK}" "${VG_NAME}"
run_bootc_image "${IMAGE}:${TAG}"
# Follow-up instructions
echo
echo "MicroShift is running in a bootc container"
echo "Hostname: 127.0.0.1.nip.io"
echo "Container: microshift-okd"
echo "LVM disk: ${LVM_DISK}"
echo "VG name: ${VG_NAME}"
echo
echo "To access the container, run the following command:"
echo " - sudo podman exec -it microshift-okd /bin/bash -l"
echo
echo "To verify that MicroShift pods are up and running, run the following command:"
echo " - sudo podman exec -it microshift-okd oc get pods -A"
echo
echo "To uninstall MicroShift, run the following command:"
echo " - curl -s https://${OWNER}.github.io/${REPO}/quickclean.sh | sudo bash"