From b6c1fd2e8e0e1ee205b9d3a301b44f828e58456f Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 08:28:55 +0100 Subject: [PATCH] Docker deploy with private registry --- Jenkinsfile | 42 +++++++++++++++++++++++++++++------------- docker-compose.yml | 8 ++++---- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 10f78ee78..f2838a43a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -32,25 +32,41 @@ try { } } stage ('Deploy') { - withCredentials([dockerCert(credentialsId: 'docker', variable: 'DOCKER_CERT_PATH')]) { - switch (env.BRANCH_NAME) { - case 'master': - env.PORT = 5000 - break; - case 'test': - env.PORT = 5001 - break; - } + env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-'); + env.TAG = env.BRANCH_NAME - env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-'); + switch (env.BRANCH_NAME) { + case 'master': + env.PORT = 5002 + break; + case 'test': + env.PORT = 5001 + break; + } + + withCredentials([usernamePassword( + credentialsId: 'docker-registry', + usernameVariable: 'USER', + passwordVariable: 'PASSWORD') + ]) { + env.REGISTRY = 'registry.verdnatura.es' + sh "docker login --username \"${env.USER}\" --password \"${env.PASSWORD}\" ${env.REGISTRY}" + sh "docker-compose build --parallel" + sh "docker-compose push" + sh "docker logout ${env.REGISTRY}" + } + + withCredentials([dockerCert( + credentialsId: 'docker', + variable: 'DOCKER_CERT_PATH') + ]) { env.DOCKER_TLS_VERIFY = 1 - env.TAG = env.BRANCH_NAME env.DOCKER_HOST = 'tcp://vch1.verdnatura.es:2376'; - sh "docker-compose up --build -d" + sh "docker-compose up -d" env.DOCKER_HOST = 'tcp://vch2.verdnatura.es:2376'; - sh "docker-compose up --build -d" + sh "docker-compose up -d" } } } diff --git a/docker-compose.yml b/docker-compose.yml index 9787368aa..317557eb2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,20 +1,20 @@ version: '3.5' services: app: + image: registry.verdnatura.es/salix-app:${TAG} + restart: unless-stopped build: context: . dockerfile: services/nginx/Dockerfile ports: - ${PORT}:80 - image: salix-app:${TAG} - restart: unless-stopped links: - api api: + image: registry.verdnatura.es/salix-api:${TAG} + restart: unless-stopped build: . environment: - NODE_ENV - restart: unless-stopped - image: salix-api:${TAG} volumes: - /containers/salix:/etc/salix