forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker.sh
250 lines (224 loc) · 5.63 KB
/
docker.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/bin/bash
#############################################################################
#
# GNU LESSER GENERAL PUBLIC LICENSE
# Version 3, 29 June 2007
#
# Copyright (C) [2007] [TRON Foundation], Inc. <https://fsf.org/>
# Everyone is permitted to copy and distribute verbatim copies
# of this license document, but changing it is not allowed.
#
#
# This version of the GNU Lesser General Public License incorporates
# the terms and conditions of version 3 of the GNU General Public
# License, supplemented by the additional permissions listed below.
#
# You can find java-tron at https://github.com/tronprotocol/java-tron/
#
##############################################################################
BASE_DIR="/java-tron"
DOCKER_REPOSITORY="tronprotocol"
DOCKER_IMAGES="java-tron"
# latest or version
DOCKER_TARGET="latest"
HOST_HTTP_PORT=8090
HOST_RPC_PORT=50051
HOST_LISTEN_PORT=18888
DOCKER_HTTP_PORT=8090
DOCKER_RPC_PORT=50051
DOCKER_LISTEN_PORT=18888
VOLUME=`pwd`
CONFIG="$VOLUME/config"
OUTPUT_DIRECTORY="$VOLUME/output-directory"
CONFIG_PATH="/java-tron/config/"
CONFIG_FILE="main_net_config.conf"
LOG_FILE="/logs/tron.log"
JAVA_TRON_REPOSITORY="https://raw.githubusercontent.com/tronprotocol/java-tron/develop/"
DOCKER_FILE="Dockerfile"
ENDPOINT_SHELL="docker-entrypoint.sh"
if test docker; then
docker -v
else
echo "warning: docker must be installed, please install docker first."
exit
fi
docker_ps() {
containerID=`docker ps -a | grep "$DOCKER_REPOSITORY-$DOCKER_IMAGES" | awk '{print $1}'`
cid=$containerID
}
docker_image() {
image_name=`docker images |grep "$DOCKER_REPOSITORY/$DOCKER_IMAGES" |awk {'print $1'}| awk 'NR==1'`
image=$image_name
}
run() {
docker_image
if [ ! $image ] ; then
echo 'warning: no java-tron mirror image, do you need to get the mirror image?[y/n]'
read need
if [[ $need == 'y' || $need == 'yes' ]]; then
pull
else
echo "warning: no mirror image found, go ahead and download a mirror."
exit
fi
fi
if [[ ! -d 'config' || ! -f "config/$CONFIG_FILE" ]]; then
mkdir -p config
if test curl; then
curl -o config/$CONFIG_FILE -LO https://raw.githubusercontent.com/tronprotocol/tron-deployment/master/main_net_config.conf
elif test wget; then
wget -P config/ https://raw.githubusercontent.com/tronprotocol/tron-deployment/master/main_net_config.conf
fi
fi
volume=""
parameter=""
tron_parameter=""
if [ $# -gt 0 ]; then
while [ -n "$1" ]; do
case "$1" in
-v)
volume="$volume -v $2"
shift 2
;;
-p)
parameter="$parameter -p $2"
shift 2
;;
-c)
tron_parameter="$tron_parameter -c $2"
shift 2
;;
*)
echo "arg: $1 is not a valid parameter"
exit
;;
esac
done
if [ -z "$volume" ]; then
volume=" -v $CONFIG:/java-tron/config -v $OUTPUT_DIRECTORY:/java-tron/output-directory"
fi
if [ -z "$parameter" ]; then
parameter=" -p $HOST_HTTP_PORT:$DOCKER_HTTP_PORT -p $HOST_RPC_PORT:$DOCKER_RPC_PORT -p $HOST_LISTEN_PORT:$DOCKER_LISTEN_PORT"
fi
if [ -z "$tron_parameter" ]; then
tron_parameter=" -c $CONFIG_PATH$CONFIG_FILE"
fi
# Using custom parameters
docker run -d -it --name "$DOCKER_REPOSITORY-$DOCKER_IMAGES" \
$volume \
$parameter \
--restart always \
"$DOCKER_REPOSITORY/$DOCKER_IMAGES:$DOCKER_TARGET" \
$tron_parameter
else
# Default parameters
docker run -d -it --name "$DOCKER_REPOSITORY-$DOCKER_IMAGES" \
-v $CONFIG:/java-tron/config \
-v $OUTPUT_DIRECTORY:/java-tron/output-directory \
-p $HOST_HTTP_PORT:$DOCKER_HTTP_PORT \
-p $HOST_RPC_PORT:$DOCKER_RPC_PORT \
-p $HOST_LISTEN_PORT:$DOCKER_LISTEN_PORT \
--restart always \
"$DOCKER_REPOSITORY/$DOCKER_IMAGES:$DOCKER_TARGET" \
-c "$CONFIG_PATH$CONFIG_FILE"
fi
}
build() {
echo 'docker build'
if [ ! -f "Dockerfile" ]; then
echo 'warning: Dockerfile not exists.'
if test curl; then
DOWNLOAD_CMD="curl -LJO "
elif test wget; then
DOWNLOAD_CMD="wget "
else
echo "Dockerfile cannot be downloaded, you need to install 'curl' or 'wget'!"
exit
fi
# download Dockerfile
`$DOWNLOAD_CMD "$JAVA_TRON_REPOSITORY$DOCKER_FILE"`
`$DOWNLOAD_CMD "$JAVA_TRON_REPOSITORY$ENDPOINT_SHELL"`
chmod u+rwx $ENDPOINT_SHELL
fi
docker build -t "$DOCKER_REPOSITORY/$DOCKER_IMAGES:$DOCKER_TARGET" .
}
pull() {
echo "docker pull $DOCKER_REPOSITORY/$DOCKER_IMAGES:$DOCKER_TARGET"
docker pull "$DOCKER_REPOSITORY/$DOCKER_IMAGES:$DOCKER_TARGET"
}
start() {
docker_ps
if [ $cid ]; then
echo "containerID: $cid"
echo "docker stop $cid"
docker start $cid
docker ps
else
echo "container not running!"
fi
}
stop() {
docker_ps
if [ $cid ]; then
echo "containerID: $cid"
echo "docker stop $cid"
docker stop $cid
docker ps
else
echo "container not running!"
fi
}
rm_container() {
stop
if [ $cid ]; then
echo "containerID: $cid"
echo "docker rm $cid"
docker rm $cid
docker_ps
else
echo "image not exists!"
fi
}
log() {
docker_ps
if [ $cid ]; then
echo "containerID: $cid"
docker exec -it $cid tail -100f $BASE_DIR/$LOG_FILE
else
echo "container not exists!"
fi
}
case "$1" in
--pull)
pull ${@: 2}
exit
;;
--start)
start ${@: 2}
exit
;;
--stop)
stop ${@: 2}
exit
;;
--build)
build ${@: 2}
exit
;;
--run)
run ${@: 2}
exit
;;
--rm)
rm_container ${@: 2}
exit
;;
--log)
log ${@: 2}
exit
;;
*)
echo "arg: $1 is not a valid parameter"
exit
;;
esac