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:
parent
2d97cdff88
commit
648b325a59
17
.dockerignore
Normal file
17
.dockerignore
Normal 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
17
docker/Dockerfile
Normal 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
21
docker/env_build.sh
Executable 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
35
docker/env_up.sh
Executable 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
|
||||||
|
}
|
49
setup_env
49
setup_env
@ -12,8 +12,9 @@ function usage {
|
|||||||
echo ""
|
echo ""
|
||||||
echo " -h Print this usage message"
|
echo " -h Print this usage message"
|
||||||
echo " -c Tempest test runner commit. You can specify SHA or branch here"
|
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 " 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}"
|
echo " ${CHECKOUT_POINT}"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@ -29,7 +30,7 @@ function check_tag {
|
|||||||
|
|
||||||
# By default tempest uses commit ${CHECKOUT_POINT}
|
# By default tempest uses commit ${CHECKOUT_POINT}
|
||||||
|
|
||||||
while getopts c:t:h FLAG; do
|
while getopts c:t:qh FLAG; do
|
||||||
case ${FLAG} in
|
case ${FLAG} in
|
||||||
c)
|
c)
|
||||||
CHECKOUT_POINT=${OPTARG}
|
CHECKOUT_POINT=${OPTARG}
|
||||||
@ -37,6 +38,9 @@ while getopts c:t:h FLAG; do
|
|||||||
t)
|
t)
|
||||||
CHECKOUT_POINT="-q ${OPTARG}"
|
CHECKOUT_POINT="-q ${OPTARG}"
|
||||||
;;
|
;;
|
||||||
|
q) #show help
|
||||||
|
QUIET_MODE=true
|
||||||
|
;;
|
||||||
h) #show help
|
h) #show help
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
@ -46,9 +50,25 @@ while getopts c:t:h FLAG; do
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
shift $((OPTIND-1)) # This tells getopts to move on to the next argument.
|
|
||||||
|
|
||||||
# Install git
|
# 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
|
if [ -n "$(command -v apt-get)" ]; then
|
||||||
# For apt-get-based Linux distributions (Ubuntu, Debian)
|
# For apt-get-based Linux distributions (Ubuntu, Debian)
|
||||||
# If we run script in container we need sudo
|
# If we run script in container we need sudo
|
||||||
@ -81,21 +101,8 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
WORKDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
git clone https://github.com/openstack/tempest.git ${TEMPEST_DIR}
|
||||||
|
cd ${TEMPEST_DIR}
|
||||||
# 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 checkout $CHECKOUT_POINT || if [ $? -ne 0 ]; then exit 1; fi
|
git checkout $CHECKOUT_POINT || if [ $? -ne 0 ]; then exit 1; fi
|
||||||
cd ${WORKDIR}
|
cd ${WORKDIR}
|
||||||
@ -146,15 +153,15 @@ if [ -d ${WORKDIR}/.venv ]; then
|
|||||||
rm -rf ${WORKDIR}/.venv
|
rm -rf ${WORKDIR}/.venv
|
||||||
fi
|
fi
|
||||||
python virtualenv.py ${WORKDIR}/.venv --python="${PYPATH}"
|
python virtualenv.py ${WORKDIR}/.venv --python="${PYPATH}"
|
||||||
python virtualenv.py ${WORKDIR}/.tempest/.venv --python="${PYPATH}"
|
python virtualenv.py ${TEMPEST_DIR}/.venv --python="${PYPATH}"
|
||||||
cd ..
|
cd ..
|
||||||
rm -rf virtualenv-${VENV_VERSION}
|
rm -rf virtualenv-${VENV_VERSION}
|
||||||
rm virtualenv-${VENV_VERSION}.tar.gz
|
rm virtualenv-${VENV_VERSION}.tar.gz
|
||||||
${WORKDIR}/.venv/bin/python -m pip install -r ${WORKDIR}/requirements.txt
|
${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
|
# Add additional packages to find more tests by tempest
|
||||||
# Note: Since there are no requirements in tempest-additional-requirements.txt by default,
|
# 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
|
# this line is commented out to prevent errors from being returned. Uncomment this line if
|
||||||
# there are requirements in tempest-additonal-requirements.txt.
|
# 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
|
||||||
|
Loading…
Reference in New Issue
Block a user