Deploy with docker swarm
gitea/salix/test There was a failure building this commit Details

This commit is contained in:
Juan Ferrer 2019-12-19 14:27:29 +01:00
parent 7fa22da619
commit d5a9a62f73
3 changed files with 38 additions and 50 deletions

62
Jenkinsfile vendored
View File

@ -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,21 @@ 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 {
steps {
stage('Frontend') {
nodejs('node-lts') {
sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=1'
}
}
stage('Backend') {
nodejs('node-lts') {
sh 'gulp backTestDockerOnce --junit --random'
}
}
}
}
}
@ -96,6 +97,7 @@ pipeline {
sh 'docker login --username $CREDS_USR --password $CREDS_PSW $REGISTRY'
sh 'docker-compose build --parallel'
sh 'docker-compose push'
sh 'docker logout $REGISTRY'
}
}
stage('Deploy') {
@ -107,27 +109,8 @@ pipeline {
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 --compose-file docker-compose.yml ${env.STACK_NAME}"
}
}
}
@ -147,15 +130,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 {

View File

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

View File

@ -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`;