-
Notifications
You must be signed in to change notification settings - Fork 0
/
startup.sh
74 lines (69 loc) · 1.94 KB
/
startup.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
#! /bin/sh
cd /usr/local/src/script || exit 1
BASE_PATH='/usr/local/src/jenkins/workspace/tjxt-dev-build'
PROJECT_NAME=""
PROJECT_PATH=''
CONTAINER_NAME=""
JAVA_OPTS="-Xms300m -Xmx300m"
PORT=8080
DEBUG_PORT=0
while getopts "c:n:d:p:o:a:" opt; do
case $opt in
c)
CONTAINER_NAME=$OPTARG
;;
n)
PROJECT_NAME=$OPTARG
;;
d)
PROJECT_PATH=$OPTARG
;;
p)
PORT=$OPTARG
;;
o)
[ -n "$OPTARG" ] && JAVA_OPTS=$OPTARG
;;
a)
[ -n "$OPTARG" ] && DEBUG_PORT=$OPTARG
;;
?)
echo "unkonw argument"
exit 1
;;
esac
done
if [ "$DEBUG_PORT" = "0" ]; then
JAVA_OPTS=$JAVA_OPTS
else
JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
fi
IMAGE_NAME="${CONTAINER_NAME}:latest"
echo "copy xx.jar from ${BASE_PATH}/${PROJECT_PATH}"
rm -f app.jar
cp ${BASE_PATH}/${PROJECT_PATH}/target/${PROJECT_NAME}.jar ./app.jar || exit 1
echo "begin to build ${PROJECT_NAME} image !!"
[ -n "`docker ps -a | grep ${CONTAINER_NAME}`" ] && docker rm -f ${CONTAINER_NAME}
[ -n "`docker images | grep ${CONTAINER_NAME}`" ] && docker rmi ${IMAGE_NAME}
docker build -t ${IMAGE_NAME} . || exit 1
echo "${PROJECT_NAME} image build success,java_opts = $JAVA_OPTS !!^_^"
echo "begin to create container ${CONTAINER_NAME},port: ${PORT} !!"
if [ "$DEBUG_PORT" = "0" ]; then
echo "run in normal mode"
docker run -d --name ${CONTAINER_NAME} \
-p "${PORT}:${PORT}" \
-e JAVA_OPTS="${JAVA_OPTS}" \
--memory 300m --memory-swap -1 \
--network heima-net ${IMAGE_NAME} \
|| exit 1
else
echo "run in debug mode"
docker run -d --name ${CONTAINER_NAME} \
-p "${PORT}:${PORT}" \
-p ${DEBUG_PORT}:5005 \
-e JAVA_OPTS="${JAVA_OPTS}" \
--network heima-net ${IMAGE_NAME} \
|| exit 1
fi
echo "container is running now !! ^_^"
exit 0