-
Notifications
You must be signed in to change notification settings - Fork 279
/
do.sh
executable file
·88 lines (72 loc) · 1.83 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
#!/bin/bash
# Copyright 2017 Sourcerer, Inc. All Rights Reserved.
# Author: Maxim Rusak ([email protected])
set -x
fn_exists() {
type $1 2>/dev/null | grep -q 'is a function'
}
COMMAND=$1
shift
ARGUMENTS=${@}
CONTAINER_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:$CONTAINER_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"
LOG="debug"
elif [ "${NAMESPACE}" == "staging" ]; then
API="https://staging.sourcerer/api/commit"
LOG="info"
elif [ "${NAMESPACE}" == "local" ]; then
API="http://localhost:3181"
LOG="debug"
else
API="https://sourcerer.io/api/commit"
LOG="info"
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
echo "Command not found"
fi