-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
133 lines (107 loc) · 3.61 KB
/
build.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env bash
function build_images() {
echo "${MAGENTA}BUILD CONTAINERS"
command -v curl 1>/dev/null || { echo "${ERROR}curl required" && exit 1; }
command -v jq 1>/dev/null || { echo "${ERROR}jq required" && exit 1; }
if [[ $KITSU_VERSION == "latest" ]]; then
export KITSU_VERSION=`curl https://api.github.com/repos/cgwire/kitsu/commits | jq -r '.[].commit.message | select(. | test("[0-9]+(\\\\.[0-9]+)+"))?' | grep -m1 ""`
echo "${GREEN}Set KITSU_VERSION to $KITSU_VERSION"
fi
if [[ $ZOU_VERSION == "latest" ]]; then
export ZOU_VERSION=`curl https://api.github.com/repos/cgwire/zou/commits | jq -r '.[].commit.message | select(. | test("[0-9]+(\\\\.[0-9]+)+"))?' | grep -m1 ""`
echo "${GREEN}Set ZOU_VERSION to $ZOU_VERSION"
fi
if [ ! -e "./nginx/Dockerfile" ] || [ ! -e "./zou/Dockerfile" ]; then
echo "${ERROR}Nginx (Kitsu and silex-front) and Zou Dockerfiles required"
exit 1
fi
docker-compose -f docker-compose.yml -f docker-compose.build.yml build --force-rm --pull --compress
}
function compose_up() {
echo "${YELLOW}START CONTAINERS"
if [ ${BUILD} == 1 ]; then
docker-compose -f docker-compose.yml -f docker-compose.build.yml up -d
else
docker-compose pull --include-deps
docker-compose up -d
fi
if [[ "${ENABLE_JOB_QUEUE}" != "True" ]]; then
echo "${YELLOW}DISABLE ZOU ASYNC JOBS"
docker-compose stop zou-jobs
fi
until docker-compose exec -T db pg_isready ; do
sleep 3
echo "${YELLOW}Waiting for db..."
done
}
function compose_down() {
echo "${YELLOW}STOP CONTAINERS"
docker-compose down --remove-orphans
}
function init_zou() {
dbowner=postgres
dbname=zoudb
if docker-compose exec db psql -U ${dbowner} ${dbname} -c '' 2>&1; then
echo "${GREEN}UPGRADE ZOU"
docker-compose exec zou-app sh upgrade_zou.sh
else
echo "${GREEN}INIT ZOU"
docker-compose exec db su - postgres -c "createdb -T template0 -E UTF8 --owner ${dbowner} ${dbname}"
docker-compose exec zou-app sh init_zou.sh
fi
}
# --------------------------------------------------------------
# ---------------------------- ARGS ----------------------------
# --------------------------------------------------------------
source common.sh
BUILD=0
DOWN=0
export ENV_FILE=./env
echo "${BLUE}PARSE ARGS"
for i in "$@"; do
case $i in
-l | --local)
BUILD=1
echo "${CYAN}USE LOCAL BUILD"
shift
;;
-e=* | --env=*)
export ENV_FILE="${i#*=}"
echo "${CYAN}USE CUSTOM ENV FILE"
shift
;;
-d | --down)
DOWN=1
echo "${CYAN}STOP INSTANCE"
shift
;;
-h | --help)
echo "
Usage:
build.sh [options]
Flags:
-l, --local Use local images
-e, --env=ENV_FILE Set custom env file. If not set ./env is used
-d, --down Compose down the stack
-h, --help Show this help
"
exit 0
;;
*)
echo "${ERROR}Invalid flag ${i} // Use -h or --help to print help"
exit 1
;;
esac
done
# --------------------------------------------------------------
# ---------------------------- MAIN ----------------------------
# --------------------------------------------------------------
source_env ${ENV_FILE}
compose_down
if [ $DOWN == 0 ]; then
if [ $BUILD == 1 ]; then
build_images
fi
compose_up
init_zou
fi