Merge branch 'test'
gitea/salix/master This commit looks good Details

This commit is contained in:
Juan Ferrer 2019-12-22 15:12:57 +01:00
commit c8e4615433
4 changed files with 40 additions and 60 deletions

68
Jenkinsfile vendored
View File

@ -8,19 +8,17 @@ pipeline {
environment { environment {
PROJECT_NAME = 'salix' PROJECT_NAME = 'salix'
REGISTRY = 'registry.verdnatura.es' REGISTRY = 'registry.verdnatura.es'
DOCKER_HOST_1 = 'vch1.verdnatura.es'
DOCKER_HOST_2 = 'vch2.verdnatura.es'
PORT_MASTER_FRONT = '5002' PORT_MASTER_FRONT = '5002'
PORT_MASTER_BACK = '3001-3002' PORT_MASTER_BACK = '3001'
PORT_TEST_FRONT = '5001' PORT_TEST_FRONT = '5001'
PORT_TEST_BACK = '4001-4002' PORT_TEST_BACK = '4001'
TAG = "${env.BRANCH_NAME}" TAG = "${env.BRANCH_NAME}"
} }
stages { stages {
stage('Checkout') { stage('Checkout') {
steps { steps {
script { script {
env.COMPOSE_PROJECT_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}" env.STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}"
if (!env.GIT_COMMITTER_EMAIL) { if (!env.GIT_COMMITTER_EMAIL) {
env.COMMITTER_EMAIL = sh( env.COMMITTER_EMAIL = sh(
@ -65,18 +63,23 @@ pipeline {
} }
} }
stage('Test') { stage('Test') {
when { not { anyOf {
branch 'test'
branch 'master'
}}}
environment { environment {
NODE_ENV = "" NODE_ENV = ""
FIREFOX_BIN = "/opt/firefox/firefox-bin"
} }
steps { parallel {
nodejs('node-lts') { stage('Frontend') {
sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=1' steps {
sh 'gulp backTestDockerOnce --junit --random' nodejs('node-lts') {
sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=1'
}
}
}
stage('Backend') {
steps {
nodejs('node-lts') {
sh 'gulp backTestDockerOnce --junit --random'
}
}
} }
} }
} }
@ -103,32 +106,8 @@ pipeline {
branch 'test' branch 'test'
branch 'master' branch 'master'
}} }}
environment { steps {
DOCKER_TLS_VERIFY = 1 sh "docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${env.STACK_NAME}"
}
parallel {
stage('Host 1') {
environment {
DOCKER_HOST = "tcp://${env.DOCKER_HOST_1}:2376"
}
steps {
withCredentials([dockerCert(credentialsId: 'docker', variable: 'DOCKER_CERT_PATH')]) {
sh 'docker-compose pull'
sh 'docker-compose up -d --scale back=2'
}
}
}
stage('Host 2') {
environment {
DOCKER_HOST = "tcp://${env.DOCKER_HOST_2}:2376"
}
steps {
withCredentials([dockerCert(credentialsId: 'docker', variable: 'DOCKER_CERT_PATH')]) {
sh 'docker-compose pull'
sh 'docker-compose up -d --scale back=2'
}
}
}
} }
} }
stage('Database') { stage('Database') {
@ -147,15 +126,6 @@ pipeline {
sh 'db/import-changes.sh -f $NODE_ENV' sh 'db/import-changes.sh -f $NODE_ENV'
} }
} }
stage('Cleanup') {
when { anyOf {
branch 'test'
branch 'master'
}}
steps {
sh 'docker logout $REGISTRY'
}
}
} }
post { post {
always { always {

View File

@ -10,6 +10,8 @@ services:
- ${PORT_FRONT}:80 - ${PORT_FRONT}:80
links: links:
- back - back
deploy:
replicas: 3
back: back:
image: registry.verdnatura.es/salix-back:${TAG} image: registry.verdnatura.es/salix-back:${TAG}
restart: unless-stopped restart: unless-stopped
@ -19,6 +21,8 @@ services:
environment: environment:
- NODE_ENV - NODE_ENV
volumes: volumes:
- /containers/salix:/etc/salix - /mnt/storage/containers/salix:/etc/salix
- /mnt/storage/pdfs:/var/lib/salix/pdfs - /mnt/storage/pdfs:/var/lib/salix/pdfs
- /mnt/storage/dms:/var/lib/salix/dms - /mnt/storage/dms:/var/lib/salix/dms
deploy:
replicas: 6

View File

@ -7,11 +7,7 @@ server {
client_max_body_size 250M; client_max_body_size 250M;
root /salix/dist; root /salix/dist;
error_page 404 = @notfound;
location @notfound {
return 302 /;
}
location / { location / {
autoindex on; autoindex on;
} }

View File

@ -110,17 +110,27 @@ backTestOnce.description = `Runs the backend tests once, can receive --junit arg
async function backTestDockerOnce() { async function backTestDockerOnce() {
let containerId = await docker(); let containerId = await docker();
await backTestOnce(); try {
if (argv['random']) await backTestOnce();
await execP(`docker rm -fv ${containerId}`); } catch (e) {
throw e;
} finally {
if (argv['random'])
await execP(`docker rm -fv ${containerId}`);
}
} }
backTestDockerOnce.description = `Runs backend tests using in site container once`; backTestDockerOnce.description = `Runs backend tests using in site container once`;
async function backTestDocker() { async function backTestDocker() {
let containerId = await docker(); let containerId = await docker();
await backTest(); try {
if (argv['random']) await backTest();
await execP(`docker rm -fv ${containerId}`); } catch (e) {
throw e;
} finally {
if (argv['random'])
await execP(`docker rm -fv ${containerId}`);
}
} }
backTestDocker.description = `Runs backend tests restoring fixtures first`; backTestDocker.description = `Runs backend tests restoring fixtures first`;