forked from stacks-archive/blockstack-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launcher
executable file
·158 lines (142 loc) · 5.19 KB
/
launcher
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
158
#!/bin/bash
# This script provides a simple interface for folks to use the docker install
coreimage=quay.io/blockstack/blockstack-core:latest
browserimage=quay.io/blockstack/blockstack-browser:latest
# Local Blockstack directory
homedir=$HOME/.blockstack
# Blockstack Directory inside container
containerdir=/root/.blockstack
# Name of Blockstack API container
corecontainer=blockstack-api
# Name of Blockstack Browser container
browsercontainer=blockstack-browser
build () {
echo "Building blockstack docker image. This might take a minute..."
docker build -t $browserimage .
}
create-wallet () {
if [ $# -eq 0 ]; then
echo "Need to input new wallet password when running setup: ./launcher create-wallet mypass"
exit 1
fi
docker run -it -v $homedir:$containerdir $coreimage blockstack setup -y --password $1
# Use init containers to set the API bind to 0.0.0.0
docker run -it -v $homedir:$containerdir $coreimage sed -i 's/api_endpoint_bind = localhost/api_endpoint_bind = 0.0.0.0/' $containerdir/client.in -e CORSPROXY_HOST="0.0.0.0"i
docker run -it -v $homedir:$containerdir $coreimage sed -i 's/api_endpoint_host = localhost/api_endpoint_host = 0.0.0.0/' $containerdir/client.ini
}
start () {
# Check for args first
if [ $# -eq 0 ]; then
echo "Need to input password for wallet located in the $HOME/.blockstack folder when staring api: ./launcher start mypass"
exit 1
fi
# Check for the blockstack-api container is running or stopped.
if [ "$(docker ps -q -f name=$corecontainer)" ]; then
echo "blockstack core container is already running"
exit 1
elif [ ! "$(docker ps -q -f name=$corecontainer)" ]; then
if [ "$(docker ps -aq -f status=exited -f name=$corecontainer)" ]; then
# cleanup old container if its still around
echo "removing old blockstack-core container..."
docker rm $corecontainer
fi
# If there is no existing $corecontainer container, run one
if [[ $(uname) == 'Linux' ]]; then
docker run -d --name $corecontainer -v $homedir:$containerdir -p 6270:6270 $coreimage blockstack api start-foreground --password $1 --api_password $1
elif [[ $(uname) == 'Darwin' ]]; then
docker run -d --name $corecontainer -v $homedir:$containerdir -p 6270:6270 $coreimage blockstack api start-foreground --password $1 --api_password $1
elif [[ $(uname) == 'Windows' ]]; then
echo "Don't know if this works!!!"
docker run -d --name $corecontainer -v $homedir:$containerdir -p 6270:6270 $coreimage blockstack api start-foreground --password $1 --api_password $1
fi
fi
# Check for the blockstack-browser-* containers are running or stopped.
if [ "$(docker ps -q -f name=$browsercontainer)" ]; then
echo "browser containers are already running"
exit 1
elif [ ! "$(docker ps -q -f name=$browsercontainer)" ]; then
if [ "$(docker ps -aq -f status=exited -f name=$browsercontainer)" ]; then
# cleanup old containers if they are still around
echo "removing old browser containers..."
docker rm $(docker ps -aq -f status=exited -f name=$browsercontainer)
fi
# If there are no existing blockstack-browser-* containers, run them
if [[ $(uname) == 'Linux' ]]; then
docker run -d --name $browsercontainer-static -p 8888:8888 $browserimage blockstack-browser
docker run -d --name $browsercontainer-cors -p 1337:1337 $browserimage blockstack-cors-proxy
sensible-browser "http://localhost:8888/#coreAPIPassword=$1"
elif [[ $(uname) == 'Darwin' ]]; then
docker run -d --name $browsercontainer-static -p 8888:8888 $browserimage blockstack-browser
docker run -d --name $browsercontainer-cors -p 1337:1337 $browserimage blockstack-cors-proxy
open "http://localhost:8888/#coreAPIPassword=$1"
elif [[ $(uname) == 'Windows' ]]; then
echo "Don't know if this works!!!"
docker run -d --name $browsercontainer-static -p 8888:8888 $browserimage blockstack-browser
docker run -d --name $browsercontainer-cors -p 1337:1337 $browserimage blockstack-cors-proxy
fi
fi
}
stop () {
bc=$(docker ps -a -f name=$browsercontainer -q)
cc=$(docker ps -f name=$corecontainer -q)
if [ ! -z "$cc" ]; then
echo "stopping the running blockstack-api container"
docker stop $cc
docker rm $cc
fi
if [ ! -z "$bc" ]; then
echo "stopping the running blockstack-browser containers"
docker stop $bc
docker rm $bc
fi
}
enter () {
echo "entering docker container"
docker exec -it $browsercontainer-static /bin/bash
}
logs () {
echo "streaming logs for blockstack-api container"
docker logs $browsercontainer-static -f
}
push () {
echo "pushing build container up to quay.io..."
docker push $browserimage
}
commands () {
cat <<-EOF
blockstack docker launcher commands:
start -> start the blockstack browser server
stop -> stop the blockstack browser server
logs -> access the logs from the blockstack browser server
enter -> exec into the running docker container
EOF
}
case $1 in
stop)
stop
;;
create-wallet)
create-wallet $2
;;
start)
start $2
;;
logs)
logs
;;
build)
build
;;
enter)
enter
;;
push)
push
;;
build)
build
;;
*)
commands
;;
esac