forked from OriginProtocol/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·151 lines (125 loc) · 3.58 KB
/
install.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
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
set -e
CLEAN=0
DRY=0
QUIET=0
function usage() {
echo "Installs Origin Protocol development environments."
echo
echo "Usage:"
echo " $0 -e [env] [-h] [-v] [-d]"
echo
echo "Options:"
echo -e " -c \t Clean - clean up all containers and volumes first'"
echo -e " -d \t Dry run mode - show the commands that would be executed."
echo -e " -e \t The environment to install, origin or origin-website."
echo -e " -h \t Show this help."
echo -e " -q \t Quiet mode - hide output of all commands."
echo
}
function print_origin_start() {
echo -e "\033[94mSetting up your Origin Protocol development environment. This will take a few minutes... \033[0m"
echo
}
function print_origin_finish() {
echo
echo -e "\033[97mAll set! Get building... \033[0m"
echo
echo -e "Origin-js blockchain is running at \033[94mhttp://localhost:8545\033[0m"
echo -e "Origin-js tests are running at \033[94mhttp://localhost:8081\033[0m"
echo -e "Origin-bridge is running at \033[94mhttp://localhost:5000\033[0m"
echo -e "Origin-dapp is running at \033[94mhttp://localhost:3000\033[0m"
echo -e "For more help \033[97mdocker-compose -h\033[0m"
echo -e "To follow the logs run \033[97mdocker-compose logs -f\033[0m"
}
function print_website_start() {
echo -e "\033[94mSetting up your Origin Protocol website development environment. This will take a few minutes... \033[0m"
echo
}
function print_website_finish() {
echo
echo -e "\033[97mAll set! Get building... \033[0m"
echo
echo -e "Origin-website is running at \033[94mhttp://localhost:5000\033[0m"
echo -e "For more help \033[97mdocker-compose -h\033[0m"
echo -e "To follow the logs run \033[97mdocker-compose -f docker-compose-web.yml logs -f\033[0m"
}
function run_step() {
printf "\033[97m%-24s\033[0m" "$1"
shift
[ $QUIET -eq 1 ] && out="> /dev/null 2>&1"
[ $DRY -eq 1 ] && dry="echo"
if [ $QUIET -eq 0 ] ; then
echo -e ""
fi
eval "$dry $@ $out"
wait
# Only display a tick if in quiet mode
if [ $QUIET -eq 1 ] ; then
echo -e "\033[97m ✓\033[0m"
fi
}
function install_origin_environment() {
print_origin_start
run_step "Building containers" \
docker-compose build
run_step "Installing dependencies and waiting for container startup..." \
docker-compose up -d && docker-compose exec origin-dapp wait-for.sh -t 0 -q origin-dapp:3000
print_origin_finish
}
function install_website_environment() {
print_website_start
run_step "Cloning origin-website" \
git clone [email protected]:OriginProtocol/origin-website.git --branch stable || true
run_step "Building containers" \
docker-compose -f docker-compose-web.yml build
run_step "Bringing up stack" \
docker-compose -f docker-compose-web.yml up -d
run_step "Configuring database" \
docker-compose -f docker-compose-web.yml exec origin-website flask db upgrade
print_website_finish
}
while getopts "e:cqdh" opt; do
case $opt in
e)
ENV=$OPTARG
;;
c)
CLEAN=1
;;
q)
QUIET=1
;;
d)
DRY=1
;;
h)
usage
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
if [ "$CLEAN" = 1 ]; then
echo -e "\033[31mDoing cleanup... \033[0m"
echo
if [ "$DRY" = 0 ]; then
docker kill $(docker ps -aq) >/dev/null 2>&1 || true
docker system prune --all --volumes
fi
echo
fi
if [ "$ENV" = "origin" ]; then
install_origin_environment
elif [ "$ENV" = "origin-website" ]; then
install_website_environment
else
usage
fi