-
Notifications
You must be signed in to change notification settings - Fork 4
/
start.sh
executable file
·139 lines (120 loc) · 3.57 KB
/
start.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env bash
#
# start.sh - is the main start script for our Demo cluster. Running it will launch a docker-compose environment
# that contains a fully connected ioFog ECN. Optionally, you can launch a different compose, e.g. tutorial.
#
# Usage : ./start.sh -h
#
set -o errexit -o pipefail -o noclobber -o nounset
cd "$(dirname "$0")"
# Import our helper functions
. ./utils.sh
printHelp() {
echo "Usage: ./start.sh [opts] [environment]"
echo "Starts ioFog environments and optionally sets up demo and tutorial environment"
echo ""
echo "Options:"
echo " -h, --help print this help / usage"
echo " -a, --agent specify a local agent image"
echo " -ct, --controller specify a local controller image"
echo ""
echo "Arguments:"
echo " [environment] setup demo application, optional, default: iofog"
echo " supported values: iofog, tutorial"
}
startIofog() {
# If stack is running, skip
local CONTROLLER_CONTAINER_ID=$(docker ps -q --filter="name=iofog-controller")
if ! [[ -z "${CONTROLLER_CONTAINER_ID}" ]]; then
return
fi
echo "---
apiVersion: iofog.org/v2
kind: LocalControlPlane
metadata:
name: local-ecn
spec:
iofogUser:
name: test
surname: local
email: [email protected]
password: '#Bugs4Fun'
controller:
name: local-controller
container:
image: $CONTROLLER_IMAGE
---
apiVersion: iofog.org/v2
kind: LocalAgent
metadata:
name: local-agent
spec:
host: localhost
container:
image: $AGENT_IMAGE
" >| init/iofog/local-stack.yaml
echoInfo "Deploying containers for ioFog stack..."
iofogctl deploy -f init/iofog/local-stack.yaml -v
}
checkProvisioning() {
AGENT_UUID=$(docker exec iofog-agent iofog-agent info | grep 'UUID' | awk '{print $4}')
if [ "$AGENT_UUID" == "not" ]; then
echoError "Failed to provision the agent"
return 1
fi
}
startEnvironment() {
local ENVIRONMENT="$1"
echoInfo "Deploying ${ENVIRONMENT} application..."
iofogctl deploy application -f "init/${ENVIRONMENT}/config.yaml" -v
echoInfo "It may take a while before ioFog stack creates all ${ENVIRONMENT} microservices."
echo ""
}
ENVIRONMENT=''
IOFOG_BUILD_NO_CACHE=''
AGENT_IMAGE='docker.io/iofog/agent:2.0.0-rc1'
CONTROLLER_IMAGE='docker.io/iofog/controller:2.0.0-rc1'
while [[ "$#" -ge 1 ]]; do
case "$1" in
-h|--help)
printHelp
exit 0
;;
-a|--agent)
AGENT_IMAGE=${2:-$AGENT_IMAGE}
shift
shift
;;
-ct|--controller)
CONTROLLER_IMAGE=${2:-$CONTROLLER_IMAGE}
shift
shift
;;
*)
if [[ -n "${ENVIRONMENT}" ]]; then
echoError "Cannot specify more than one environment!"
printHelp
exit 1
fi
ENVIRONMENT=$1
shift
;;
esac
done
prettyHeader "Starting ioFog Demo"
# Figure out which environment we are going to be starting. By default, setup only the ioFog stack
ENVIRONMENT=${ENVIRONMENT:="iofog"}
echoInfo "Starting \"${ENVIRONMENT}\" demo environment..."
# Start ioFog stack
startIofog
checkProvisioning
# Optionally start another environment
if [[ "${ENVIRONMENT}" != "iofog" ]]; then
# TODO check if this environment is up or not
startEnvironment "${ENVIRONMENT}";
fi
# Display the running environment
./status.sh
if [[ "${ENVIRONMENT}" == "tutorial" ]]; then
echoSuccess "## Visit https://iofog.org/docs/2.0.0/tutorial/introduction.html to continue with the ioFog tutorial."
fi