forked from IBM/ibm-cloud-reference-architectures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch.sh
executable file
·88 lines (64 loc) · 2.22 KB
/
launch.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
82
83
84
85
86
87
88
#!/bin/bash
# IBM GSI Ecosystem Lab
SCRIPT_DIR="$(cd $(dirname "$0"); pwd -P)"
SRC_DIR="${SCRIPT_DIR}/automation"
AUTOMATION_BASE=$(basename "${SCRIPT_DIR}")
DOCKER_CMD="${1:-docker}"
if [[ ! -d "${SRC_DIR}" ]]; then
SRC_DIR="${SCRIPT_DIR}"
fi
# check if colima is installed, and apply dns override if no override file already exists
if command -v colima &> /dev/null
then
if [ ! -f ~/.lima/_config/override.yaml ]; then
echo "applying colima dns override..."
COLIMA_STATUS="$(colima status 2>&1)"
SUB='colima is running'
if [[ "$COLIMA_STATUS" == *"$SUB"* ]]; then
echo "stopping colima"
colima stop
fi
echo "writing ~/.lima/_config/override.yaml"
mkdir -p ~/.lima/_config
printf "useHostResolver: false\ndns:\n- 8.8.8.8" > ~/.lima/_config/override.yaml
if [[ "$COLIMA_STATUS" == *"$SUB"* ]]; then
echo "restarting colima"
colima start
fi
fi
fi
DOCKER_IMAGE="quay.io/cloudnativetoolkit/cli-tools-ibmcloud:v1.2-v0.3.3"
SUFFIX=$(echo $(basename ${SCRIPT_DIR}) | base64 | sed -E "s/[^a-zA-Z0-9_.-]//g" | sed -E "s/.*(.{5})/\1/g")
CONTAINER_NAME="cli-tools-${SUFFIX}"
echo "Cleaning up old container: ${CONTAINER_NAME}"
${DOCKER_CMD} kill ${CONTAINER_NAME} 1> /dev/null 2> /dev/null
${DOCKER_CMD} rm ${CONTAINER_NAME} 1> /dev/null 2> /dev/null
if [[ -n "$1" ]]; then
echo "Pulling container image: ${DOCKER_IMAGE}"
${DOCKER_CMD} pull "${DOCKER_IMAGE}"
fi
ENV_VARS=""
if [[ -f "credentials.properties" ]]; then
echo "parsing credentials.properties..."
props=$(grep -v '^#' credentials.properties)
while read line ; do
#remove export statement prefixes
CLEAN="$(echo $line | sed 's/export //' )"
#parse key-value pairs
TOKENS=(${CLEAN//\"/ })
KEY="${TOKENS[0]%?}"
VALUE="${TOKENS[1]}"
ENV_VARS="-e $KEY=$VALUE $ENV_VARS"
done <<< "$props"
fi
echo "Initializing container ${CONTAINER_NAME} from ${DOCKER_IMAGE}"
${DOCKER_CMD} run -itd --name ${CONTAINER_NAME} \
--device /dev/net/tun --cap-add=NET_ADMIN \
-u "${UID}" \
-v "${SRC_DIR}:/terraform" \
-v "workspace-${AUTOMATION_BASE}:/workspaces" \
${ENV_VARS} \
-w /terraform \
${DOCKER_IMAGE}
echo "Attaching to running container..."
${DOCKER_CMD} attach ${CONTAINER_NAME}