Compare commits

..

No commits in common. "826c8ff682605b419f6e5243064b182a66ebe8ed" and "bd990cf1051558b195296ab2fd49af2b3b96ad7e" have entirely different histories.

3 changed files with 75 additions and 114 deletions

183
Jenkinsfile vendored
View File

@ -1,57 +1,36 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
def PROTECTED_BRANCH
def FROM_GIT
def RUN_TESTS
pipeline { pipeline {
agent any agent any
options { options {
disableConcurrentBuilds() disableConcurrentBuilds()
} }
tools {
nodejs 'node-v20'
}
environment { environment {
PROJECT_NAME = 'salix' PROJECT_NAME = 'salix'
STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}" STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}"
} }
stages { stages {
stage('Checkout') { stage('Checkout') {
steps { steps {
script { script {
switch (env.BRANCH_NAME) { switch (env.BRANCH_NAME) {
case 'dev': case 'master':
env.NODE_ENV = 'dev' env.NODE_ENV = 'production'
env.BACK_REPLICAS = 1 env.BACK_REPLICAS = 4
break break
case 'test': case 'test':
env.NODE_ENV = 'test' env.NODE_ENV = 'test'
env.BACK_REPLICAS = 2 env.BACK_REPLICAS = 2
break break
case 'master':
env.NODE_ENV = 'production'
env.BACK_REPLICAS = 4
break
} }
def packageJson = readJSON file: 'package.json'
env.VERSION = packageJson.version
env.GIT_COMMIT_MSG = sh(
script: 'git log -1 --pretty=%B ${GIT_COMMIT}',
returnStdout: true
).trim()
PROTECTED_BRANCH = [
'dev',
'test',
'master'
].contains(env.BRANCH_NAME)
FROM_GIT = JOB_NAME.startsWith('gitea/')
RUN_TESTS = !PROTECTED_BRANCH && FROM_GIT
} }
configFileProvider([
configFile(fileId: "salix.groovy",
variable: 'GROOVY_FILE')
]) {
load env.GROOVY_FILE
}
setEnv() setEnv()
} }
} }
@ -59,91 +38,83 @@ pipeline {
environment { environment {
NODE_ENV = "" NODE_ENV = ""
} }
parallel { steps {
stage('Backend') { nodejs('node-v20') {
steps { sh 'npm install --no-audit --prefer-offline'
sh 'npm install --no-audit --prefer-offline' sh 'gulp install --ci'
}
}
stage('Frontend') {
when {
expression { return FROM_GIT }
}
steps {
sh 'npm install --no-audit --prefer-offline --prefix=front'
}
}
stage('Print') {
when {
expression { return FROM_GIT }
}
steps {
sh 'npm install --no-audit --prefer-offline --prefix=print'
}
} }
} }
} }
stage('Test') { stage('Test') {
when { when { not { anyOf {
expression { return RUN_TESTS } branch 'test'
} branch 'master'
}}}
environment { environment {
NODE_ENV = "" NODE_ENV = ""
TZ = 'Europe/Madrid' TZ = 'Europe/Madrid'
} }
parallel { parallel {
stage('Backend') {
steps {
sh 'npm run test:back:ci'
}
}
stage('Frontend') { stage('Frontend') {
steps { steps {
sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=6' nodejs('node-v20') {
sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=4'
}
}
}
stage('Backend') {
steps {
nodejs('node-v20') {
sh 'npm run test:back:ci'
}
} }
} }
} }
} }
stage('Build') { stage('Build') {
when { when { anyOf {
expression { return PROTECTED_BRANCH && FROM_GIT } branch 'test'
} branch 'master'
}}
environment { environment {
CREDENTIALS = credentials('docker-registry') CREDENTIALS = credentials('docker-registry')
} }
steps { steps {
sh 'gulp build' nodejs('node-v20') {
sh 'gulp build'
}
dockerBuild() dockerBuild()
} }
} }
stage('Deploy') { stage('Deploy') {
when { when { anyOf {
expression { return PROTECTED_BRANCH } branch 'test'
branch 'master'
}}
environment {
DOCKER_HOST = "${env.SWARM_HOST}"
} }
parallel { steps {
stage('Database') { sh "docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${env.STACK_NAME}"
steps { }
configFileProvider([ }
configFile(fileId: "config.${env.NODE_ENV}.ini", stage('Database') {
variable: 'MYSQL_CONFIG') when { anyOf {
]) { branch 'dev'
sh 'mkdir -p db/remotes' branch 'test'
sh 'cp "$MYSQL_CONFIG" db/remotes/$NODE_ENV.ini' branch 'master'
} }}
steps {
sh 'npx myt push $NODE_ENV --force --commit' configFileProvider([
} configFile(fileId: "config.${NODE_ENV}.ini",
variable: 'MYSQL_CONFIG')
]) {
sh 'mkdir -p db/remotes'
sh 'cp "$MYSQL_CONFIG" db/remotes/$NODE_ENV.ini'
} }
stage('Docker') { nodejs('node-v20') {
when { sh 'npx myt push $NODE_ENV --force --commit'
expression { return FROM_GIT }
}
environment {
DOCKER_HOST = "${env.SWARM_HOST}"
}
steps {
sh "docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${env.STACK_NAME}"
}
} }
} }
} }
@ -151,7 +122,7 @@ pipeline {
post { post {
always { always {
script { script {
if (RUN_TESTS) { if (!['master', 'test'].contains(env.BRANCH_NAME)) {
try { try {
junit 'junitresults.xml' junit 'junitresults.xml'
junit 'junit.xml' junit 'junit.xml'
@ -159,28 +130,18 @@ pipeline {
echo e.toString() echo e.toString()
} }
} }
}
}
success {
script {
if (env.BRANCH_NAME == 'master' && FROM_GIT) {
String message = env.GIT_COMMIT_MSG
int index = message.indexOf('\n')
if (index != -1)
message = message.substring(0, index)
rocketSend( if (!env.COMMITTER_EMAIL || currentBuild.currentResult == 'SUCCESS') return;
channel: 'vn-database', try {
message: "*DB version uploaded:* ${message}" mail(
+"\n$COMMITTER_EMAIL ($BRANCH_NAME)" to: env.COMMITTER_EMAIL,
+"\n$GIT_URL/commit/$GIT_COMMIT", subject: "Pipeline: ${env.JOB_NAME} (${env.BUILD_NUMBER}): ${currentBuild.currentResult}",
rawMessage: true body: "Check status at ${env.BUILD_URL}"
) )
} catch (e) {
echo e.toString()
} }
} }
} }
unsuccessful {
sendEmail()
}
} }
} }

View File

@ -1,7 +1,7 @@
version: '3.7' version: '3.7'
services: services:
front: front:
image: registry.verdnatura.es/salix-front:${VERSION:?} image: registry.verdnatura.es/salix-front:${BRANCH_NAME:?}
build: build:
context: . context: .
dockerfile: front/Dockerfile dockerfile: front/Dockerfile
@ -16,7 +16,7 @@ services:
limits: limits:
memory: 1G memory: 1G
back: back:
image: registry.verdnatura.es/salix-back:${VERSION:?} image: registry.verdnatura.es/salix-back:${BRANCH_NAME:?}
build: . build: .
ports: ports:
- 3000 - 3000

View File

@ -1,6 +1,6 @@
{ {
"name": "salix-back", "name": "salix-back",
"version": "24.6.0", "version": "24.06.01",
"author": "Verdnatura Levante SL", "author": "Verdnatura Levante SL",
"description": "Salix backend", "description": "Salix backend",
"license": "GPL-3.0", "license": "GPL-3.0",