forked from me-box/databox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabox-start
executable file
·157 lines (134 loc) · 3.57 KB
/
databox-start
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
#include helper functions
source ./scripts/utils
## debug
if [[ "$DATABOX_DEBUG" = "true" ]]; then
set -x
PS4='$LINENO: '
fi
declare -r ME="$(basename $0)"
## check we have the tools
if ! [ -x "$(command -v docker)" ]; then
die 1 "docker is not installed;"`
`"see https://docs.docker.com/engine/installation/"
fi
if ! [ -x "$(command -v docker-compose)" ]; then
die 2 "docker-compose is not installed;"`
`"see https://docs.docker.com/compose/install/#install-compose"
fi
## parse command line args
DOCKER_REPO="" #default to local images
DATABOX_SDK="0"
DATABOX_DEV="0"
DEV=0
SDK=0
case "$1" in
dev )
DEV=1
export DATABOX_DEV="1"
;;
sdk )
SDK=1
;;
esac
#Start the SDK
if [ "$SDK" == "1" ]
then
err "Starting SDK"
#SDK only works in DEV mode so force it
DEV=1
export DATABOX_DEV="1"
export HOSTMOUNT=$(pwd -P)
docker-compose -f docker-databox-sdk.yaml up -d
fi
## test if Databox is already running
err "testing if Databox is already running ..."
docker node ls >/dev/null 2>&1
assert_or_die $? 1 "Databox is already running!"
## extract a host interface IP address
err "extracting host interface IP address ..."
ips=($(ifconfig | sed -En 's/127.0.0.1//;s/172.//;s/169.//;s/.inet (addr:)?(([0-9]+.){3}[0-9]+).*/\2/p'))
EXT_IP=$ips
if [[ "${#ips[@]}" -gt "1" ]]; then
err "More than one IP found! Please select one:"
select ip in ${ips[*]}; do
case $ip in
exit )
die 0 "exiting ..."
break
;;
* )
EXT_IP=$ip
break
;;
esac
done
fi
err "host interface IP address = ${EXT_IP}"
## base images: what are we running on?
ARCH=$(uname -m)
case "$ARCH" in
armv7l )
NODE_IMAGE="hypriot/rpi-node:slim"
DEV=1 #ARM is only supported in dev mode with localy built images (for now)
export DATABOX_ARCH="-"${ARCH}
export DATABOX_DEV="1"
;;
aarch64 )
NODE_IMAGE="forumi0721alpineaarch64/alpine-aarch64-nodejs"
DEV=1 #ARM is only supported in dev mode with localy built images (for now)
export DATABOX_ARCH="-"${ARCH}
export DATABOX_DEV="1"
;;
* )
ARCH=""
NODE_IMAGE="node:alpine"
export DATABOX_ARCH=""
;;
esac
DOCKER_REPO=""
if [ "$DEV" != "1" ]
then
# use images from https://hub.docker.com/r/databoxsystems/
DOCKER_REPO="databoxsystems/"
fi
export DOCKER_REPO=$DOCKER_REPO
function _exec {
docker run \
--net=host -ti --rm -v "$(pwd -P)":/cwd -w /cwd \
$DARGS $NODE_IMAGE "$@"
}
if [ ! -d "node_modules" ]; then
_exec npm install -loglevel silent
fi
err "starting the Databox swarm"
docker swarm init --advertise-addr $EXT_IP > /dev/null
mkdir -p ./certs
_exec node ./src/createCerts.js
if [ "$DEV" == "1" ]
then
# build all images locally in dev mode
err "Building Databox localy in dev mode"
./databox-fetch-components
source ./databox-build-core
assert_or_die $? 0 "Problem building core images"
if [ -z "$DATABOX_TESTING" ]
then
# dont build these optional components when testing
docker-compose -f ./docker-compose-dev-local-images.yaml build
assert_or_die $? 0 "Problem building optional images"
fi
fi
err "starting Databox"
docker-compose -f ./docker-databox-appstore.yaml up -d
docker stack deploy -c docker-compose.yaml databox
assert_or_die $? 0 "Problem with docker stack deploy"
DARGS="-e DATABOX_DEV=$DEV"
err "seeding manifests"
_exec node ./src/seedManifests.js
assert_or_die $? 0 "Failed to seed manifests app-store not found"
err "Databox started! Visit http://127.0.0.1:8989"
if [ -z "$DATABOX_TESTING" ]
then
docker service logs databox_container-manager -f
fi