forked from Byloth/cmangos-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmangos-build.sh
executable file
·207 lines (175 loc) · 5.13 KB
/
cmangos-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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/env bash
#
set -e
function docker-build()
{
docker build ${@} \
\
${NO_CACHE} \
${PULL} \
\
--build-arg TIMEZONE="${TIMEZONE}" \
--build-arg EXPANSION="${EXPANSION}" \
--build-arg THREADS="${THREADS}" \
--build-arg COMMIT_SHA="${COMMIT_SHA}" \
--build-arg CREATE_DATE="${TIMESTAMP}" \
--build-arg VERSION="${VERSION_CODE}" \
\
. # There's a `dot` on this line!
}
readonly EXECUTABLE="${0}"
readonly HELP_MSG="
Allows you to build more easily the Docker images
of CMaNGOS you'll need to run the server properly.
Usage:
${EXECUTABLE} [OPTIONS...]
Options:
-x | --target \"runner\" | \"builder\" | \"all\"
Specify the Docker image target to build.
When not specified, the target
is \"runner\" by default.
-e | --expansion \"classic\" | \"tbc\" | \"wotlk\"
Specify the latest game expansion
that CMaNGOS will support.
When not specified, the expansion
is \"tbc\" by default.
-i | --image <name>
Specify the repository that will be
used to name the built Docker image.
When not specified, the prefix
name is \"byloth/cmangos-\${EXPANSION}\" by default.
-v | --version <version>
Specify the tag that will be used
to name the built Docker image.
When not specified, the tag
is \"develop\" by default.
-z | --timezone <timezone>
Specify the timezone that will be injected
as a default into the built Docker image.
When not specified, the timezone
is \"Europe/Rome\" by default.
-t | --threads <number>
Specify the number of threads that
will be used during the build process.
When not specified, the number of
threads is 2 by default.
-C | --no-cache
Force Docker to build the images
from scratch without using any cache.
-p | --pull
Force Docker to pull the latest core
image from DockerHub before building.
-h | -? | --help
Displays this help message.
"
while [[ ${#} -gt 0 ]]
do
case "${1}" in
-x | --target)
if [[ "${2}" != "runner" ]] && [[ "${2}" != "builder" ]] && [[ "${2}" != "all" ]]
then
echo ""
echo -e " ERROR!"
echo -e " └ Invalid target specified: \"${2}\""
echo ""
echo " Run \"${EXECUTABLE} --help\" for more information."
exit 3
fi
readonly TARGET="${2}"
shift
;;
-e | --expansion)
if [[ "${2}" != "classic" ]] && [[ "${2}" != "tbc" ]] && [[ "${2}" != "wotlk" ]]
then
echo ""
echo -e " ERROR!"
echo -e " └ Invalid expansion specified: \"${2}\""
echo ""
echo " Run \"${EXECUTABLE} --help\" for more information."
exit 2
fi
readonly EXPANSION="${2}"
shift
;;
-i | --image)
readonly IMAGE="${2}"
shift
;;
-v | --version)
readonly VERSION="${2}"
shift
;;
-z | --timezone)
readonly TIMEZONE="${2}"
shift
;;
-t | --threads)
if [[ ! "${2}" =~ ^[0-9]+$ ]]
then
echo ""
echo -e " ERROR!"
echo -e " └ Invalid threads number specified: \"${2}\""
echo ""
echo " Run \"${EXECUTABLE} --help\" for more information."
return 4
fi
readonly THREADS="${2}"
shift
;;
-C | --no-cache)
readonly NO_CACHE="--no-cache"
;;
-p | --pull)
readonly PULL="--pull"
;;
-h | -? | --help)
echo -e "${HELP_MSG}"
exit 0
;;
*)
echo ""
echo -e " ERROR!"
echo -e " └ Unknown option: \"${1}\""
echo ""
echo " Run \"${EXECUTABLE} --help\" for more information."
exit 1
;;
esac
shift
done
if [[ -z "${TARGET}" ]]
then
readonly TARGET="runner"
fi
if [[ -z "${EXPANSION}" ]]
then
readonly EXPANSION="tbc"
fi
if [[ -z "${IMAGE}" ]]
then
readonly IMAGE="byloth/cmangos-${EXPANSION}"
fi
if [[ -z "${VERSION}" ]]
then
readonly VERSION="develop"
fi
if [[ -z "${TIMEZONE}" ]]
then
readonly TIMEZONE="Europe/Rome"
fi
if [[ -z "${THREADS}" ]]
then
readonly THREADS="2"
fi
readonly COMMIT_SHA="$(git log -1 --format="%H")"
readonly TIMESTAMP="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
readonly VERSION_CODE="1.0.0-develop+$(date -u +"%Y%m%d%H%M%S")"
if [[ "${TARGET}" == "builder" ]] || [[ "${TARGET}" == "all" ]]
then
docker-build --tag "${IMAGE}/builder:${VERSION}" \
--target "builder"
fi
if [[ "${TARGET}" == "runner" ]] || [[ "${TARGET}" == "all" ]]
then
docker-build --tag "${IMAGE}:${VERSION}"
fi