-
Notifications
You must be signed in to change notification settings - Fork 3
/
percona-mongodb-mongosh-builder.sh
328 lines (308 loc) · 9.65 KB
/
percona-mongodb-mongosh-builder.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#!/bin/sh
shell_quote_string() {
echo "$1" | sed -e 's,\([^a-zA-Z0-9/_.=-]\),\\\1,g'
}
usage () {
cat <<EOF
Usage: $0 [OPTIONS]
The following options may be given :
--builddir=DIR Absolute path to the dir where all actions will be performed
--get_sources Source will be downloaded from github
--build_src_rpm If it is set - src rpm will be built
--build_src_deb If it is set - source deb package will be built
--build_mongosh If it is set - mongosh will be built
--build_variant Varint to build(rpm-x64, deb-x64, linux-x64)
--install_deps Install build dependencies(root privilages are required)
--branch Branch for build
--repo Repo for build
--version Version to build
--help) usage ;;
Example $0 --builddir=/tmp/percona-mongodb-mongosh --get_sources=1 --build_src_rpm=1
EOF
exit 1
}
append_arg_to_args () {
args="$args "$(shell_quote_string "$1")
}
parse_arguments() {
pick_args=
if test "$1" = PICK-ARGS-FROM-ARGV
then
pick_args=1
shift
fi
for arg do
val=$(echo "$arg" | sed -e 's;^--[^=]*=;;')
case "$arg" in
--builddir=*) WORKDIR="$val" ;;
--build_src_rpm=*) SRPM="$val" ;;
--build_src_deb=*) SDEB="$val" ;;
--get_sources=*) SOURCE="$val" ;;
--branch=*) BRANCH="$val" ;;
--repo=*) REPO="$val" ;;
--version=*) VERSION="$val" ;;
--install_deps=*) INSTALL="$val" ;;
--build_mongosh=*) MONGOSH="$val" ;;
--build_variant=*) VARIANT="$val" ;;
--help) usage ;;
*)
if test -n "$pick_args"
then
append_arg_to_args "$arg"
fi
;;
esac
done
}
check_workdir(){
if [ "x$WORKDIR" = "x$CURDIR" ]
then
echo >&2 "Current directory cannot be used for building!"
exit 1
else
if ! test -d "$WORKDIR"
then
echo >&2 "$WORKDIR is not a directory."
exit 1
fi
fi
return
}
get_sources(){
cd "${WORKDIR}"
if [ "${SOURCE}" = 0 ]
then
echo "Sources will not be downloaded"
return 0
fi
PRODUCT=percona-mongodb-mongosh
echo "PRODUCT=${PRODUCT}" > percona-mongodb-mongosh.properties
echo "BUILD_NUMBER=${BUILD_NUMBER}" >> percona-mongodb-mongosh.properties
echo "BUILD_ID=${BUILD_ID}" >> percona-mongodb-mongosh.properties
echo "VERSION=${VERSION}" >> percona-mongodb-mongosh.properties
echo "BRANCH=${BRANCH}" >> percona-mongodb-mongosh.properties
rm -rf ${PRODUCT}
git clone "$REPO" ${PRODUCT}
retval=$?
if [ $retval != 0 ]
then
echo "There were some issues during repo cloning from github. Please retry one more time"
exit 1
fi
cd ${PRODUCT}
if [ ! -z "$BRANCH" ]
then
git reset --hard
git clean -xdf
git checkout -b "$BRANCH" "$BRANCH"
fi
REVISION=$(git rev-parse --short HEAD)
GITCOMMIT=$(git rev-parse HEAD 2>/dev/null)
GITBRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
NODE_JS_VERSION=$(grep -oP '(?<="version": ")[^"]*' .evergreen/node-20-latest.json)
echo "export VERSION=${VERSION}" > VERSION
echo "export REVISION=${REVISION}" >> VERSION
echo "export GITCOMMIT=${GITCOMMIT}" >> VERSION
echo "export GITBRANCH=${GITBRANCH}" >> VERSION
echo "export NODE_JS_VERSION=${NODE_JS_VERSION}" >> VERSION
echo "export REVISION=${REVISION}" >> ${WORKDIR}/percona-mongodb-mongosh.properties
cd ${WORKDIR}
rm -fr debian rpm ${PRODUCT}-${VERSION}
mv ${PRODUCT} ${PRODUCT}-${VERSION}
pushd ${PRODUCT}-${VERSION}
cp ../../mongosh.patch .
git apply ./mongosh.patch || exit 1
rm ./mongosh.patch
grep -r -l "0\.0\.0\-dev\.0" . | xargs sed -i "s:0.0.0-dev.0:${VERSION}:g"
#rm -rf ./scripts/nodejs-patches/*
popd
tar --owner=0 --group=0 --exclude=.* -czf ${PRODUCT}-${VERSION}.tar.gz ${PRODUCT}-${VERSION}
echo "UPLOAD=UPLOAD/experimental/BUILDS/${PRODUCT}/${PRODUCT}-${VERSION}/${BRANCH}/${REVISION}/${BUILD_ID}" >> percona-mongodb-mongosh.properties
mkdir -p $WORKDIR/source_tarball
mkdir -p $CURDIR/source_tarball
cp ${PRODUCT}-${VERSION}.tar.gz $WORKDIR/source_tarball
cp ${PRODUCT}-${VERSION}.tar.gz $CURDIR/source_tarball
cd $CURDIR
rm -rf ${PRODUCT}
return
}
get_system(){
if [ -f /etc/redhat-release ]; then
RHEL=$(rpm --eval %rhel)
ARCH=$(echo $(uname -m) | sed -e 's:i686:i386:g')
OS_NAME="el$RHEL"
OS="rpm"
else
ARCH=$(uname -m)
OS_NAME="$(lsb_release -sc)"
OS="deb"
fi
return
}
install_npm_modules() {
npm install -g n
n ${NODE_JS_VERSION}
npm install -g npm@10
hash -r
npm install -g lerna
npm install -g typescript
npm install -g cross-env
}
install_deps() {
if [ $INSTALL = 0 ]
then
echo "Dependencies will not be installed"
return;
fi
if [ ! $( id -u ) -eq 0 ]
then
echo "It is not possible to instal dependencies. Please run as root"
exit 1
fi
CURPLACE=$(pwd)
if [ "x$OS" = "xrpm" ]; then
RHEL=$(rpm --eval %rhel)
yum -y install wget git rpm-build rpmdevtools python3 krb5-devel cmake bzip2
if [ "x${RHEL}" = "x7" ]; then
until yum -y install epel-release centos-release-scl; do
echo "waiting"
sleep 1
done
yum -y install npm cmake3 devtoolset-11
ln -sf /usr/bin/cmake3 /usr/bin/cmake
source /opt/rh/devtoolset-11/enable
fi
if [ "x${RHEL}" = "x8" ]; then
yum -y install npm gcc-toolset-11
source /opt/rh/gcc-toolset-11/enable
fi
if [ "x${RHEL}" = "x9" ]; then
yum -y install npm gcc g++ openssl-devel
fi
yum clean all
else
until apt-get -y update; do
sleep 1
echo "waiting"
done
DEBIAN_FRONTEND=noninteractive apt-get -y install lsb-release gpg wget
export DEBIAN=$(lsb_release -sc)
if [ x"${DEBIAN}" = xbionic ]; then
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ bionic main' | tee /etc/apt/sources.list.d/kitware.list >/dev/null
apt-get -y update
fi
INSTALL_LIST="wget git devscripts debhelper debconf pkg-config npm libkrb5-dev cmake bzip2 gcc g++"
if [ x"${DEBIAN}" = xnoble ]; then
INSTALL_LIST="${INSTALL_LIST} python3-distutils-extra"
fi
until DEBIAN_FRONTEND=noninteractive apt-get -y install ${INSTALL_LIST}; do
sleep 1
echo "waiting"
done
fi
return;
}
get_tar(){
TARBALL=$1
TARFILE=$(basename $(find $WORKDIR/$TARBALL -name 'percona-mongodb-mongosh*.tar.gz' | sort | tail -n1))
if [ -z $TARFILE ]
then
TARFILE=$(basename $(find $CURDIR/$TARBALL -name 'percona-mongodb-mongosh*.tar.gz' | sort | tail -n1))
if [ -z $TARFILE ]
then
echo "There is no $TARBALL for build"
exit 1
else
cp $CURDIR/$TARBALL/$TARFILE $WORKDIR/$TARFILE
fi
else
cp $WORKDIR/$TARBALL/$TARFILE $WORKDIR/$TARFILE
fi
return
}
build_mongosh(){
if [ $MONGOSH = 0 ]
then
echo "mongosh will not be built"
return;
fi
echo $PATH
if [ "x$OS" = "xrpm" ]; then
RHEL=$(rpm --eval %rhel)
if [ "x${RHEL}" = "x7" ]; then
source /opt/rh/devtoolset-11/enable
fi
if [ "x${RHEL}" = "x8" ]; then
source /opt/rh/gcc-toolset-11/enable
fi
fi
get_tar "source_tarball"
cd $WORKDIR
rm -rf ${PRODUCT}-${VERSION}
TARFILE=$(basename $(find . -name 'percona-mongodb-mongosh*.tar.gz' | sort | tail -n1))
tar xzf ${TARFILE}
cd ${PRODUCT}-${VERSION}
source VERSION
install_npm_modules
pwd
ls -la
npm run bootstrap
if [ "x${RHEL}" = "x9" ]; then
export BOXEDNODE_CONFIGURE_ARGS="--shared-openssl"
fi
NODE_JS_VERSION=${NODE_JS_VERSION} SEGMENT_API_KEY="dummy" BOXEDNODE_CONFIGURE_ARGS=${BOXEDNODE_CONFIGURE_ARGS} BOXEDNODE_MAKE_ARGS="-j${NCPU}" REVISION=${REVISION} BUILD_FLE_FROM_SOURCE=true npm run compile-exec;
NODE_JS_VERSION=${NODE_JS_VERSION} SEGMENT_API_KEY="dummy" BOXEDNODE_CONFIGURE_ARGS=${BOXEDNODE_CONFIGURE_ARGS} BOXEDNODE_MAKE_ARGS="-j${NCPU}" REVISION=${REVISION} BUILD_FLE_FROM_SOURCE=true npm run evergreen-release package -- --build-variant=${VARIANT}
echo ${VARIANT}
if [[ ${VARIANT} =~ 'rpm' ]]; then
PKGDIR="rpm"
EXT="rpm"
elif [[ ${VARIANT} =~ 'deb' ]]; then
PKGDIR="deb"
EXT="deb"
elif [[ ${VARIANT} =~ 'linux' ]]; then
PKGDIR="tarball"
EXT="tar.gz"
fi
mkdir -p ${WORKDIR}/${PKGDIR}
mkdir -p ${CURDIR}/${PKGDIR}
cp dist/*.${EXT} ${WORKDIR}/${PKGDIR}
cp dist/*.${EXT} ${CURDIR}/${PKGDIR}
}
#main
CURDIR=$(pwd)
VERSION_FILE=$CURDIR/percona-mongodb-mongosh.properties
args=
WORKDIR=
SRPM=0
SDEB=0
RPM=0
DEB=0
SOURCE=0
TARBALL=0
MONGOSH=0
OS_NAME=
ARCH=
OS=
INSTALL=0
RPM_RELEASE=1
DEB_RELEASE=1
VERSION="1.6.0"
RELEASE="1"
REVISION=0
BRANCH="nocoord"
REPO="https://github.com/mongodb-js/mongosh.git"
PRODUCT=percona-mongodb-mongosh
parse_arguments PICK-ARGS-FROM-ARGV "$@"
PSM_BRANCH=${BRANCH}
if test -e "/proc/cpuinfo"
then
NCPU="$(grep -c ^processor /proc/cpuinfo)"
else
NCPU=4
fi
check_workdir
get_system
install_deps
get_sources
build_mongosh