From 0b46be8bf9e30b92eb924bb052a3514511ece71e Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 7 Mar 2019 10:35:23 +0100 Subject: [PATCH 2/2] Jenkinsfile: use temporary directory and database (#31192) pg_virtualenv is used to allocate a temporary postgressql database with fsync=off option. --- Jenkinsfile | 14 +++++++++++++- tests/settings.py | 9 ++++++--- tox.ini | 6 +++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ee172a99..15ac2665 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,10 +2,21 @@ pipeline { agent any + options { disableConcurrentBuilds() } + environment { + TMPDIR = "/tmp/$BUILD_TAG" + } stages { stage('Unit Tests') { steps { - sh 'tox -rv' + sh """ +virtualenv --no-site-packages .env +mkdir -p ${env.TMPDIR} +env +.env/bin/pip install tox + +pg_virtualenv -o fsync=off .env/bin/tox -rv +""" } post { always { @@ -35,6 +46,7 @@ pipeline { utils = new Utils() utils.mail_notify(currentBuild, env, 'admin+jenkins-passerelle@entrouvert.com') } + sh "rm -rf ${env.TMPDIR}" } success { cleanWs() diff --git a/tests/settings.py b/tests/settings.py index 375daabd..9945c425 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -61,8 +61,11 @@ CACHES = { DATABASES = { 'default': { 'ENGINE': os.environ.get('DB_ENGINE', 'django.db.backends.sqlite3'), - 'TEST': { - 'NAME': 'passerelle-test-%s' % os.environ.get("BRANCH_NAME", "").replace('/', '-')[:63], - }, + 'NAME': 'passerelle', } } + +if 'postgres' in DATABASES['default']['ENGINE']: + for key in ('PGPORT', 'PGHOST', 'PGUSER', 'PGPASSWORD'): + if key in os.environ: + DATABASES['default'][key[2:]] = os.environ[key] diff --git a/tox.ini b/tox.ini index 48173675..b0cb4279 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/passerelle/{env:BRANCH_NAME:} +toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/passerelle/ envlist = py27-django{18,111}-{sqlite,pg} [testenv] @@ -12,6 +12,10 @@ setenv = fast: FAST=--nomigrations sqlite: DB_ENGINE=django.db.backends.sqlite3 pg: DB_ENGINE=django.db.backends.postgresql_psycopg2 + PGPORT={env:PGPORT:} + PGHOST={env:PGHOST:} + PGUSER={env:PGUSER:} + PGPASSWORD={env:PGPASSWORD:} deps = django18: django>=1.8,<1.9 django111: django>=1.11,<1.12 -- 2.20.1