-
Notifications
You must be signed in to change notification settings - Fork 44
/
custom_build.sh
executable file
·239 lines (218 loc) · 9.15 KB
/
custom_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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/bin/bash -x
set -e
TAG=${1}
GIT_HASH_COMMAND="`git show -s --format=%H`"
readonly GEOSERVER_VERSION=${2}
readonly GEOSERVER_MASTER_VERSION=${3}
readonly GEOSERVER_DATA_DIR_RELEASE=${4}
readonly PULL=${5}
readonly ALL_PARAMETERS=$*
readonly BASE_BUILD_URL="https://build.geoserver.org/geoserver"
readonly BASE_BUILD_URL_STABLE="https://netcologne.dl.sourceforge.net/project/geoserver/GeoServer"
#readonly BASE_BUILD_URL_STABLE="https://build.geoserver.org/geoserver"
readonly EXTRA_FONTS_URL="https://www.dropbox.com/s/hs5743lwf1rktws/fonts.tar.gz?dl=1"
readonly MARLIN_VERSION=0.9.2
readonly ARTIFACT_DIRECTORY=./resources
readonly GEOSERVER_ARTIFACT_DIRECTORY=${ARTIFACT_DIRECTORY}/geoserver/
readonly DATADIR_ARTIFACT_DIRECTORY=${ARTIFACT_DIRECTORY}/geoserver-datadir/
readonly PLUGIN_ARTIFACT_DIRECTORY=${ARTIFACT_DIRECTORY}/geoserver-plugins
readonly FONTS_ARTIFACT_DIRECTORY=${ARTIFACT_DIRECTORY}/fonts/
readonly MARLIN_ARTIFACT_DIRECTORY=${ARTIFACT_DIRECTORY}/marlin/
readonly USERID=1000
readonly GROUPID=1000
readonly UNAME=tomcat
function help() {
if [ "$#" -ne 5 ] ; then
echo "Usage: $0 [docker image tag] [geoserver version] [geoserver main version] [datadir|nodatadir] [pull|no_pull];"
echo "";
echo "[docker image tag] : the tag to be used for the docker image";
echo "[geoserver version] : the release version of geoserver to be used; you can set it to main if you want the last release";
echo "[geoserver main version] : if you use the main version for geoserver you need to set it to the numerical value for the next release;"
echo " if you use a released version you need to put it to the release number";
echo "[datadir|nodatadir]: datadir: copies ${DATADIR_ARTIFACT_DIRECTORY} in place into the container image, nodatadir: does nothing about any custom datadir";
echo "[pull|no_pull]: docker build use always a remote image or a local image";
exit 1;
fi
}
function clean_up_directory() {
# we shall never clean datadir
echo "rm -rf ./resources/geoserver-plugins/* ./resources/geoserver/*"
}
function create_plugins_folder() {
mkdir -p ./resources/geoserver-plugins
}
function download_from_url_to_a_filepath {
URL=${1}
FILE_PATH=${2}
FILE_DOWNLOADED=$(basename "${FILE_PATH}" )
if [ ! -f "${FILE_PATH}" ]; then
curl -L "${URL}" --output "${FILE_PATH}"
echo "* ${FILE_DOWNLOADED} artefact downloaded *"
else
echo "* ${FILE_DOWNLOADED} artefact already downloaded *"
fi
}
function download_plugin() {
TYPE=${1}
PLUGIN_NAME=${2}
case ${GEOSERVER_VERSION} in
"${GEOSERVER_MASTER_VERSION%.*}")
PLUGIN_FULL_NAME=geoserver-${GEOSERVER_VERSION%.*}-SNAPSHOT-${PLUGIN_NAME}-plugin.zip
PLUGIN_ARTIFACT_URL=${BASE_BUILD_URL}/${GEOSERVER_VERSION}/${TYPE}-latest/${PLUGIN_FULL_NAME}
;;
"main")
PLUGIN_FULL_NAME=geoserver-${GEOSERVER_MASTER_VERSION%.*}-SNAPSHOT-${PLUGIN_NAME}-plugin.zip
PLUGIN_ARTIFACT_URL=${BASE_BUILD_URL}/${GEOSERVER_VERSION}/${TYPE}-latest/${PLUGIN_FULL_NAME}
;;
*)
PLUGIN_FULL_NAME=geoserver-${GEOSERVER_VERSION}-${PLUGIN_NAME}-plugin.zip
if [ "${TYPE}" == "ext" ]; then
NEWTYPE=extensions
PLUGIN_ARTIFACT_URL=${BASE_BUILD_URL_STABLE}/${GEOSERVER_VERSION}/${NEWTYPE}/${PLUGIN_FULL_NAME}
else
VERSION="${GEOSERVER_VERSION%.*}-SNAPSHOT"
PLUGIN_FULL_NAME=geoserver-${VERSION}-${PLUGIN_NAME}-plugin.zip
PLUGIN_ARTIFACT_URL=${BASE_BUILD_URL}/${GEOSERVER_VERSION%.*}.x/${TYPE}-latest/${PLUGIN_FULL_NAME}
fi
;;
esac
download_from_url_to_a_filepath "${PLUGIN_ARTIFACT_URL}" "${PLUGIN_ARTIFACT_DIRECTORY}/${PLUGIN_FULL_NAME}"
}
function download_fonts() {
if [ ! -e "${FONTS_ARTIFACT_DIRECTORY}" ]; then
mkdir -p "${FONTS_ARTIFACT_DIRECTORY}"
fi
download_from_url_to_a_filepath "${EXTRA_FONTS_URL}" "${FONTS_ARTIFACT_DIRECTORY}/fonts.tar.gz"
}
function download_marlin() {
IFS='.' read -r -a marlin_v_arr <<< "$MARLIN_VERSION"
unset IFS
marlin_major=${marlin_v_arr[0]}
marlin_minor=${marlin_v_arr[1]}
marlin_patch=${marlin_v_arr[2]}
if [ ! -e "${MARLIN_ARTIFACT_DIRECTORY}" ]; then
mkdir -p "${MARLIN_ARTIFACT_DIRECTORY}"
fi
marlin_url_1="https://github.com/bourgesl/marlin-renderer/releases/download/v${marlin_major}_${marlin_minor}_${marlin_patch}/marlin-${marlin_major}.${marlin_minor}.${marlin_patch}-Unsafe.jar"
marlin_url_2="https://github.com/bourgesl/marlin-renderer/releases/download/v${marlin_major}_${marlin_minor}_${marlin_patch}/marlin-${marlin_major}.${marlin_minor}.${marlin_patch}-Unsafe-sun-java2d.jar"
download_from_url_to_a_filepath "${marlin_url_1}" "${MARLIN_ARTIFACT_DIRECTORY}/marlin-${marlin_major}.${marlin_minor}.${marlin_patch}-Unsafe.jar"
download_from_url_to_a_filepath "${marlin_url_2}" "${MARLIN_ARTIFACT_DIRECTORY}/marlin-${marlin_major}.${marlin_minor}.${marlin_patch}-Unsafe-sun-java2d.jar"
}
function download_geoserver() {
clean_up_directory ${GEOSERVER_ARTIFACT_DIRECTORY}
local VERSION=${1}
local GEOSERVER_FILE_NAME_NIGHTLY="geoserver-${VERSION}-latest-war.zip"
local GEOSERVER_FILE_NAME_STABLE="geoserver-${VERSION}-war.zip"
if [[ ( "${VERSION}" =~ "x" ) || ( "${VERSION}" == "main" ) ]]; then
local GEOSERVER_ARTIFACT_URL=${BASE_BUILD_URL}/${VERSION}/${GEOSERVER_FILE_NAME_NIGHTLY}
else
local GEOSERVER_ARTIFACT_URL=${BASE_BUILD_URL_STABLE}/${VERSION}/${GEOSERVER_FILE_NAME_STABLE}
fi
if [ -f /tmp/geoserver.war.zip ]; then
rm /tmp/geoserver.war.zip
fi
if [ ! -e "${GEOSERVER_ARTIFACT_DIRECTORY}" ]; then
mkdir -p "${GEOSERVER_ARTIFACT_DIRECTORY}"
fi
if [ -f "${GEOSERVER_ARTIFACT_DIRECTORY}/geoserver.war" ]; then
rm "${GEOSERVER_ARTIFACT_DIRECTORY}/geoserver.war"
fi
download_from_url_to_a_filepath "${GEOSERVER_ARTIFACT_URL}" "${GEOSERVER_ARTIFACT_DIRECTORY}/geoserver.${GEOSERVER_VERSION}.war.zip"
unzip "${GEOSERVER_ARTIFACT_DIRECTORY}/geoserver.${GEOSERVER_VERSION}.war.zip" geoserver.war -d "${GEOSERVER_ARTIFACT_DIRECTORY}"
}
function build_with_data_dir() {
local TAG=${1}
local PULL_ENABLED=${2}
DOCKER_VERSION="$(docker --version | grep "Docker version"| awk '{print $3}' | sed 's/,//')"
case $DOCKER_VERSION in
2[0-9].*|3[0-9].*)
if [[ "${PULL_ENABLED}" == "pull" ]]; then
DOCKER_BUILD_COMMAND="docker buildx build --pull"
else
DOCKER_BUILD_COMMAND="docker buildx build"
fi;
;;
*"19"*)
if [[ "${PULL_ENABLED}" == "pull" ]]; then
DOCKER_BUILD_COMMAND="docker build --pull --no-cache"
else
DOCKER_BUILD_COMMAND="docker build --no-cache"
fi;
;;
*"18"*)
if [[ "${PULL_ENABLED}" == "pull" ]]; then
DOCKER_BUILD_COMMAND="docker build --pull --no-cache"
else
DOCKER_BUILD_COMMAND="docker build --no-cache"
fi;
;;
*)
echo "Docker version $DOCKER_VERSION is not supported by this script."
exit 1
;;
esac
${DOCKER_BUILD_COMMAND} --build-arg GEOSERVER_WEBAPP_SRC=${GEOSERVER_ARTIFACT_DIRECTORY}/geoserver.war \
--build-arg PLUG_IN_PATHS=$PLUGIN_ARTIFACT_DIRECTORY \
--build-arg GEOSERVER_DATA_DIR_SRC=${DATADIR_ARTIFACT_DIRECTORY} \
--build-arg UID=${USERID} --build-arg GID=${GROUPID} --build-arg UNAME=${UNAME} \
--build-arg GIT_HASH=${GIT_HASH_COMMAND} \
-t geosolutionsit/geoserver:"${TAG}-${GEOSERVER_VERSION}" \
.
}
function build_without_data_dir() {
local TAG=${1}
local PULL_ENABLED=${2}
DOCKER_VERSION="$(docker --version | grep "Docker version"| awk '{print $3}' | sed 's/,//')"
case $DOCKER_VERSION in
2[0-9].*|3[0-9].*)
docker builder prune --all -f
if [[ "${PULL_ENABLED}" == "pull" ]]; then
DOCKER_BUILD_COMMAND="docker buildx build --pull"
else
DOCKER_BUILD_COMMAND="docker buildx build"
fi;
;;
*"19"*)
if [[ "${PULL_ENABLED}" == "pull" ]]; then
DOCKER_BUILD_COMMAND="docker build --pull --no-cache"
else
DOCKER_BUILD_COMMAND="docker build --no-cache"
fi;
;;
*"18"*)
if [[ "${PULL_ENABLED}" == "pull" ]]; then
DOCKER_BUILD_COMMAND="docker build --pull --no-cache"
else
DOCKER_BUILD_COMMAND="docker build --no-cache"
fi;
;;
*)
echo "Docker version $DOCKER_VERSION is not supported by this script."
exit 1
;;
esac
${DOCKER_BUILD_COMMAND} --build-arg GEOSERVER_WEBAPP_SRC=${GEOSERVER_ARTIFACT_DIRECTORY}/geoserver.war \
--build-arg PLUG_IN_PATHS=$PLUGIN_ARTIFACT_DIRECTORY \
--build-arg UID=${USERID} --build-arg GID=${GROUPID} --build-arg UNAME=${UNAME} \
--build-arg GIT_HASH=${GIT_HASH_COMMAND} \
-t geosolutionsit/geoserver:"${TAG}-${GEOSERVER_VERSION}" \
.
}
function main {
help ${ALL_PARAMETERS}
clean_up_directory
download_geoserver "${GEOSERVER_VERSION}"
create_plugins_folder
# download_plugin ext monitor
# download_plugin ext control-flow
# download_plugin ext geofence-plugin
# download_plugin ext geofence-server-plugin
# download_plugin community sec-oauth2-geonode
#download_marlin
if [ "${GEOSERVER_DATA_DIR_RELEASE}" = "nodatadir" ]; then
build_without_data_dir "${TAG}" "${PULL}"
else
build_with_data_dir "${TAG}" "${PULL}"
fi
}
main