-
Notifications
You must be signed in to change notification settings - Fork 9
/
launch.sh
executable file
·88 lines (72 loc) · 2.86 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 Cloud Garage, Catalyst Team
SCRIPT_DIR="$(cd $(dirname $0); pwd -P)"
SRC_DIR="$(cd "${SCRIPT_DIR}/output" ; pwd -P)"
DOCKER_IMAGE="quay.io/ibmgaragecloud/cli-tools:v0.15"
helpFunction()
{
RED='\033[0;31m'
CYAN='\033[0;36m'
LIGHT_GRAY='\033[0;37m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
error="$1"
echo "Iteration Zero Setup"
echo -e "This script will help setup setup a development environment and tools on the IBM Public Kubernetes Service"
echo ""
echo -e "${CYAN}Usage:${NC} $0"
echo ""
if [[ "${error}" =~ "file is not found" ]]; then
echo -e "${RED}${error}${NC}"
echo -e "Credentials should be provided in a file named ${CYAN}'${ENV}.properties'${NC}"
else
echo -e "${RED}${error}${NC}"
echo -e "The ${ENV}.properties file should contain the following values:"
echo -e " ${GREEN}ibmcloud.api.key${NC} is the IBM Cloud api key"
echo -e " ${GREEN}classic.username${NC} is the Classic Infrastructure user name or API user name (e.g. 282165_joe@us.ibm.com)"
echo -e " ${GREEN}classic.api.key${NC} is the Classic Infrastructure api key"
fi
echo ""
exit 1 # Exit script after printing help
}
ENV="credentials"
function prop {
grep "${1}" ${ENV}.properties | grep -vE "^#" | cut -d'=' -f2 | sed 's/"//g'
}
if [[ -f "${ENV}.properties" ]]; then
# Load the credentials
IBMCLOUD_API_KEY=$(prop 'ibmcloud.api.key')
CLASSIC_API_KEY=$(prop 'classic.api.key')
CLASSIC_USERNAME=$(prop 'classic.username')
LOGIN_USER=$(prop 'login.user')
LOGIN_PASSWORD=$(prop 'login.password')
LOGIN_TOKEN=$(prop 'login.token')
SERVER_URL=$(prop 'server.url')
else
helpFunction "The ${ENV}.properties file is not found."
fi
SUFFIX=$(echo $(basename ${SCRIPT_DIR}) | base64 | sed -E "s/[^a-zA-Z0-9_.-]//g" | sed -E "s/.*(.{5})/\1/g")
CONTAINER_NAME="ibm-garage-cli-tools-${SUFFIX}"
echo "Cleaning up old container: ${CONTAINER_NAME}"
DOCKER_CMD="docker"
${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
echo "Initializing container ${CONTAINER_NAME} from ${DOCKER_IMAGE}"
${DOCKER_CMD} run -itd --name ${CONTAINER_NAME} \
-v ${SRC_DIR}:/home/devops/src \
-e TF_VAR_ibmcloud_api_key="${IBMCLOUD_API_KEY}" \
-e TF_VAR_login_user="${LOGIN_USER}" \
-e TF_VAR_login_password="${LOGIN_PASSWORD}" \
-e TF_VAR_login_token="${LOGIN_TOKEN}" \
-e TF_VAR_server_url="${SERVER_URL}" \
-e IBMCLOUD_API_KEY="${IBMCLOUD_API_KEY}" \
-e IAAS_CLASSIC_USERNAME="${CLASSIC_USERNAME}" \
-e IAAS_CLASSIC_API_KEY="${CLASSIC_API_KEY}" \
-w /home/devops/src \
${DOCKER_IMAGE}
echo "Attaching to running container..."
${DOCKER_CMD} attach ${CONTAINER_NAME}