From 027f7d2c1dc8e44711ee802a7e5ed1b1e3780613 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 20:41:24 +0100 Subject: [PATCH] build: refs #5483 dev deploy, tag image with version --- Jenkinsfile | 46 ++++++++++++++++++++++++++++++---------------- docker-compose.yml | 8 ++++++-- package.json | 2 +- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3ffa98394..a73047b31 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,24 +8,41 @@ pipeline { PROJECT_NAME = 'salix' STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}" } + parameters { + booleanParam( + name: 'PROTECTED_BRANCH', + defaultValue: false, + description: 'Whether branch is a protected branch' + ) + } stages { stage('Checkout') { steps { script { + def packageJson = readJSON file: 'package.json' + env.VERSION = packageJson.version + switch (env.BRANCH_NAME) { - case 'master': - env.NODE_ENV = 'production' - env.BACK_REPLICAS = 4 + case 'dev': + env.NODE_ENV = 'dev' + env.BACK_REPLICAS = 1 break case 'test': env.NODE_ENV = 'test' env.BACK_REPLICAS = 2 break - case 'dev': - env.NODE_ENV = 'dev' + case 'master': + env.NODE_ENV = 'production' + env.BACK_REPLICAS = 4 break } + params.PROTECTED_BRANCH = [ + 'dev', + 'test', + 'master' + ].contains(env.BRANCH_NAME) + env.GIT_COMMIT_MSG = sh( script: 'git log -1 --pretty=%B ${GIT_COMMIT}', returnStdout: true @@ -69,6 +86,7 @@ pipeline { when { environment name: 'RUN_SOURCE', value: 'git' not { anyOf { + branch 'dev' branch 'test' branch 'master' }} @@ -98,6 +116,7 @@ pipeline { when { environment name: 'RUN_SOURCE', value: 'git' anyOf { + branch 'dev' branch 'test' branch 'master' } @@ -114,13 +133,13 @@ pipeline { } } stage('Deploy') { + when { anyOf { + branch 'dev' + branch 'test' + branch 'master' + }} parallel { stage('Database') { - when { anyOf { - branch 'dev' - branch 'test' - branch 'master' - }} steps { configFileProvider([ configFile(fileId: "config.${env.NODE_ENV}.ini", @@ -137,10 +156,6 @@ pipeline { stage('Docker') { when { environment name: 'RUN_SOURCE', value: 'git' - anyOf { - branch 'test' - branch 'master' - } } environment { DOCKER_HOST = "${env.SWARM_HOST}" @@ -155,8 +170,7 @@ pipeline { post { success { script { - if (env.RUN_SOURCE == 'git' - && ['master', 'test'].contains(env.BRANCH_NAME)) { + if (env.RUN_SOURCE == 'git' && env.BRANCH_NAME == 'master') { String message = env.GIT_COMMIT_MSG int index = message.indexOf('\n') if (index != -1) diff --git a/docker-compose.yml b/docker-compose.yml index 0d2db1a63..32bcb1777 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,9 @@ version: '3.7' services: front: - image: registry.verdnatura.es/salix-front:${BRANCH_NAME:?} + image: registry.verdnatura.es/salix-front:${VERSION:?} + tags: + - ${BRANCH_NAME:?} build: context: . dockerfile: front/Dockerfile @@ -16,7 +18,9 @@ services: limits: memory: 1G back: - image: registry.verdnatura.es/salix-back:${BRANCH_NAME:?} + image: registry.verdnatura.es/salix-back:${VERSION:?} + tags: + - ${BRANCH_NAME:?} build: . ports: - 3000 diff --git a/package.json b/package.json index 3f3a3ad8e..041bd39df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.06.01", + "version": "24.6.0", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0",