Projet

Général

Profil

0002-Jenkinsfile-use-temporary-directory-and-database-311.patch

Benjamin Dauvergne, 13 mai 2019 20:09

Télécharger (2,59 ko)

Voir les différences:

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(-)
Jenkinsfile
2 2

  
3 3
pipeline {
4 4
    agent any
5
    options { disableConcurrentBuilds() }
6
    environment {
7
       TMPDIR = "/tmp/$BUILD_TAG"
8
    }
5 9
    stages {
6 10
        stage('Unit Tests') {
7 11
            steps {
8
                sh 'tox -rv'
12
                sh """
13
virtualenv --no-site-packages .env
14
mkdir -p ${env.TMPDIR}
15
env
16
.env/bin/pip install tox
17

  
18
pg_virtualenv -o fsync=off .env/bin/tox -rv
19
"""
9 20
            }
10 21
            post {
11 22
                always {
......
35 46
                utils = new Utils()
36 47
                utils.mail_notify(currentBuild, env, 'admin+jenkins-passerelle@entrouvert.com')
37 48
            }
49
            sh "rm -rf ${env.TMPDIR}"
38 50
        }
39 51
        success {
40 52
            cleanWs()
tests/settings.py
61 61
DATABASES = {
62 62
    'default': {
63 63
        'ENGINE': os.environ.get('DB_ENGINE', 'django.db.backends.sqlite3'),
64
        'TEST': {
65
            'NAME': 'passerelle-test-%s' % os.environ.get("BRANCH_NAME", "").replace('/', '-')[:63],
66
        },
64
        'NAME': 'passerelle',
67 65
    }
68 66
}
67

  
68
if 'postgres' in DATABASES['default']['ENGINE']:
69
    for key in ('PGPORT', 'PGHOST', 'PGUSER', 'PGPASSWORD'):
70
        if key in os.environ:
71
            DATABASES['default'][key[2:]] = os.environ[key]
tox.ini
1 1
[tox]
2
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/passerelle/{env:BRANCH_NAME:}
2
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/passerelle/
3 3
envlist = py27-django{18,111}-{sqlite,pg}
4 4

  
5 5
[testenv]
......
12 12
  fast: FAST=--nomigrations
13 13
  sqlite: DB_ENGINE=django.db.backends.sqlite3
14 14
  pg: DB_ENGINE=django.db.backends.postgresql_psycopg2
15
  PGPORT={env:PGPORT:}
16
  PGHOST={env:PGHOST:}
17
  PGUSER={env:PGUSER:}
18
  PGPASSWORD={env:PGPASSWORD:}
15 19
deps =
16 20
  django18: django>=1.8,<1.9
17 21
  django111: django>=1.11,<1.12
18
-