From a7cb2a26d417e74787ee8f76015ae9b09815ce59 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Mon, 7 Dec 2015 16:49:35 +0100 Subject: [PATCH] MT#6259 support unittest at docker environment Change-Id: I6c4288b9f25675c2c6d7ea5654f735f06d6c2c61 --- Makefile | 26 +++++--------------------- t/Dockerfile | 46 ++++++++++++++++++++++++++++++++++++++++++++++ t/common.txt | 10 ++++++++++ t/test.txt | 7 +++++++ t/testrunner | 19 +++++++++++++++++++ 5 files changed, 87 insertions(+), 21 deletions(-) create mode 100644 t/Dockerfile create mode 100644 t/common.txt create mode 100644 t/test.txt create mode 100755 t/testrunner diff --git a/Makefile b/Makefile index ee07bd5..2535355 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,9 @@ VAR_DIR ?= /var/lib/repoapi - +RESULTS ?= ./reports # do nothing by default all: # virtual environments ############# -.ONESHELL: -SHELL = /bin/bash -venv_test: requirements/test.txt - virtualenv --python=python2.7 venv_test - source ./venv_test/bin/activate && \ - pip install -r ./requirements/test.txt | tee install.log - -.ONESHELL: -SHELL = /bin/bash -venv_dev: requirements/dev.txt - virtualenv --python=python2.7 venv_dev - source ./venv_dev/bin/activate && \ - pip install -r ./requirements/dev.txt | tee install.log - .ONESHELL: SHELL = /bin/bash venv_prod: requirements/prod.txt @@ -26,9 +12,8 @@ venv_prod: requirements/prod.txt pip install -r ./requirements/prod.txt | tee install.log ################################### -test: venv_test - source ./venv_test/bin/activate && \ - ./manage.py jenkins --settings="repoapi.settings.dev" +test: + ./manage.py jenkins --output-dir $(RESULTS) --settings="repoapi.settings.dev" deploy: venv_prod source $(VAR_DIR)/venv_prod/bin/activate && \ @@ -42,9 +27,8 @@ migrate: venv_prod ################################### -run_dev: venv_dev - source ./venv_dev/bin/activate && \ - ./manage.py runserver_plus --settings="repoapi.settings.dev" +run_dev: + ./manage.py runserver_plus --settings="repoapi.settings.dev" ################################### diff --git a/t/Dockerfile b/t/Dockerfile new file mode 100644 index 0000000..56ee817 --- /dev/null +++ b/t/Dockerfile @@ -0,0 +1,46 @@ +# TODO - switch to sipwise internal one +FROM debian:jessie + +# Important! Update this no-op ENV variable when this Dockerfile +# is updated with the current date. It will force refresh of all +# of the base images and things like `apt-get update` won't be using +# old cached versions when the Dockerfile is built. +ENV REFRESHED_AT 2015-12-07 + +# mirrors behind httpredir randomly throw `Error reading from server. Remote end closed connection` +# and we want to be independent from any external services anyway +# TODO - the release-trunk-jessie is too dynamic yet, though required for some build/test dependencies +RUN apt-get update && apt-get -y install apt-transport-https wget +RUN echo "# generated by Dockerfile from repoapi-jessie at $(date)\n\ +deb https://debian.sipwise.com/debian jessie main non-free\n\ +deb https://debian.sipwise.com/debian jessie-updates main non-free\n\ +deb https://debian-security.sipwise.com/debian-security jessie-security main contrib non-free\n\ +deb https://deb.sipwise.com/autobuild/ release-trunk-jessie main\n" > /etc/apt/sources.list +RUN wget -O /etc/apt/trusted.gpg.d/sipwise.gpg https://deb.sipwise.com/spce/sipwise.gpg + +RUN apt-get update +RUN apt-get install --assume-yes python2.7 python2.7-dev python-distribute python-pip git + +# Get pip to download and install requirements: +COPY test.txt common.txt /tmp/ +RUN pip install -r /tmp/test.txt + +RUN echo './t/testrunner' >>/root/.bash_history + +WORKDIR /code/ + +################################################################################ +# Instructions for usage +# ---------------------- +# When you want to build the base image from scratch (jump to the next section if you don't want to build yourself!): +# % docker build --tag="repoapi-jessie" . +# % docker run --rm -i -t -v $(pwd)/..:/code:rw repoapi-jessie:latest bash +# +# Use the existing docker image: +# % docker pull docker1.mgm.sipwise.com/repoapi-jessie +# % docker run --rm -i -t -v $(pwd)/..:/code:rw docker1.mgm.sipwise.com/repoapi-jessie:latest bash +# +# Inside docker (the command is in history, just press UP button): +# ./t/testrunner +# +################################################################################ diff --git a/t/common.txt b/t/common.txt new file mode 100644 index 0000000..48f7d58 --- /dev/null +++ b/t/common.txt @@ -0,0 +1,10 @@ +Django==1.8 +django-extensions +yuicompressor +django-assets +djangorestframework +django-rest-swagger +markdown +django-filter +six +webassets diff --git a/t/test.txt b/t/test.txt new file mode 100644 index 0000000..ebde66d --- /dev/null +++ b/t/test.txt @@ -0,0 +1,7 @@ +-r common.txt +django-nose +git+https://github.com/linuxmaniac/django-jenkins.git@vseva/nose#egg=django-jenkins +flake8==2.4.1 +pylint +coverage==3.7.1 +mock diff --git a/t/testrunner b/t/testrunner new file mode 100755 index 0000000..1db2886 --- /dev/null +++ b/t/testrunner @@ -0,0 +1,19 @@ +#!/bin/bash +# This script is used for running the tests with proper arguments +# from within Jenkins + +set -e +set -u + +if [ -d /results ] ; then + # Running from Jenkins (RW) + RESULTS="/results" + + cd "/code" +else + # Running locally in Docker + RESULTS="./results" + mkdir -p "${RESULTS}" +fi + +RESULTS=${RESULTS} make test