forked from sourcerer-io/sourcerer-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdo.sh
executable file
·94 lines (77 loc) · 1.91 KB
/
do.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
93
94
#!/bin/bash
#-------------------#
#----- Helpers -----#
#-------------------#
set -x
usage() {
echo "$0 [COMMAND] [ARGUMENTS]"
echo " Commands:"
echo " - build_jar: build jar"
echo " - build_prod_inside: build nginx container"
echo " - run_jar: run jar"
echo " - run_prod: start nginx container"
}
fn_exists() {
type $1 2>/dev/null | grep -q 'is a function'
}
COMMAND=$1
shift
ARGUMENTS=${@}
TAG="${CONTAINER_TAG:-latest}"
NAMESPACE="${NAMESPACE:-sandbox}"
LOG="${LOG:-debug}"
VOLUME="${BUILD_VOLUME:-$PWD}"
PROJECT=sourcerer-app
PORT=3182
REPO_NAME=gcr.io/sourcerer-1377/$PROJECT:$TAG
GRADLE_VERSION=4.2.0
#--------------------#
#----- Commands -----#
#--------------------#
# run only inside build container
build_jar_inside() {
if [ "$NAMESPACE" == "sandbox" ]; then
API="https://sandbox.sourcerer/api/commit"
elif [ "$NAMESPACE" == "staging" ]; then
API="https://staging.sourcerer/api/commit"
elif [ "$NAMESPACE" == "local" ]; then
API="http://localhost:3181"
else
API="https://sourcerer.io/api/commit"
fi
gradle -Penv=$NAMESPACE -Plog=$LOG -Papi=$API build
}
build_jar() {
docker run -i -v $VOLUME:/home/gradle/app --workdir=/home/gradle/app \
-e LOG=$LOG -e NAMESPACE=$NAMESPACE \
gradle:$GRADLE_VERSION \
./do.sh build_jar_inside
}
build_prod_inside() {
docker build -t $REPO_NAME .
}
deploy() {
source ./deploy/${NAMESPACE}_env.sh
envsubst < ./deploy/sourcerer-app.yaml > /tmp/deploy.yaml
kubectl --namespace=$NAMESPACE apply -f /tmp/deploy.yaml
}
######################
run_jar() {
docker run -i -v $VOLUME:/app --workdir=/app gradle:$GRADLE_VERSION \
java -jar build/libs/app.jar
}
run_prod() {
docker run -i -p $PORT:80 $REPO_NAME
}
push() {
gcloud docker -- push $REPO_NAME
}
#---------------------#
#----- Execution -----#
#---------------------#
fn_exists $COMMAND
if [ $? -eq 0 ]; then
$COMMAND $ARGUMENTS
else
usage
fi