-
Notifications
You must be signed in to change notification settings - Fork 3
/
dockube-build.sh
executable file
·170 lines (149 loc) · 4.91 KB
/
dockube-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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env sh
# -----------------------------------------------------------------------------
# DOCKER BUILDER SCRIPT
# -----------------------------------------------------------------------------
# Author : Dwi Fahni Denni (@zeroc0d3)
# Repository : https://github.com/dockube/dockube
# License : Apache v2
# -----------------------------------------------------------------------------
TITLE="DOCKUBE-CONTAINER BUILDER SCRIPT" # script name
VER="1.4.4" # script version
ENV="0" # container environment (0 = development, 1 = staging, 2 = production)
SKIP_BUILD="0" # (0 = with build process, 1 = bypass build process)
REMOVE_CACHE="0" # (0 = using cache, 1 = no-cache)
RECREATE_CONTAINER="0" # (0 = disable recreate container, 1 = force recreate container)
DAEMON_MODE="1" # (0 = disable daemon mode, 1 = running daemon mode / background)
USERNAME=`echo $USER`
PATH_HOME=`echo $HOME`
CONTAINER_PRODUCTION="portainer dockube-master dockube-node dockube-nfs"
CONTAINER_STAGING="portainer dockube-master dockube-node dockube-nfs"
CONTAINER_DEVELOPMENT="portainer dockube-master dockube-node dockube-nfs"
export DOCKER_CLIENT_TIMEOUT=300
export COMPOSE_HTTP_TIMEOUT=300
get_time() {
DATE=`date '+%Y-%m-%d %H:%M:%S'`
}
print_line0() {
echo "\033[22;32m==========================================================================\033[0m"
}
print_line1() {
echo "\033[22;32m--------------------------------------------------------------------------\033[0m"
}
print_line2() {
echo "--------------------------------------------------------------------------"
}
logo() {
clear
print_line0
echo "\033[22;31m'########:::'#######:::'######::'##:::'##:'##::::'##:'########::'########:\033[0m"
echo "\033[22;31m ##.... ##:'##.... ##:'##... ##: ##::'##:: ##:::: ##: ##.... ##: ##.....::\033[0m"
echo "\033[22;31m ##:::: ##: ##:::: ##: ##:::..:: ##:'##::: ##:::: ##: ##:::: ##: ##:::::::\033[0m"
echo "\033[22;31m ##:::: ##: ##:::: ##: ##::::::: #####:::: ##:::: ##: ########:: ######:::\033[0m"
echo "\033[22;31m ##:::: ##: ##:::: ##: ##::::::: ##. ##::: ##:::: ##: ##.... ##: ##...::::\033[0m"
echo "\033[22;31m ##:::: ##: ##:::: ##: ##::: ##: ##:. ##:: ##:::: ##: ##:::: ##: ##:::::::\033[0m"
echo "\033[22;31m ########::. #######::. ######:: ##::. ##:. #######:: ########:: ########:\033[0m"
echo "\033[22;31m........::::.......::::......:::..::::..:::.......:::........:::........::\033[0m"
print_line1
echo "\033[22;32m# $TITLE :: ver-$VER \033[0m"
}
header() {
logo
print_line0
get_time
echo "\033[22;31m# BEGIN PROCESS..... (Please Wait) \033[0m"
echo "\033[22;31m# Start at: $DATE \033[0m\n"
}
footer() {
print_line0
get_time
echo "\033[22;31m# Finish at: $DATE \033[0m"
echo "\033[22;31m# END PROCESS..... \033[0m\n"
}
build_env() {
if [ "$ENV" = "0" ]
then
BUILD_ENV="$CONTAINER_DEVELOPMENT"
elif [ "$ENV" = "1" ]
then
BUILD_ENV="$CONTAINER_STAGING"
else
BUILD_ENV="$CONTAINER_PRODUCTION"
fi
}
cache() {
if [ "$REMOVE_CACHE" = "0" ]
then
CACHE=""
else
CACHE="--no-cache "
fi
}
recreate() {
if [ "$RECREATE_CONTAINER" = "0" ]
then
RECREATE=""
else
RECREATE="--force-recreate "
fi
}
daemon_mode() {
if [ "$DAEMON_MODE" = "0" ]
then
DAEMON=""
else
DAEMON="-d "
fi
}
docker_build() {
if [ "$SKIP_BUILD" = "0" ]
then
print_line2
get_time
echo "\033[22;34m[ $DATE ] ##### Docker Compose: \033[0m "
echo "\033[22;32m[ $DATE ] docker-compose build $CACHE$BUILD_ENV \033[0m\n"
## MULTI CONTAINER
## ------------------------------
for CONTAINER in $BUILD_ENV
do
get_time
print_line2
echo "\033[22;32m[ $DATE ] docker-compose build $CONTAINER \033[0m "
print_line2
docker-compose build $CONTAINER
echo ""
done
## SINGLE CONTAINER (test)
## ------------------------------
## get_time
## echo "--------------------------------------------------------------------------"
## echo "\033[22;32m[ $DATE ] docker-compose build $BUILD_ENV \033[0m "
## echo "--------------------------------------------------------------------------"
## docker-compose build $BUILD_ENV
## echo ""
fi
}
docker_up() {
daemon_mode
echo ""
print_line2
get_time
echo "\033[22;34m[ $DATE ] ##### Docker Compose Up: \033[0m "
echo "\033[22;32m[ $DATE ] docker-compose up $RECREATE$BUILD_ENV \033[0m\n "
get_time
print_line2
echo "\033[22;32m[ $DATE ] docker-compose up $RECREATE$BUILD_ENV \033[0m "
print_line2
docker-compose up $DAEMON $RECREATE$BUILD_ENV
echo ""
}
main() {
header
cache
recreate
build_env
docker_build
docker_up
footer
}
### START HERE ###
main $@