2017-08-08 19:13:59 +00:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
#
|
2017-09-11 19:53:03 +00:00
|
|
|
|
# Script to build khaganat server
|
2017-08-08 19:13:59 +00:00
|
|
|
|
#
|
2017-09-11 19:53:03 +00:00
|
|
|
|
# Copyright (C) 2017 AleaJactaEst
|
|
|
|
|
#
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU 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 General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-08-08 19:13:59 +00:00
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
declare -i REMOVE=0
|
2017-09-03 13:20:49 +00:00
|
|
|
|
declare -i IMAGE=0
|
2017-08-08 19:13:59 +00:00
|
|
|
|
declare -i BUILD=1
|
|
|
|
|
declare -i DEBUG=0
|
|
|
|
|
declare JOBS=""
|
|
|
|
|
declare CMAKEOPTS=""
|
2017-08-27 14:38:04 +00:00
|
|
|
|
declare DOCKEROPTS=""
|
2017-08-08 19:13:59 +00:00
|
|
|
|
declare DIRBUILD=""
|
|
|
|
|
declare CLEANDOCKER=0
|
2017-09-11 19:53:03 +00:00
|
|
|
|
declare -i CLEANIMAGENONE=0
|
2017-09-03 13:20:49 +00:00
|
|
|
|
declare -i AUTODETEC=1
|
2017-09-15 20:44:13 +00:00
|
|
|
|
declare DOCKERBUILDOPT=""
|
2017-08-08 19:13:59 +00:00
|
|
|
|
|
2017-08-29 21:08:14 +00:00
|
|
|
|
declare IMAGEDOCKER="builder_khanat_debian_jessie_x86_64"
|
|
|
|
|
declare LOCALBUILDDIR="build/$IMAGEDOCKER"
|
2017-08-08 19:13:59 +00:00
|
|
|
|
declare LOCALSRC="debian/jessie/x86_64"
|
2017-10-11 19:11:32 +00:00
|
|
|
|
declare DIRPACKAGE="output/khanat_debian_jessie_x86_64/package"
|
|
|
|
|
declare PACKAGEBIN="$DIRPACKAGE/ryzomcore_jessie_x86_64.tar.gz"
|
|
|
|
|
declare PACKAGEREF="$DIRPACKAGE/khanat-ref-ressources.tar.gz"
|
2017-08-08 19:13:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
usage()
|
|
|
|
|
{
|
|
|
|
|
cat << EOF
|
|
|
|
|
usage:$0 [options]
|
|
|
|
|
script to build under docker
|
|
|
|
|
|
|
|
|
|
Step:
|
|
|
|
|
1) clean old build directory
|
|
|
|
|
2) create image builder
|
|
|
|
|
3) launch build under docker (launch script build-under-docker.sh)
|
2017-10-09 20:10:36 +00:00
|
|
|
|
4) remove docker container with state exited and clean docker images NONE
|
2017-08-08 19:13:59 +00:00
|
|
|
|
|
|
|
|
|
options:
|
|
|
|
|
-h, --help : Show this help
|
|
|
|
|
-d, --debug : Show debug message
|
|
|
|
|
-r, --remove : Remove old build repository
|
2017-09-03 13:20:49 +00:00
|
|
|
|
-f, --force-create-image : force to create docker image (use to build khanat) - default autodetec.
|
2017-08-08 19:13:59 +00:00
|
|
|
|
-j [N], --jobs[=N] Allow N jobs at once; infinite jobs with no arg.
|
|
|
|
|
-a OPTS, --add-opts-cmake=OPTS : Adding options on cmake command (before build)
|
|
|
|
|
-c, --clean-container : remove all container in state Exited
|
2017-09-11 19:53:03 +00:00
|
|
|
|
-w, --clean-images-none : Remove images docker (with name 'none')
|
2017-08-27 14:38:04 +00:00
|
|
|
|
-m OPTS, --add-opts-docker=OPTS : Adding options on docker command (when build)
|
|
|
|
|
--only-build-server : adding option to build only server
|
2017-08-08 19:13:59 +00:00
|
|
|
|
|
|
|
|
|
Example :
|
|
|
|
|
cd [root Khanat directory]
|
2017-08-27 14:38:04 +00:00
|
|
|
|
./build.sh -c -r -m '-m 20g'
|
|
|
|
|
./build.sh -c -r -j 4 -a '-DWITH_SYMBOLS=ON' -a '-DWITH_RYZOM_TOOLS=OFF' -a '-DWITH_NEL_TOOLS=OFF' -m '-m 20g' -d
|
|
|
|
|
|
2017-08-08 19:13:59 +00:00
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function msg_debug()
|
|
|
|
|
{
|
|
|
|
|
if [[ $DEBUG -ne 0 ]]
|
|
|
|
|
then
|
|
|
|
|
echo "$(date "+%Y/%m/%d %H:%M:%S") DEBUG - $*"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function msg_info()
|
|
|
|
|
{
|
|
|
|
|
echo "$(date "+%Y/%m/%d %H:%M:%S") INFO - $*"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function msg_error()
|
|
|
|
|
{
|
|
|
|
|
echo "$(date "+%Y/%m/%d %H:%M:%S") ERROR - $*" >&2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# MAIN
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
calldir="$(dirname $0)"
|
|
|
|
|
basedir=$(cd $calldir; pwd)
|
|
|
|
|
rootdir="$(dirname $(dirname $(dirname $(dirname $(dirname $(dirname ${basedir}))))))"
|
|
|
|
|
|
|
|
|
|
while test $# -gt 0
|
|
|
|
|
do
|
|
|
|
|
case "$1" in
|
|
|
|
|
-h|--help)
|
|
|
|
|
usage
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
-d|--debug)
|
|
|
|
|
DEBUG=1
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
-c|--clean-container)
|
|
|
|
|
CLEANDOCKER=1
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
-r|--remove)
|
|
|
|
|
REMOVE=1
|
|
|
|
|
shift
|
|
|
|
|
;;
|
2017-09-03 13:20:49 +00:00
|
|
|
|
-f|--force-create-image)
|
2017-08-08 19:13:59 +00:00
|
|
|
|
IMAGE=1
|
2017-09-15 20:44:13 +00:00
|
|
|
|
DOCKERBUILDOPT="$DOCKERBUILDOPT --no-cache"
|
2017-08-08 19:13:59 +00:00
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
-j)
|
|
|
|
|
shift
|
|
|
|
|
# search next argument is value or new argument
|
|
|
|
|
if [[ ${1:0:1} == "-" ]]
|
|
|
|
|
then
|
|
|
|
|
JOBS="-j"
|
|
|
|
|
else
|
|
|
|
|
JOBS="-j $1"
|
|
|
|
|
shift
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
--jobs*)
|
|
|
|
|
if [[ ${1#*=} == "" ]]
|
|
|
|
|
then
|
|
|
|
|
JOBS="-j"
|
|
|
|
|
else
|
|
|
|
|
JOBS="-j ${1#*=}"
|
|
|
|
|
fi
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
-a)
|
|
|
|
|
shift
|
|
|
|
|
CMAKEOPTS="$CMAKEOPTS $1"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
--add-opts-cmake=*)
|
|
|
|
|
CMAKEOPTS="$CMAKEOPTS ${1#*=}"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
2017-08-27 14:38:04 +00:00
|
|
|
|
-m)
|
|
|
|
|
shift
|
|
|
|
|
DOCKEROPTS="$DOCKEROPTS $1"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
--add-opts-docker=*)
|
|
|
|
|
DOCKEROPTS="$DOCKEROPTS ${1#*=}"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
--only-build-server)
|
|
|
|
|
CMAKEOPTS="$CMAKEOPTS -DWITH_NEL_TESTS=OFF -DWITH_RYZOM_CLIENT=OFF -DWITH_DRIVER_OPENGL=OFF -DWITH_DRIVER_OPENAL=OFF -DWITH_NEL_SAMPLES=OFF -DWITH_SOUND=OFF"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
2017-09-11 19:53:03 +00:00
|
|
|
|
-w|--clean-images-none)
|
|
|
|
|
CLEANIMAGENONE=1
|
|
|
|
|
shift
|
|
|
|
|
;;
|
2017-08-08 19:13:59 +00:00
|
|
|
|
*)
|
|
|
|
|
msg_error "options '$1' not recoginze"
|
|
|
|
|
usage
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
function chrashed()
|
|
|
|
|
{
|
|
|
|
|
msg_error "BUILD FAILED (code:$?)"
|
|
|
|
|
exit 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trap chrashed EXIT
|
|
|
|
|
|
|
|
|
|
msg_debug "prg: $0"
|
|
|
|
|
|
|
|
|
|
docker -v 1>/dev/null
|
|
|
|
|
if [[ $? -ne 0 ]]
|
|
|
|
|
then
|
|
|
|
|
echo "*** ERROR docker not installed"
|
|
|
|
|
exit 2
|
|
|
|
|
fi
|
|
|
|
|
|
2017-09-03 13:20:49 +00:00
|
|
|
|
if [[ $AUTODETEC -ne 0 ]]
|
|
|
|
|
then
|
|
|
|
|
if [[ $(docker images -f "reference=$IMAGEDOCKER" | wc -l) -lt 2 ]]
|
|
|
|
|
then
|
|
|
|
|
IMAGE=1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2017-10-09 20:10:36 +00:00
|
|
|
|
DIRBUILD="${rootdir}/${LOCALBUILDDIR}"
|
2017-08-08 19:13:59 +00:00
|
|
|
|
|
|
|
|
|
msg_debug "calldir: $calldir"
|
|
|
|
|
msg_debug "basedir: $basedir"
|
|
|
|
|
msg_debug "rootdir: $rootdir"
|
|
|
|
|
msg_debug "JOBS: '$JOBS'"
|
|
|
|
|
msg_debug "CMAKEOPTS: '$CMAKEOPTS'"
|
2017-08-27 14:38:04 +00:00
|
|
|
|
msg_debug "DOCKEROPTS: '$DOCKEROPTS'"
|
2017-08-08 19:13:59 +00:00
|
|
|
|
|
|
|
|
|
mkdir -p "${DIRBUILD}"
|
|
|
|
|
if [[ $REMOVE -ne 0 ]]
|
|
|
|
|
then
|
|
|
|
|
msg_info "REMOVE OLD BUILD"
|
|
|
|
|
rm -rf ${DIRBUILD}/* || exit 2
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
touch ${DIRBUILD}/build.log
|
|
|
|
|
|
|
|
|
|
cat << EOF > ${DIRBUILD}/envi.sh
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
export MAKEOPTS="$JOBS"
|
|
|
|
|
export CMAKEOPTS="$CMAKEOPTS"
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
if [[ $IMAGE -ne 0 ]]
|
|
|
|
|
then
|
|
|
|
|
msg_info "GENERATE DOCKER IMAGE"
|
2017-09-15 20:44:13 +00:00
|
|
|
|
cd $rootdir; docker build . ${DOCKERBUILDOPT} -t ${IMAGEDOCKER} \
|
2017-08-08 19:13:59 +00:00
|
|
|
|
--file "${basedir}/Dockerfile" || exit 2
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ $BUILD -ne 0 ]]
|
|
|
|
|
then
|
|
|
|
|
msg_info "BUILD"
|
|
|
|
|
cd $rootdir; docker run -it \
|
|
|
|
|
--hostname=builder \
|
|
|
|
|
-u "$(id -u $USERNAME):$(id -g $USERNAME)" \
|
2017-10-09 20:10:36 +00:00
|
|
|
|
-v $rootdir/dist:/opt/dist:ro \
|
|
|
|
|
-v $rootdir/code:/opt/code:ro \
|
|
|
|
|
-v $rootdir/build:/opt/build \
|
|
|
|
|
-v /etc/localtime:/etc/localtime:ro \
|
2017-08-27 14:38:04 +00:00
|
|
|
|
${DOCKEROPTS} \
|
2017-08-08 19:13:59 +00:00
|
|
|
|
${IMAGEDOCKER} \
|
2017-10-09 20:10:36 +00:00
|
|
|
|
/opt/dist/docker/builder/${LOCALSRC}/build-under-docker.sh "/opt/${LOCALBUILDDIR}" || exit 2
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ $BUILD -ne 0 ]]
|
|
|
|
|
then
|
|
|
|
|
msg_info "COPY PACKAGES"
|
2017-10-11 19:11:32 +00:00
|
|
|
|
mkdir -p "$rootdir/$DIRPACKAGE"
|
2017-10-09 20:10:36 +00:00
|
|
|
|
cd ${rootdir}; tar czf ${PACKAGEREF} \
|
|
|
|
|
code/ryzom/server/shard.screen.rc \
|
|
|
|
|
code/ryzom/common/* \
|
|
|
|
|
code/ryzom/client/* \
|
|
|
|
|
code/ryzom/server/* \
|
|
|
|
|
code/web/* || exit 2
|
|
|
|
|
cp ${rootdir}/${LOCALBUILDDIR}/ryzomcore-0.12.0..tar.gz ${PACKAGEBIN} || exit 2
|
2017-08-08 19:13:59 +00:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ $CLEANDOCKER -ne 0 ]]
|
|
|
|
|
then
|
|
|
|
|
msg_info "CLEAN CONTAINER"
|
|
|
|
|
docker rm --force `docker ps -qf 'status=exited' -f "ancestor=${IMAGEDOCKER}"` || exit 2
|
|
|
|
|
fi
|
|
|
|
|
|
2017-09-11 19:53:03 +00:00
|
|
|
|
if [[ $CLEANIMAGENONE -ne 0 ]]
|
|
|
|
|
then
|
|
|
|
|
msg_info "CLEAN IMAGE DOCKER 'NONE'"
|
|
|
|
|
listimages=( $(docker images | awk '{if ($1=="<none>")print $3}') )
|
|
|
|
|
|
|
|
|
|
msg_debug "IMAGES NONE : ${listimages[@]}"
|
|
|
|
|
if [[ -n "${listimages[@]}" ]]
|
|
|
|
|
then
|
|
|
|
|
docker rmi --force "${listimages[@]}" || exit 2
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2017-08-08 19:13:59 +00:00
|
|
|
|
trap '' EXIT
|
|
|
|
|
msg_info "END"
|