Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 5509-entryDmsBack

This commit is contained in:
Alex Moreno 2024-01-31 08:34:37 +01:00
commit 7472570b95
7 changed files with 146 additions and 91 deletions

160
Jenkinsfile vendored
View File

@ -1,9 +1,17 @@
#!/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}"
@ -13,24 +21,37 @@ pipeline {
steps { steps {
script { script {
switch (env.BRANCH_NAME) { switch (env.BRANCH_NAME) {
case 'master': case 'dev':
env.NODE_ENV = 'production' env.NODE_ENV = 'dev'
env.BACK_REPLICAS = 4 env.BACK_REPLICAS = 1
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
} }
configFileProvider([ def packageJson = readJSON file: 'package.json'
configFile(fileId: "salix.groovy", env.VERSION = packageJson.version
variable: 'GROOVY_FILE')
]) {
load env.GROOVY_FILE
}
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
}
setEnv() setEnv()
} }
} }
@ -38,60 +59,85 @@ pipeline {
environment { environment {
NODE_ENV = "" NODE_ENV = ""
} }
parallel {
stage('Backend') {
steps { steps {
nodejs('node-v20') {
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 { not { anyOf { when {
branch 'test' expression { return RUN_TESTS }
branch 'master' }
}}}
environment { environment {
NODE_ENV = "" NODE_ENV = ""
TZ = 'Europe/Madrid' TZ = 'Europe/Madrid'
} }
parallel { parallel {
stage('Frontend') {
steps {
nodejs('node-v20') {
sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=4'
}
}
}
stage('Backend') { stage('Backend') {
steps { steps {
nodejs('node-v20') {
sh 'npm run test:back:ci' sh 'npm run test:back:ci'
} }
} }
stage('Frontend') {
steps {
sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=6'
}
} }
} }
} }
stage('Build') { stage('Build') {
when { anyOf { when {
branch 'test' expression { return PROTECTED_BRANCH && FROM_GIT }
branch 'master' }
}}
environment { environment {
CREDENTIALS = credentials('docker-registry') CREDENTIALS = credentials('docker-registry')
} }
steps { steps {
nodejs('node-v20') {
sh 'gulp build' sh 'gulp build'
}
dockerBuild() dockerBuild()
} }
} }
stage('Deploy') { stage('Deploy') {
when { anyOf { when {
branch 'test' expression { return PROTECTED_BRANCH }
branch 'master' }
}} parallel {
stage('Database') {
steps {
configFileProvider([
configFile(fileId: "config.${env.NODE_ENV}.ini",
variable: 'MYSQL_CONFIG')
]) {
sh 'mkdir -p db/remotes'
sh 'cp "$MYSQL_CONFIG" db/remotes/$NODE_ENV.ini'
}
sh 'npx myt push $NODE_ENV --force --commit'
}
}
stage('Docker') {
when {
expression { return FROM_GIT }
}
environment { environment {
DOCKER_HOST = "${env.SWARM_HOST}" DOCKER_HOST = "${env.SWARM_HOST}"
} }
@ -99,29 +145,13 @@ pipeline {
sh "docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${env.STACK_NAME}" sh "docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${env.STACK_NAME}"
} }
} }
stage('Database') {
when { anyOf {
branch 'test'
branch 'master'
}}
steps {
configFileProvider([
configFile(fileId: "config.${NODE_ENV}.ini",
variable: 'MYSQL_CONFIG')
]) {
sh 'mkdir -p db/remotes'
sh 'cp "$MYSQL_CONFIG" db/remotes/$NODE_ENV.ini'
}
nodejs('node-v20') {
sh 'npx myt push $NODE_ENV --force --commit'
}
} }
} }
} }
post { post {
always { always {
script { script {
if (!['master', 'test'].contains(env.BRANCH_NAME)) { if (RUN_TESTS) {
try { try {
junit 'junitresults.xml' junit 'junitresults.xml'
junit 'junit.xml' junit 'junit.xml'
@ -129,18 +159,28 @@ 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)
if (!env.COMMITTER_EMAIL || currentBuild.currentResult == 'SUCCESS') return; rocketSend(
try { channel: 'vn-database',
mail( message: "*DB version uploaded:* ${message}"
to: env.COMMITTER_EMAIL, +"\n$COMMITTER_EMAIL ($BRANCH_NAME)"
subject: "Pipeline: ${env.JOB_NAME} (${env.BUILD_NUMBER}): ${currentBuild.currentResult}", +"\n$GIT_URL/commit/$GIT_COMMIT",
body: "Check status at ${env.BUILD_URL}" rawMessage: true
) )
} catch (e) {
echo e.toString()
} }
} }
} }
unsuccessful {
sendEmail()
}
} }
} }

View File

@ -1,9 +1,10 @@
/* eslint-disable no-console */
const path = require('path'); const path = require('path');
const Myt = require('@verdnatura/myt/myt'); const Myt = require('@verdnatura/myt/myt');
const Run = require('@verdnatura/myt/myt-run'); const Run = require('@verdnatura/myt/myt-run');
let dataSources = require('../loopback/server/datasources.json'); let dataSources = require('../loopback/server/datasources.json');
let myt; let server;
process.on('warning', warning => { process.on('warning', warning => {
console.log(warning.name); console.log(warning.name);
@ -11,26 +12,33 @@ process.on('warning', warning => {
console.log(warning.stack); console.log(warning.stack);
}); });
process.on('SIGUSR2', async() => { process.on('SIGUSR2', rmServer);
if (myt) await myt.deinit(); process.on('exit', rmServer);
});
process.on('exit', async function() { async function rmServer() {
if (myt) await myt.deinit(); if (!server) return;
}); await server.rm();
server = null;
}
async function test() { async function test() {
console.log('Building and running DB container.');
const isCI = process.argv[2] === 'ci'; const isCI = process.argv[2] === 'ci';
myt = new Myt(); const myt = new Myt();
await myt.init({ await myt.init({
workspace: path.join(__dirname, '..'), workspace: path.join(__dirname, '..'),
random: true, random: true,
ci: isCI, ci: isCI,
tmpfs: true, tmpfs: process.platform == 'linux',
network: isCI ? 'jenkins' : null network: isCI ? 'jenkins' : null
}); });
const {dbConfig} = await myt.run(Run); server = await myt.run(Run);
await myt.deinit();
const {dbConfig} = server;
console.log('Initializing backend.');
dataSources = JSON.parse(JSON.stringify(dataSources)); dataSources = JSON.parse(JSON.stringify(dataSources));
Object.assign(dataSources.vn, { Object.assign(dataSources.vn, {
@ -47,6 +55,8 @@ async function test() {
// FIXME: Workaround to wait for loopback to be ready // FIXME: Workaround to wait for loopback to be ready
await app.models.Application.status(); await app.models.Application.status();
console.log('Running tests.');
const Jasmine = require('jasmine'); const Jasmine = require('jasmine');
const jasmine = new Jasmine(); const jasmine = new Jasmine();
@ -82,9 +92,13 @@ async function test() {
}); });
await jasmine.execute(); await jasmine.execute();
console.log('Stopping.');
if (app) await app.disconnect(); if (app) await app.disconnect();
if (myt) await myt.deinit(); await rmServer();
console.log('App disconnected & container removed');
console.log('Tests ended.\n');
} }
test(); test();

View File

@ -6,9 +6,10 @@
*/ */
SET foreign_key_checks = 0; SET foreign_key_checks = 0;
-- CREATE ROLE 'salix'; DROP ROLE 'salix';
-- GRANT 'salix' TO 'root'@'%'; CREATE ROLE 'salix';
-- SET DEFAULT ROLE 'salix' FOR 'root'@'%'; GRANT 'salix' TO 'root'@'%';
SET DEFAULT ROLE 'salix' FOR 'root'@'%';
CREATE SCHEMA IF NOT EXISTS `vn2008`; CREATE SCHEMA IF NOT EXISTS `vn2008`;
CREATE SCHEMA IF NOT EXISTS `tmp`; CREATE SCHEMA IF NOT EXISTS `tmp`;

View File

@ -1,7 +1,7 @@
version: '3.7' version: '3.7'
services: services:
front: front:
image: registry.verdnatura.es/salix-front:${BRANCH_NAME:?} image: registry.verdnatura.es/salix-front:${VERSION:?}
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:${BRANCH_NAME:?} image: registry.verdnatura.es/salix-back:${VERSION:?}
build: . build: .
ports: ports:
- 3000 - 3000

View File

@ -27,6 +27,6 @@ describe('Ticket expeditions and log path', () => {
const result = await page const result = await page
.countElement(selectors.ticketExpedition.expeditionRow); .countElement(selectors.ticketExpedition.expeditionRow);
expect(result).toEqual(4); expect(result).toEqual(6);
}); });
}); });

View File

@ -41,10 +41,10 @@ describe('Supplier basic data path', () => {
expect(result).toEqual('Plants Nick SL'); expect(result).toEqual('Plants Nick SL');
}); });
it('should check the isSerious checkbox is now unchecked', async() => { it('should check the isSerious checkbox is now checked', async() => {
const result = await page.checkboxState(selectors.supplierBasicData.isSerious); const result = await page.checkboxState(selectors.supplierBasicData.isSerious);
expect(result).toBe('unchecked'); expect(result).toBe('checked');
}); });
it('should check the isActive checkbox is now unchecked', async() => { it('should check the isActive checkbox is now unchecked', async() => {

View File

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