-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
executable file
·92 lines (77 loc) · 1.95 KB
/
bootstrap.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
#!/bin/bash
PROJECT_NAME=geoloc
DOCKER_IMAGE=$PROJECT_NAME:latest
DIR=$(pwd)
DOCKER_DIR=$DIR/docker
TARGET_DIR=$DIR/target
JAR_VERSION=1.0.0
JAR_FILE=$PROJECT_NAME-$JAR_VERSION.jar
COMPOSE_FILE=$DIR/compose/$PROJECT_NAME.yml
build() {
$DIR/./mvnw clean install
echo "removing old image '$DOCKER_IMAGE' inorder to build latest again"
docker rmi $DOCKER_IMAGE
echo "building new docker image for $PROJECT_NAME..."
/bin/cp -f $TARGET_DIR/$JAR_FILE $DOCKER_DIR/$JAR_FILE
touch $DOCKER_DIR/$PROJECT_NAME.log
docker build -t $DOCKER_IMAGE $DOCKER_DIR
}
run() {
docker-compose -p $PROJECT_NAME -f $COMPOSE_FILE up -d
echo "Sleepng for 3 seconds ..."
sleep 3
}
stop() {
docker-compose -p $PROJECT_NAME -f $COMPOSE_FILE down
}
top() {
docker-compose -p $PROJECT_NAME -f $COMPOSE_FILE top
}
tail() {
NAME=$1
docker-compose -p $PROJECT_NAME -f $COMPOSE_FILE logs -f $NAME
}
list() {
docker-compose -p $PROJECT_NAME -f $COMPOSE_FILE config --services
}
status() {
docker-compose -p $PROJECT_NAME -f $COMPOSE_FILE ps
}
OPTION=$1
case $OPTION in
build)
echo "Building docker image for ${PROJECT_NAME}"
build
;;
run)
echo "Running containers for ${PROJECT_NAME} in detached mode"
run
;;
stop)
echo "Stopping all containers for ${PROJECT_NAME}"
stop
;;
display)
echo "Containers in ${PROJECT_NAME}"
top
;;
tail)
tail $2
;;
list)
list
;;
status)
status
;;
*)
echo "Did you forget something!! [ build | run | stop | list | tail | status | display ]"
echo "-- Options --"
echo "build : Builds the docker image for ${PROJECT_NAME}"
echo "run : Runs the complete container in detached mode"
echo "stop : Stops and remove the complete container"
echo "list : List all the services in the container"
echo "status : Status of all the services in the container"
echo "tail <service_name> : Tail the logs of the service"
echo "display : Shows the top output for all the services"
esac