test.sh 1.72 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#!/bin/bash

if [ -z ${WCMD_TEST_RUNNING+x} ]; then

# outside docker

D=$( realpath $( dirname ${0} ) )
. "${D}/libs/shflags"
DEFINE_string py '3.5' "Python version to test against" p
DEFINE_boolean preserve_wdir "${FLAGS_FALSE}" "Don't use a temporary working directory during tests, but mount the host directory given as --wdir instead." s
DEFINE_string wdir "${D}/webis-cmd-test-tmp/" "Working directory to use, if preserve_wdiris set." t

FLAGS_HELP="Usage: ${0} [flags] -- <command>
Test webis-cmd against a python docker container with specified version.
 <command> : the webis-cmd command to run. "


FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"

WDIR=/tmp/wcmd-tmp
22
WVOL=""
23 24 25 26

[ "${FLAGS_preserve_wdir}" = "${FLAGS_TRUE}" ] && {
    mkdir -vp ${FLAGS_wdir}
    WDIR=${FLAGS_wdir}
27
    WVOL="-v ${WDIR}:${WDIR}"
28 29 30
}

docker run --rm -it \
Michael Völske's avatar
Michael Völske committed
31
       -e "WCMD_TEST_RUNNING=1" \
32 33 34
       --net host \
       -v "${D}:/webis-cmd" \
       -v "${HOME}:/wcmd-home" \
35
       $WVOL \
Michael Völske's avatar
Michael Völske committed
36
       -e "PYTHONPATH=/webis-cmd" \
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
       -e "HOME=/wcmd-home" \
       -e "WCMD_WDIR=${WDIR}" \
       -e "WCMD_UID=$(id -u)" \
       -e "WCMD_USER=$(whoami)" \
       python:${FLAGS_py} /webis-cmd/$(basename ${0}) $@


else

# inside docker
useradd -d ${HOME} -M --password '...' --uid ${WCMD_UID} ${WCMD_USER}
mkdir -p ${WCMD_WDIR}

ln -s /webis-cmd/webis.py /bin/webis
chmod +x /bin/webis

chown ${WCMD_USER} ${WCMD_WDIR}
cd ${WCMD_WDIR}

Michael Völske's avatar
Michael Völske committed
56 57
echo "echo '[TEST]' \$(/usr/bin/env python --version)" >> /tmp/run
echo "echo '[TEST] Executing <${@}>...'" >> /tmp/run
58
echo "$@" >> /tmp/run
Michael Völske's avatar
Michael Völske committed
59
echo "echo '[TEST] Finished executing <${@}>. Working dir contents now:'" >> /tmp/run
60 61 62 63 64 65
echo "ls -ahl " >> /tmp/run
chmod +x /tmp/run

su --preserve-environment ${WCMD_USER} -c '. /tmp/run'

fi