diff --git a/Jenkinsfile b/Jenkinsfile index 0aaba1e93..0d56f7476 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,19 +8,17 @@ pipeline { environment { PROJECT_NAME = 'salix' REGISTRY = 'registry.verdnatura.es' - DOCKER_HOST_1 = 'vch1.verdnatura.es' - DOCKER_HOST_2 = 'vch2.verdnatura.es' PORT_MASTER_FRONT = '5002' - PORT_MASTER_BACK = '3001-3002' + PORT_MASTER_BACK = '3001' PORT_TEST_FRONT = '5001' - PORT_TEST_BACK = '4001-4002' + PORT_TEST_BACK = '4001' TAG = "${env.BRANCH_NAME}" } stages { stage('Checkout') { steps { 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) { env.COMMITTER_EMAIL = sh( @@ -65,18 +63,23 @@ pipeline { } } stage('Test') { - when { not { anyOf { - branch 'test' - branch 'master' - }}} environment { NODE_ENV = "" - FIREFOX_BIN = "/opt/firefox/firefox-bin" } - steps { - nodejs('node-lts') { - sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=1' - sh 'gulp backTestDockerOnce --junit --random' + parallel { + stage('Frontend') { + steps { + 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 'master' }} - environment { - DOCKER_TLS_VERIFY = 1 - } - 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' - } - } - } + steps { + sh "docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${env.STACK_NAME}" } } stage('Database') { @@ -147,15 +126,6 @@ pipeline { sh 'db/import-changes.sh -f $NODE_ENV' } } - stage('Cleanup') { - when { anyOf { - branch 'test' - branch 'master' - }} - steps { - sh 'docker logout $REGISTRY' - } - } } post { always { diff --git a/docker-compose.yml b/docker-compose.yml index c0f02273e..c9011bdf4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,8 @@ services: - ${PORT_FRONT}:80 links: - back + deploy: + replicas: 3 back: image: registry.verdnatura.es/salix-back:${TAG} restart: unless-stopped @@ -19,6 +21,8 @@ services: environment: - NODE_ENV volumes: - - /containers/salix:/etc/salix + - /mnt/storage/containers/salix:/etc/salix - /mnt/storage/pdfs:/var/lib/salix/pdfs - /mnt/storage/dms:/var/lib/salix/dms + deploy: + replicas: 6 diff --git a/front/nginx.conf b/front/nginx.conf index 64f9436f3..22bce2283 100644 --- a/front/nginx.conf +++ b/front/nginx.conf @@ -7,11 +7,7 @@ server { client_max_body_size 250M; root /salix/dist; - error_page 404 = @notfound; - location @notfound { - return 302 /; - } location / { autoindex on; } diff --git a/gulpfile.js b/gulpfile.js index 06c65e451..dcb0aa6f1 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -110,17 +110,27 @@ backTestOnce.description = `Runs the backend tests once, can receive --junit arg async function backTestDockerOnce() { let containerId = await docker(); - await backTestOnce(); - if (argv['random']) - await execP(`docker rm -fv ${containerId}`); + try { + await backTestOnce(); + } catch (e) { + throw e; + } finally { + if (argv['random']) + await execP(`docker rm -fv ${containerId}`); + } } backTestDockerOnce.description = `Runs backend tests using in site container once`; async function backTestDocker() { let containerId = await docker(); - await backTest(); - if (argv['random']) - await execP(`docker rm -fv ${containerId}`); + try { + await backTest(); + } catch (e) { + throw e; + } finally { + if (argv['random']) + await execP(`docker rm -fv ${containerId}`); + } } backTestDocker.description = `Runs backend tests restoring fixtures first`;