Add scripts for running refstack-client in docker

Prerequisites:

Linux host with Docker installed.

Usage:

./docker/env_build - script removes previous container if eny and builds
an updated `refstack-client` image
./docker/env_up - script setups environment in container if is the first run
and joins to shell in this container

Basic usage example:

1) Checkout repository
2) Run ./docker/env_build.sh
3) Run ./docker/env_up.sh
...
You will get Bash console in the prepared dockerized environment.

4) Run ./docker/env_up.sh  to get back to shell in the env
5) Run ./docker/env_build.sh to rebuild image and spin a new env
container.

NOTE: These scripts are safe to run locally.

Change-Id: I51e34a5d130d9595ead948f7ddb0db840527a797
This commit is contained in:
sslypushenko 2017-02-08 12:10:35 +02:00 committed by sslypushenko
parent 2d97cdff88
commit 648b325a59
5 changed files with 118 additions and 21 deletions

17
.dockerignore Normal file
View File

@ -0,0 +1,17 @@
*.egg*
*.py[cod]
.coverage
.cache
.tox/
.venv/
AUTHORS
ChangeLog
build/
cover/
dist
.git/
venv/
.venv/
.tempest/
htmlcov/
test-reports/

17
docker/Dockerfile Normal file
View File

@ -0,0 +1,17 @@
FROM ubuntu:16.04
RUN apt-get update && \
apt-get install -y sudo curl vim less tar
ARG UID
ARG GID
ENV DEV_USER=ubuntu COLUMNS=120
RUN [ ! $(grep ":${GID}:" /etc/group) ] && groupadd -g ${GID:-1000} ${DEV_USER}
RUN useradd -g ${DEV_USER} -u ${UID:-1000} -s /bin/bash -d /home/${DEV_USER} -m ${DEV_USER} && \
( umask 226 && echo "${DEV_USER} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/50_${DEV_USER} )
USER ${DEV_USER}
WORKDIR /home/${DEV_USER}

21
docker/env_build.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash -x
if [ "$EUID" -eq 0 ]
then echo "This script should not be runned with sudo!"
exit
fi
docker ps &> /dev/null; (( $? != 0 )) && echo 'Docker should be accessible without sudo '
CONTAINER_NAME=refstack_client
if [ $( docker ps -a -q --filter name=${CONTAINER_NAME} ) ]; then
docker rm -f $( docker ps -a -q --filter name=${CONTAINER_NAME} )
fi
docker build -t ${CONTAINER_NAME} \
--build-arg UID=$( id -u $USER ) \
--build-arg GID=$( id -g $USER ) \
--file $( git rev-parse --show-toplevel )/docker/Dockerfile \
$( git rev-parse --show-toplevel )

35
docker/env_up.sh Executable file
View File

@ -0,0 +1,35 @@
#!/bin/bash -x
if [ "$EUID" -eq 0 ]
then echo "This script should not be runned with sudo!"
exit
fi
docker ps &> /dev/null; (( $? != 0 )) && echo 'Docker should be accessible without sudo '
CONTAINER_NAME=refstack_client
if [ ! $( docker ps -q --filter name=${CONTAINER_NAME} ) ]; then
ENV_CONTAINER=$( docker ps -a -q --filter name=${CONTAINER_NAME} )
if [ ${ENV_CONTAINER} ]; then
docker start -a -i $ENV_CONTAINER
exit 0
fi
docker run \
--dns=8.8.8.8 \
-i -t \
--name ${CONTAINER_NAME}\
-v $( git rev-parse --show-toplevel ):/home/ubuntu/refstack-client \
-e REFSTACK_CLIENT_TEMPEST_DIR=/home/ubuntu/tempest \
${CONTAINER_NAME} bash -c '~/refstack-client/setup_env -q && bash'
fi
ENV_CONTAINER=$( docker ps -q --filter name=${CONTAINER_NAME} )
[[ ! ${ENV_CONTAINER} ]] && exit 1
[[ $* ]] && {
docker exec ${ENV_CONTAINER} $*
} || {
docker exec -i -t ${ENV_CONTAINER} bash
}

View File

@ -12,8 +12,9 @@ function usage {
echo ""
echo " -h Print this usage message"
echo " -c Tempest test runner commit. You can specify SHA or branch here"
echo " -t Tempest test runner tag. You can specify tag here"
echo " If no commit or tag is specified, tempest will be install from commit"
echo " -q Run quietly. If .tempest folder exists, refstack-client is considered as installed"
echo " -t Tempest test runner tag. You can specify tag here"
echo " ${CHECKOUT_POINT}"
exit 1
}
@ -29,7 +30,7 @@ function check_tag {
# By default tempest uses commit ${CHECKOUT_POINT}
while getopts c:t:h FLAG; do
while getopts c:t:qh FLAG; do
case ${FLAG} in
c)
CHECKOUT_POINT=${OPTARG}
@ -37,6 +38,9 @@ while getopts c:t:h FLAG; do
t)
CHECKOUT_POINT="-q ${OPTARG}"
;;
q) #show help
QUIET_MODE=true
;;
h) #show help
usage
;;
@ -46,9 +50,25 @@ while getopts c:t:h FLAG; do
;;
esac
done
shift $((OPTIND-1)) # This tells getopts to move on to the next argument.
# Install git
WORKDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TEMPEST_DIR=${REFSTACK_CLIENT_TEMPEST_DIR:-${WORKDIR}/.tempest}
# Checkout tempest on specified tag
if [ -d "${TEMPEST_DIR}" ]; then
[ ${QUIET_MODE} ] && echo 'Looks like RefStack client is already installed' && exit 0
while true; do
read -p "Existing tempest installation found. We should remove it. All data from previous test runs will be deleted. Continue (y/n) ?" yn
case ${yn} in
[Yy]* ) rm -rf ${TEMPEST_DIR}; break;;
[Nn]* ) exit 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
if [ -n "$(command -v apt-get)" ]; then
# For apt-get-based Linux distributions (Ubuntu, Debian)
# If we run script in container we need sudo
@ -81,21 +101,8 @@ else
exit 1
fi
WORKDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Checkout tempest on specified tag
if [ -d "${WORKDIR}/.tempest" ]; then
while true; do
read -p "Existing tempest installation found. We should remove it. All data from previous test runs will be deleted. Continue (y/n) ?" yn
case ${yn} in
[Yy]* ) rm -rf ${WORKDIR}/.tempest; break;;
[Nn]* ) exit 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
git clone https://github.com/openstack/tempest.git ${WORKDIR}/.tempest
cd ${WORKDIR}/.tempest
git clone https://github.com/openstack/tempest.git ${TEMPEST_DIR}
cd ${TEMPEST_DIR}
git checkout $CHECKOUT_POINT || if [ $? -ne 0 ]; then exit 1; fi
cd ${WORKDIR}
@ -146,15 +153,15 @@ if [ -d ${WORKDIR}/.venv ]; then
rm -rf ${WORKDIR}/.venv
fi
python virtualenv.py ${WORKDIR}/.venv --python="${PYPATH}"
python virtualenv.py ${WORKDIR}/.tempest/.venv --python="${PYPATH}"
python virtualenv.py ${TEMPEST_DIR}/.venv --python="${PYPATH}"
cd ..
rm -rf virtualenv-${VENV_VERSION}
rm virtualenv-${VENV_VERSION}.tar.gz
${WORKDIR}/.venv/bin/python -m pip install -r ${WORKDIR}/requirements.txt
${WORKDIR}/.tempest/.venv/bin/python -m pip install -r ${WORKDIR}/.tempest/requirements.txt
${TEMPEST_DIR}/.venv/bin/python -m pip install -r ${TEMPEST_DIR}/requirements.txt
# Add additional packages to find more tests by tempest
# Note: Since there are no requirements in tempest-additional-requirements.txt by default,
# this line is commented out to prevent errors from being returned. Uncomment this line if
# there are requirements in tempest-additonal-requirements.txt.
#${WORKDIR}/.tempest/.venv/bin/pip install -r ${WORKDIR}/tempest-additional-requirements.txt
# ${TEMPEST_DIR}/.venv/bin/pip install -r ${WORKDIR}/tempest-additional-requirements.txt