-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstart.sh
executable file
·66 lines (56 loc) · 1.63 KB
/
start.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
#!/bin/bash
#=================================================================================================
#
# Load docker image with war file
#
#=================================================================================================
# exit script on any error
trap 'docker network disconnect supercharge-net supercharge-db;docker network rm supercharge-net;' ERR
IMAGE_VERSION="1.0"
IMAGE_NAME="supercharge-api"
IMAGE_TAG="${IMAGE_NAME}:${IMAGE_VERSION}"
CONTAINER_NAME="supercharge-api"
SCRIPT_DIR=`dirname $0`;
DB_NAME="supercharge-db"
DB_HOST="$DB_NAME:5432"
CONN=false
#
# Network setup
#
RESP=`docker network ls`
if [[ $RESP != *supercharge-net* ]]; then
CONN=true
docker network create supercharge-net
fi
LIST=`docker ps`
if ! [[ $LIST =~ $DB_NAME($'\n'|$) ]]; then
CONN=true
echo "Starting $DB_NAME..."
RESP=`docker start $DB_NAME`
if [[ $RESP == *"No such container"* ]]; then
echo $RESP
echo "Please create container from database folder first"
exit
fi
fi
if [ "$CONN" = true ]; then
docker network connect supercharge-net $DB_NAME
fi
#
# Build image
#
docker build --tag $IMAGE_TAG "$SCRIPT_DIR/"
if [[ $LIST =~ $CONTAINER_NAME($'\n'|$) ]]; then
docker network disconnect supercharge-net supercharge-api 2> /dev/null
docker stop $CONTAINER_NAME
fi
#
# Create and start the container
#
docker run --name $CONTAINER_NAME \
--detach \
--env "JAVA_OPTS=-Ddb.url=jdbc:postgresql://$DB_HOST/postgres -Dspring.profiles.active=development" \
--rm \
--network supercharge-net \
--publish 8080:8080 \
"$IMAGE_TAG"