-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.sh.example
122 lines (107 loc) · 3.79 KB
/
env.sh.example
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
#!/usr/bin/env sh
TITLE="DOCKER BUILDER SCRIPT" # script name
VER="1.2" # script version
ENV="development" # (development / production)
REMOVE_CACHE="0" # (0 = using cache, 1 = no-cache)
RECREATE_CONTAINER="0" # (0 = disable recreate container, 1 = force recreate container)
SKIP_BUILD="0" # (0 = with build process, 1 = bypass build process)
USERNAME=`echo $USER`
PATH_HOME=`echo $HOME`
CONTAINER_PRODUCTION="ruby"
CONTAINER_DEVELOPMENT="ruby"
export DOCKER_CLIENT_TIMEOUT=120
export COMPOSE_HTTP_TIMEOUT=120
get_time() {
DATE=`date '+%Y-%m-%d %H:%M:%S'`
}
logo() {
clear
echo "\033[22;32m==========================================================================\033[0m"
echo "\033[22;31m __________ _________ _______ .___________ \033[0m"
echo "\033[22;31m \____ /___________ ____ \_ ___ \\ _ \ __| _/\_____ \ LAB \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;32m--------------------------------------------------------------------------\033[0m"
echo "\033[22;32m# $TITLE :: ver-$VER \033[0m"
}
header() {
logo
echo "\033[22;32m==========================================================================\033[0m"
get_time
echo "\033[22;37m# BEGIN PROCESS..... (Please Wait) \033[0m"
echo "\033[22;33m# Start at: $DATE \033[0m\n"
}
footer() {
echo "\033[22;32m==========================================================================\033[0m"
get_time
echo "\033[22;33m# Finish at: $DATE \033[0m"
echo "\033[22;37m# END PROCESS..... \033[0m\n"
}
build_env() {
if [ "$ENV" = "development" ]
then
BUILD_ENV="$CONTAINER_DEVELOPMENT"
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
}
docker_build() {
if [ "$SKIP_BUILD" = "0" ]
then
echo "--------------------------------------------------------------------------"
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"
for CONTAINER in $BUILD_ENV
do
get_time
echo "--------------------------------------------------------------------------"
echo "\033[22;32m[ $DATE ] docker-compose build $CONTAINER \033[0m "
echo "--------------------------------------------------------------------------"
docker-compose build $CONTAINER
echo ""
done
fi
}
docker_up() {
echo ""
echo "--------------------------------------------------------------------------"
get_time
echo "\033[22;34m[ $DATE ] ##### Docker Compose Up: \033[0m "
echo "\033[22;32m[ $DATE ] docker-compose up $CACHE $BUILD_ENV \033[0m\n "
get_time
echo "--------------------------------------------------------------------------"
echo "\033[22;32m[ $DATE ] docker-compose up $RECREATE $BUILD_ENV \033[0m "
echo "--------------------------------------------------------------------------"
docker-compose up $RECREATE $BUILD_ENV
echo ""
}
main() {
header
cache
recreate
build_env
docker_build
docker_up
footer
}
### START HERE ###
main