Jenkinsfile: use pgvirtualenv

This commit is contained in:
Benjamin Dauvergne 2021-11-24 12:09:57 +01:00
parent a8cdbf3dfc
commit ea13b6f87f
2 changed files with 13 additions and 2 deletions

9
Jenkinsfile vendored
View File

@ -6,10 +6,16 @@ pipeline {
disableConcurrentBuilds()
timeout(time: 20, unit: 'MINUTES')
}
environment {
TMPDIR = "${sh(returnStdout: true, script: "mktemp -d").trim()}"
}
stages {
stage('Unit Tests') {
steps {
sh 'tox -r'
sh """
python3 -m venv ${env.TMPDIR}/venv/
${env.TMPDIR}/venv/bin/pip install tox
PGPORT=`python -c 'import struct; import socket; s=socket.socket(); s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", 1, 0)); s.bind(("", 0)); print(s.getsockname()[1]); s.close()'` pg_virtualenv -o fsync=off ${env.TMPDIR}/venv/bin/tox -r --workdir ${env.TMPDIR}/tox/"""
}
post {
always {
@ -41,6 +47,7 @@ pipeline {
}
}
cleanup {
sh "rm -rf ${env.TMPDIR}"
cleanWs()
}
}

View File

@ -22,7 +22,11 @@ DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'TEST': {
'NAME': 'barbacompta-test-%s' % os.environ.get("BRANCH_NAME", "").replace('/', '-')[:45],
'NAME': 'barbacompta-test',
},
}
}
for key in ('PGPORT', 'PGHOST', 'PGUSER', 'PGPASSWORD'):
if key in os.environ:
DATABASES['default']['TEST'][key[2:]] = os.environ[key]