From a67a347a9ef185ed809468d958c215aa00d4b4ee Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 6 Feb 2024 21:51:15 +0100 Subject: [PATCH] ci: refs#6706 CI fixes --- .dockerignore | 6 ++++-- Jenkinsfile | 23 ++++++++++++----------- back/tests.js | 41 ++++++++++++++++++++++++++++++----------- docker-compose.yml | 10 ++++++---- front/Dockerfile | 2 +- gulpfile.js | 2 +- package.json | 3 ++- pnpm-lock.yaml | 3 +++ webpack.config.js | 4 ++-- 9 files changed, 61 insertions(+), 33 deletions(-) diff --git a/.dockerignore b/.dockerignore index afe81bb0f..1a47908ab 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,6 @@ node_modules print/node_modules -front/node_modules -services \ No newline at end of file +front +db +e2e +storage diff --git a/Jenkinsfile b/Jenkinsfile index 56e33f4ae..4bacaa6d2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -86,9 +86,6 @@ pipeline { } } stage('Stack') { - environment { - TZ = 'Europe/Madrid' - } parallel { stage('Back') { stages { @@ -104,14 +101,10 @@ pipeline { } post { always { - script { - try { - junit 'junitresults.xml' - junit 'junit.xml' - } catch (e) { - echo e.toString() - } - } + junit( + testResults: 'junitresults.xml', + allowEmptyResults: true + ) } } } @@ -144,6 +137,14 @@ pipeline { steps { sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=10' } + post { + always { + junit( + testResults: 'junit.xml', + allowEmptyResults: true + ) + } + } } stage('Build') { when { diff --git a/back/tests.js b/back/tests.js index 0fb4c76ea..1848132f8 100644 --- a/back/tests.js +++ b/back/tests.js @@ -1,19 +1,36 @@ /* eslint-disable no-console */ const path = require('path'); +const getopts = require('getopts'); const Myt = require('@verdnatura/myt/myt'); const Run = require('@verdnatura/myt/myt-run'); const helper = require('./tests-helper'); +const opts = getopts(process.argv.slice(2), { + string: [ + 'network' + ], + boolean: [ + 'ci', + 'junit' + ] +}); + let server; -const isCI = process.argv[2] === 'ci'; const PARALLEL = false; const TIMEOUT = 900000; -process.on('SIGINT', teardown); process.on('exit', teardown); process.on('uncaughtException', onError); process.on('unhandledRejection', onError); +const exitSignals = [ + 'SIGINT', + 'SIGUSR1', + 'SIGUSR2' +]; +for (const signal of exitSignals) + process.on(signal, () => process.exit()); + async function setup() { console.log('Building and running DB container.'); @@ -21,9 +38,9 @@ async function setup() { await myt.init({ workspace: path.join(__dirname, '..'), random: true, - ci: isCI, + ci: opts.ci, tmpfs: process.platform == 'linux', - network: isCI ? 'jenkins' : null + network: opts.network || null }); server = await myt.run(Run); await myt.deinit(); @@ -38,18 +55,19 @@ async function setup() { async function teardown() { if (!server) return; + const oldServer = server; + server = null; if (!PARALLEL) await helper.deinit(); console.log('Stopping and removing DB container.'); - await server.rm(); - server = null; + await oldServer.rm(); } async function onError(err) { - await teardown(); console.error(err); + process.exit(1); } async function test() { @@ -79,8 +97,8 @@ async function test() { const SpecReporter = require('jasmine-spec-reporter').SpecReporter; runner.addReporter(new SpecReporter({ spec: { - displaySuccessful: isCI, - displayPending: isCI + displaySuccessful: opts.ci, + displayPending: opts.ci }, summary: { displayPending: false, @@ -88,11 +106,12 @@ async function test() { })); } - if (isCI) { + if (opts.junit) { const JunitReporter = require('jasmine-reporters'); runner.addReporter(new JunitReporter.JUnitXmlReporter()); - runner.jasmine.DEFAULT_TIMEOUT_INTERVAL = TIMEOUT; } + if (opts.ci) + runner.jasmine.DEFAULT_TIMEOUT_INTERVAL = TIMEOUT; // runner.loadConfigFile('back/jasmine.json'); runner.loadConfig(config); diff --git a/docker-compose.yml b/docker-compose.yml index dda4187f2..8391a5e23 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,8 +3,9 @@ services: front: image: registry.verdnatura.es/salix-front:${VERSION:?} build: - context: . - dockerfile: front/Dockerfile + context: front + environment: + - TZ ports: - 80 deploy: @@ -18,11 +19,12 @@ services: back: image: registry.verdnatura.es/salix-back:${VERSION:?} build: . - ports: - - 3000 environment: - NODE_ENV - DEBUG + - TZ + ports: + - 3000 configs: - source: datasources target: /etc/salix/datasources.json diff --git a/front/Dockerfile b/front/Dockerfile index d0ee26904..c507d863c 100644 --- a/front/Dockerfile +++ b/front/Dockerfile @@ -10,7 +10,7 @@ RUN apt-get update \ && ln -sf /dev/stderr /var/log/nginx/error.log WORKDIR /etc/nginx -COPY front/nginx.conf sites-available/salix +COPY nginx.conf sites-available/salix RUN rm sites-enabled/default && ln -s ../sites-available/salix sites-enabled/salix COPY dist /salix/dist diff --git a/gulpfile.js b/gulpfile.js index a4caa6196..1c6fe2a2d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -17,7 +17,7 @@ if (argv.NODE_ENV) let langs = ['es', 'en']; let srcDir = './front'; let modulesDir = './modules'; -let buildDir = 'dist'; +let buildDir = 'front/dist'; let backSources = [ '!node_modules', diff --git a/package.json b/package.json index 04c0e6d04..ff8eca428 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "eslint-plugin-jasmine": "^2.10.1", "fancy-log": "^1.3.2", "file-loader": "^6.2.0", + "getopts": "^2.3.0", "gulp": "^4.0.2", "gulp-concat": "^2.6.1", "gulp-env": "^0.4.0", @@ -107,7 +108,7 @@ "scripts": { "dbtest": "nodemon -q db/tests.js -w db/tests", "test:back": "nodemon -q back/tests.js --config back/nodemonConfig.json", - "test:back:ci": "node back/tests.js ci", + "test:back:ci": "node back/tests.js --ci --junit --network jenkins", "test:e2e": "node e2e/helpers/tests.js", "test:front": "jest --watch", "back": "nodemon --inspect -w modules ./node_modules/gulp/bin/gulp.js back", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2df0ae49c..69528e3e2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -163,6 +163,9 @@ devDependencies: file-loader: specifier: ^6.2.0 version: 6.2.0(webpack@5.90.1) + getopts: + specifier: ^2.3.0 + version: 2.3.0 gulp: specifier: ^4.0.2 version: 4.0.2 diff --git a/webpack.config.js b/webpack.config.js index a102b838e..7296a62d1 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -11,7 +11,7 @@ let baseConfig = { entry: {salix: 'salix'}, mode, output: { - path: path.join(__dirname, 'dist'), + path: path.join(__dirname, 'front/dist'), publicPath: '/' }, module: { @@ -139,7 +139,7 @@ let devConfig = { host: '0.0.0.0', port: 5000, publicPath: '/', - contentBase: 'dist', + contentBase: 'front/dist', quiet: false, noInfo: false, hot: true,