Skip to content

Commit 08c24fe

Browse files
author
王浩彬
committed
[Feature] 增加docker脚本
1 parent 7c8cee3 commit 08c24fe

File tree

7 files changed

+253
-15
lines changed

7 files changed

+253
-15
lines changed

ace-admin/src/main/docker/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
FROM livingobjects/jre8
22
VOLUME /tmp
33
ADD ace-admin.jar app.jar
4+
ADD wait-for-it.sh /wait-for-it.sh
45
RUN bash -c 'touch /app.jar'
56
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
#!/usr/bin/env bash
2+
# Use this script to test if a given TCP host/port are available
3+
4+
cmdname=$(basename $0)
5+
6+
echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
7+
8+
usage()
9+
{
10+
cat << USAGE >&2
11+
Usage:
12+
$cmdname host:port [-s] [-t timeout] [-- command args]
13+
-h HOST | --host=HOST Host or IP under test
14+
-p PORT | --port=PORT TCP port under test
15+
Alternatively, you specify the host and port as host:port
16+
-s | --strict Only execute subcommand if the test succeeds
17+
-q | --quiet Don't output any status messages
18+
-t TIMEOUT | --timeout=TIMEOUT
19+
Timeout in seconds, zero for no timeout
20+
-- COMMAND ARGS Execute command with args after the test finishes
21+
USAGE
22+
exit 1
23+
}
24+
25+
wait_for()
26+
{
27+
if [[ $TIMEOUT -gt 0 ]]; then
28+
echoerr "$cmdname: waiting $TIMEOUT seconds for $HOST:$PORT"
29+
else
30+
echoerr "$cmdname: waiting for $HOST:$PORT without a timeout"
31+
fi
32+
start_ts=$(date +%s)
33+
while :
34+
do
35+
if [[ $ISBUSY -eq 1 ]]; then
36+
nc -z $HOST $PORT
37+
result=$?
38+
else
39+
(echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1
40+
result=$?
41+
fi
42+
if [[ $result -eq 0 ]]; then
43+
end_ts=$(date +%s)
44+
echoerr "$cmdname: $HOST:$PORT is available after $((end_ts - start_ts)) seconds"
45+
break
46+
fi
47+
sleep 1
48+
done
49+
return $result
50+
}
51+
52+
wait_for_wrapper()
53+
{
54+
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
55+
if [[ $QUIET -eq 1 ]]; then
56+
timeout $BUSYTIMEFLAG $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
57+
else
58+
timeout $BUSYTIMEFLAG $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
59+
fi
60+
PID=$!
61+
trap "kill -INT -$PID" INT
62+
wait $PID
63+
RESULT=$?
64+
if [[ $RESULT -ne 0 ]]; then
65+
echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT"
66+
fi
67+
return $RESULT
68+
}
69+
70+
# process arguments
71+
while [[ $# -gt 0 ]]
72+
do
73+
case "$1" in
74+
*:* )
75+
hostport=(${1//:/ })
76+
HOST=${hostport[0]}
77+
PORT=${hostport[1]}
78+
shift 1
79+
;;
80+
--child)
81+
CHILD=1
82+
shift 1
83+
;;
84+
-q | --quiet)
85+
QUIET=1
86+
shift 1
87+
;;
88+
-s | --strict)
89+
STRICT=1
90+
shift 1
91+
;;
92+
-h)
93+
HOST="$2"
94+
if [[ $HOST == "" ]]; then break; fi
95+
shift 2
96+
;;
97+
--host=*)
98+
HOST="${1#*=}"
99+
shift 1
100+
;;
101+
-p)
102+
PORT="$2"
103+
if [[ $PORT == "" ]]; then break; fi
104+
shift 2
105+
;;
106+
--port=*)
107+
PORT="${1#*=}"
108+
shift 1
109+
;;
110+
-t)
111+
TIMEOUT="$2"
112+
if [[ $TIMEOUT == "" ]]; then break; fi
113+
shift 2
114+
;;
115+
--timeout=*)
116+
TIMEOUT="${1#*=}"
117+
shift 1
118+
;;
119+
--)
120+
shift
121+
CLI="$@"
122+
break
123+
;;
124+
--help)
125+
usage
126+
;;
127+
*)
128+
echoerr "Unknown argument: $1"
129+
usage
130+
;;
131+
esac
132+
done
133+
134+
if [[ "$HOST" == "" || "$PORT" == "" ]]; then
135+
echoerr "Error: you need to provide a host and port to test."
136+
usage
137+
fi
138+
139+
TIMEOUT=${TIMEOUT:-15}
140+
STRICT=${STRICT:-0}
141+
CHILD=${CHILD:-0}
142+
QUIET=${QUIET:-0}
143+
144+
# check to see if timeout is from busybox?
145+
# check to see if timeout is from busybox?
146+
TIMEOUT_PATH=$(realpath $(which timeout))
147+
if [[ $TIMEOUT_PATH =~ "busybox" ]]; then
148+
ISBUSY=1
149+
BUSYTIMEFLAG="-t"
150+
else
151+
ISBUSY=0
152+
BUSYTIMEFLAG=""
153+
fi
154+
155+
if [[ $CHILD -gt 0 ]]; then
156+
wait_for
157+
RESULT=$?
158+
exit $RESULT
159+
else
160+
if [[ $TIMEOUT -gt 0 ]]; then
161+
wait_for_wrapper
162+
RESULT=$?
163+
else
164+
wait_for
165+
RESULT=$?
166+
fi
167+
fi
168+
169+
if [[ $CLI != "" ]]; then
170+
if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then
171+
echoerr "$cmdname: strict mode, refusing to execute subprocess"
172+
exit $RESULT
173+
fi
174+
exec $CLI
175+
else
176+
exit $RESULT
177+
fi

ace-admin/src/main/resources/application.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ spring:
1111
default-property-inclusion: non_null
1212
datasource:
1313
name: test
14-
url: jdbc:mysql://localhost:3306/ag_admin?useUnicode=true&characterEncoding=UTF8
14+
url: jdbc:mysql://${MYSQL_HOST:localhost}:${MYSQL_PORT:3306}/ag_admin?useUnicode=true&characterEncoding=UTF8
1515
username: root
1616
password: 123456
1717
# 使用druid数据源
@@ -31,8 +31,8 @@ spring:
3131
poolPreparedStatements: true
3232
maxOpenPreparedStatements: 20
3333
rabbitmq:
34-
host: localhost
35-
port: 5672
34+
host: ${RABBIT_MQ_HOST:localhost}
35+
port: ${RABBIT_MQ_PORT:5672}
3636
username: guest
3737
password: guest
3838
zipkin:
@@ -52,8 +52,8 @@ eureka:
5252
statusPageUrlPath: /info
5353
healthCheckUrlPath: /health
5454
# docker 部署开启
55-
# prefer-ip-address: true
56-
# ip-address: 127.0.0.1
55+
prefer-ip-address: true
56+
ip-address: 127.0.0.1
5757
client:
5858
serviceUrl:
5959
# defaultZone: http://localhost:8761/eureka/
@@ -111,8 +111,8 @@ redis:
111111
maxActive: 300
112112
maxIdle: 100
113113
maxWait: 1000
114-
host: 127.0.0.1
115-
port: 6379
114+
host: ${REDIS_HOST:localhost}
115+
port: ${REDIS_PORT:6379}
116116
password:
117117
timeout: 2000
118118
# 服务或应用名

ace-auth/ace-auth-server/src/main/resources/application.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ spring:
77
default-property-inclusion: non_null
88
redis:
99
database: 1
10-
host: 127.0.0.1
10+
host: ${REDIS_HOST:localhost}
11+
port: ${REDIS_PORT:6379}
1112
pool:
1213
max-active: 20
1314
datasource:
1415
name: test
15-
url: jdbc:mysql://localhost:3306/ag_auth?useUnicode=true&characterEncoding=UTF8
16+
url: jdbc:mysql://${MYSQL_HOST:localhost}:${MYSQL_PORT:3306}/ag_auth?useUnicode=true&characterEncoding=UTF8
1617
username: root
1718
password: 123456
1819
# 使用druid数据源
@@ -32,8 +33,8 @@ spring:
3233
poolPreparedStatements: true
3334
maxOpenPreparedStatements: 20
3435
rabbitmq:
35-
host: localhost
36-
port: 5672
36+
host: ${RABBIT_MQ_HOST:localhost}
37+
port: ${RABBIT_MQ_PORT:5672}
3738
username: guest
3839
password: guest
3940
zipkin:
@@ -82,8 +83,8 @@ eureka:
8283
statusPageUrlPath: /info
8384
healthCheckUrlPath: /health
8485
# docker 部署开启
85-
# prefer-ip-address: true
86-
# ip-address: 127.0.0.1
86+
prefer-ip-address: true
87+
ip-address: 127.0.0.1
8788
client:
8889
serviceUrl:
8990
# defaultZone: http://localhost:8761/eureka/

ace-common/src/main/java/com/github/wxiaoqi/security/common/constant/RestCodeConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Created by ace on 2017/8/23.
55
*/
66
public class RestCodeConstants {
7+
78
public static final int TOKEN_ERROR_CODE = 40101;
89
public static final int TOKEN_FORBIDDEN_CODE = 40301;
910
}

ace-gate/ace-gate-server/src/main/resources/application.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ spring:
1414
pool:
1515
max-active: 20
1616
rabbitmq:
17-
host: localhost
18-
port: 5672
17+
host: ${RABBIT_MQ_HOST:localhost}
18+
port: ${RABBIT_MQ_PORT:5672}
1919
username: guest
2020
password: guest
2121
zipkin:

docker-compose.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
version: '2'
2+
services:
3+
eureka:
4+
image: ag/ace-center
5+
ports:
6+
- "8761:8761"
7+
ace-auth:
8+
image: ag/ace-auth
9+
ports:
10+
- "9777:9777"
11+
depends_on:
12+
- eureka
13+
environment:
14+
- EUREKA_HOST=eureka
15+
- EUREKA_PORT=8761
16+
- REDIS_HOST=redis
17+
- REDIS_PORT=6379
18+
- MYSQL_HOST=mysql
19+
- MYSQL_PORT=3306
20+
- RABBIT_MQ_HOST=rabbitmq
21+
- RABBIT_MQ_HOST=5672
22+
ace-admin:
23+
image: ag/ace-admin
24+
ports:
25+
- "8762:8762"
26+
links:
27+
- ace-auth
28+
entrypoint: ./wait-for-it.sh ace-auth:9777 -t 600 --
29+
command: java -Djava.security.egd=file:/dev/./urandom -jar /app.jar
30+
environment:
31+
- EUREKA_HOST=eureka
32+
- EUREKA_PORT=8761
33+
- REDIS_HOST=redis
34+
- REDIS_PORT=6379
35+
- MYSQL_HOST=mysql
36+
- MYSQL_PORT=3306
37+
- RABBIT_MQ_HOST=rabbitmq
38+
- RABBIT_MQ_HOST=5672
39+
ace-gate:
40+
image: ag/ace-gate
41+
ports:
42+
- "8765:8765"
43+
links:
44+
- ace-auth
45+
entrypoint: ./wait-for-it.sh ace-auth:9777 -t 600 --
46+
command: java -Djava.security.egd=file:/dev/./urandom -jar /app.jar
47+
environment:
48+
- EUREKA_HOST=eureka
49+
- EUREKA_PORT=8761
50+
- RABBIT_MQ_HOST=rabbitmq
51+
- RABBIT_MQ_HOST=5672
52+
redis:
53+
image: redis
54+
restart: always
55+
ports:
56+
- "6379:6379"
57+
volumes:
58+
- ./.docker/redis:/var/lib/redis

0 commit comments

Comments
 (0)