-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsamples-cli.sh
executable file
·85 lines (77 loc) · 1.9 KB
/
samples-cli.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
#!/bin/bash
### build ###
function build-app() {
echo ""
echo "===================="
echo "Building application"
echo "===================="
echo ""
mvn clean install -DskipTests && cp -f target/samples.war ./openliberty-dropins/
}
function build-images() {
echo ""
echo "========================="
echo "Building Container images"
echo "========================="
echo ""
docker-compose -f docker-compose.yaml build --no-cache
}
### compose ###
function run-compose() {
echo ""
echo "==================="
echo "Running application"
echo "==================="
echo ""
docker-compose -f docker-compose.yaml up -d
}
function stop-compose() {
echo ""
echo "===================="
echo "Stopping application"
echo "===================="
echo ""
docker-compose -f docker-compose.yaml down --remove-orphans
}
### kubernetes ###
### script ###
COMMAND="${1:-help}"
# Build app
if [ "$COMMAND" = "build-app" ]; then
build-app
fi
# Build docker images
if [ "$COMMAND" = "build-images" ]; then
build-images
fi
# run on docker compose
if [ "$COMMAND" = "up" ]; then
IMAGE_PRESENT=$(docker image ls | grep com.example/samples)
IMAGE_PRESENT=$?
if [ "$IMAGE_PRESENT" = "1" ]; then
echo ""
echo "======================================================="
echo "Container mages are missing, Trying to build them first"
echo "======================================================="
echo ""
build-images
fi
build-app
run-compose
fi
#stop docker compose
if [ "$COMMAND" = "down" ]; then
stop-compose
fi
# help
if [ "$COMMAND" = "help" ]; then
echo ""
echo "Usage:"
echo " samples-cli.sh <command>"
echo "Commands:"
echo " build-app : build app and copy war into deployment dir"
echo " build-images : build docker images"
echo " up : run on docker-compose"
echo " down : stop running on docker-compose"
echo ""
fi