This repository has been archived by the owner on Mar 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.sh
executable file
·261 lines (223 loc) · 7.36 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
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/bin/bash
: '
eXist-db Docker Image builder
Copyright (C) 2017 Evolved Binary Ltd
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'
set -e
# set -x
SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
TARGET="${SCRIPT_PATH}/target"
EXIST_CLONE="${TARGET}/exist"
EXIST_MINIMAL="${TARGET}/exist-minimal"
EXIST_MODS="${TARGET}"
##
# Shows the usage message and exits
##
exit_with_usage() {
echo "Usage: ./build.sh [options] <branch>"
echo ""
echo "--no-experimental Don't use experimental Docker features"
echo "--minimal Create a minimal eXist-db server Docker image"
echo "--no-recompile Only perform docker build without rebuilding eXist-db"
echo "--config <conf.xml> Supply custom conf.xml"
echo ""
exit 1
}
##
# Given a built eXist-db Git clone, outputs the minimum needed to run eXist-db server
#
# @param $1 path to eXist-db clone folder
# @param $2 path to output folder
##
minify_exist() {
EXIST_CLONE="${1}"
EXIST_MINIMAL="${2}"
copy_extension_libs() {
EXTENSION_NAME="${1}"
mkdir -p "${EXIST_MINIMAL}/extensions/${EXTENSION_NAME}"
cp -r "${EXIST_CLONE}/extensions/${EXTENSION_NAME}/lib" "${EXIST_MINIMAL}/extensions/${EXTENSION_NAME}"
}
if [ ! -d "$EXIST_MINIMAL" ]
then
mkdir -p "${EXIST_MINIMAL}"
else
# make sure we start with a clean build
rm -rf "${EXIST_MINIMAL}/*"
fi
# copy sundries
cp "${EXIST_CLONE}/LICENSE" "${EXIST_CLONE}/README.md" "${EXIST_MINIMAL}"
# copy base folders
cp -r "${EXIST_CLONE}/autodeploy" "${EXIST_CLONE}/bin" "${EXIST_MINIMAL}"
# copy base libs
cp "${EXIST_CLONE}/start.jar" "${EXIST_CLONE}/exist.jar" "${EXIST_CLONE}/exist-optional.jar" "${EXIST_MINIMAL}"
mkdir -p "${EXIST_MINIMAL}/lib"
cp -r "${EXIST_CLONE}/lib/core" "${EXIST_CLONE}/lib/endorsed" "${EXIST_CLONE}/lib/optional" "${EXIST_CLONE}/lib/extensions" "${EXIST_CLONE}/lib/user" "${EXIST_CLONE}/lib/test" "${EXIST_MINIMAL}/lib"
# copy config files
cp "${EXIST_CLONE}/descriptor.xml" "${EXIST_CLONE}/log4j2.xml" "${EXIST_CLONE}/mime-types.xml" "${EXIST_MINIMAL}"
# copy tools
mkdir -p "${EXIST_MINIMAL}/tools"
cp -r "${EXIST_CLONE}/tools/ant" "${EXIST_CLONE}/tools/aspectj" "${EXIST_CLONE}/tools/jetty" "${EXIST_MINIMAL}/tools"
# copy webapp
mkdir -p "${EXIST_MINIMAL}/webapp/WEB-INF"
cp -r "${EXIST_CLONE}/webapp/404.html" "${EXIST_CLONE}/webapp/controller.xql" "${EXIST_CLONE}/webapp/logo.jpg" "${EXIST_CLONE}/webapp/resources" "${EXIST_MINIMAL}/webapp"
cp -r "${EXIST_CLONE}/webapp/WEB-INF/betterform-version.info" "${EXIST_CLONE}/webapp/WEB-INF/catalog.xml" "${EXIST_CLONE}/webapp/WEB-INF/controller-config.xml" "${EXIST_CLONE}/webapp/WEB-INF/entities" "${EXIST_CLONE}/webapp/WEB-INF/web.xml" "${EXIST_MINIMAL}/webapp/WEB-INF"
# copy extension libs
copy_extension_libs modules
copy_extension_libs betterform/main
copy_extension_libs contentextraction
copy_extension_libs webdav
copy_extension_libs xprocxq/main
copy_extension_libs xqdoc
copy_extension_libs expath
copy_extension_libs exquery
copy_extension_libs exquery/restxq
copy_extension_libs indexes/lucene
}
# Extract arguments
EXPERIMENTAL=YES # YES to use Docker experimental features, NO otherwise
MINIMAL=NO # YES to create a minimal eXist-db server Docker image,$ NO for a full image
SHOW_USAGE=NO # YES to show the usage message, NO otherwise
NORECOMPILE=NO # YES to only run docker build without building exist-db again
DOCKERFILE="Dockerfile"
for i in "$@"
do
case $i in
-n|--no-experimental)
EXPERIMENTAL=NO
shift
;;
-m|--minimal)
MINIMAL=YES
shift
;;
-nr|--no-recompile)
NORECOMPILE=YES
shift
;;
-c|--config)
CUSTOM_CONF="$1";
shift
;;
-h|--help)
SHOW_USAGE=YES
shift
;;
*)
# unknown option
;;
esac
done
if [ "$MINIMAL" == "YES" ]; then SUFFIX="$SUFFIX-minimal"; fi
DOCKERFILE="${DOCKERFILE}${SUFFIX}"
BRANCH_NAME="${1}"
CONTAINER_EXIST_PATH=/exist
CONTAINER_EXIST_DATA_PATH=/exist-data
if [ "$SHOW_USAGE" == "YES" ]
then
exit_with_usage
fi
if [ -z ${BRANCH_NAME} ]
then
echo "You must specify a branch to build!"
echo ""
exit_with_usage
fi
if [ ! "$NORECOMPILE" == "YES" ]
then
command -v git >/dev/null 2>&1 || { echo "An installation of Git client is required, but could not be found... Aborting." >&2; exit 2; }
command -v java >/dev/null 2>&1 || { echo "An installation of Java 8 is required, but could not be found... Aborting." >&2; exit 3; }
if [ ! -f "${CUSTOM_CONF}" ]
then
command -v augtool >/dev/null 2>&1 || { echo "An installation of Augeas (augtool) is required, but could not be found... Aborting." >&2; exit 4; }
fi
fi
if [ ! -d "$TARGET" ]
then
mkdir -p "${TARGET}"
fi
# Either get or update from GitHub eXist-db
if [ ! -d "$EXIST_CLONE" ]
then
NORECOMPILE=NO
git clone https://github.com/exist-db/exist.git "${EXIST_CLONE}"
cd "${EXIST_CLONE}"
git checkout "${BRANCH_NAME}"
else
if [ "$NORECOMPILE" == "YES" ]
then
echo "Not re-building eXist-db, --docker-only option selected"
else
cd "${EXIST_CLONE}"
git fetch origin
git checkout "${BRANCH_NAME}"
if git describe --exact-match --tags HEAD > /dev/null
then
# this is a tag, don't need to rebase (update)
echo "On tag: ${BRANCH_NAME}"
else
# this is a branch, rebase to make sure we are up to date
git rebase "origin/${BRANCH_NAME}"
echo "Updated branch: ${BRANCH_NAME}"
fi
fi
fi
if [ "$NORECOMPILE" != "YES" ]
then
# Build/Rebuild eXist-db
cd "${EXIST_CLONE}"
EXIST_HOME="${EXIST_CLONE}" ./build.sh clean && EXIST_HOME="${EXIST_CLONE}" ./build.sh
fi
# Back to the root
cd "${SCRIPT_PATH}"
# Create the updated conf.xml
if [ ! -d "$EXIST_MODS" ]
then
mkdir "${EXIST_MODS}"
fi
UPDATED_CONF="${EXIST_MODS}/conf.xml"
if [ -f "$CUSTOM_CONF" ]
then
cp "${CUSTOM_CONF}" "${UPDATED_CONF}"
else
cp "${EXIST_CLONE}/conf.xml" "${UPDATED_CONF}"
cat << EOF | augtool --noload --noautoload
set /augeas/load/xml/lens "Xml.lns"
set /augeas/load/xml/incl "${UPDATED_CONF}"
load
set /files/$UPDATED_CONF/exist/db-connection/#attribute/files $CONTAINER_EXIST_DATA_PATH
set /files/$UPDATED_CONF/exist/db-connection/recovery/#attribute/journal-dir $CONTAINER_EXIST_DATA_PATH
save
EOF
fi
# should we minify the eXist-db we put into the Docker Image?
if [ "$MINIMAL" == "YES" ]
then
echo "Minifying to $EXIST_MINIMAL"
minify_exist "$EXIST_CLONE" "$EXIST_MINIMAL"
fi
# Build Docker image
EXPERIMENTAL_ARGS=""
if [ "$EXPERIMENTAL" == "YES" ]
then
EXPERIMENTAL_ARGS="--squash"
fi
BRANCH_NAME="${BRANCH_NAME}${SUFFIX}"
if [ ! -f "$DOCKERFILE" ]
then
echo "A Dockerfile for this combination of options does not exist. $DOCKERFILE does not exist."
else
docker build \
--build-arg VCS_REF=`git rev-parse --short HEAD` \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--rm --force-rm $EXPERIMENTAL_ARGS -t "evolvedbinary/exist-db:${BRANCH_NAME}" --file "${DOCKERFILE}" . 1> build.log 2> errors.log
fi