refs #5739 feat(docker): run back tests
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2023-12-19 15:32:39 +01:00
parent 865ab56ef3
commit e4dcdc0a72
15 changed files with 96 additions and 223 deletions

View File

@ -3,7 +3,7 @@
// Carácter predeterminado de final de línea. // Carácter predeterminado de final de línea.
"files.eol": "\n", "files.eol": "\n",
"editor.codeActionsOnSave": { "editor.codeActionsOnSave": {
"source.fixAll.eslint": true "source.fixAll.eslint": "explicit"
}, },
"search.useIgnoreFiles": false, "search.useIgnoreFiles": false,
"editor.defaultFormatter": "dbaeumer.vscode-eslint", "editor.defaultFormatter": "dbaeumer.vscode-eslint",

View File

@ -31,14 +31,13 @@ RUN apt-get update \
WORKDIR /salix WORKDIR /salix
COPY print/package.json print/package-lock.json print/ COPY print/package.json print/package-lock.json print/
RUN npm --prefix ./print install ./print RUN npm --prefix ./print install --omit=dev ./print
COPY package.json package-lock.json ./ COPY package.json package-lock.json ./
COPY loopback/package.json loopback/ COPY loopback/package.json loopback/
RUN npm install RUN npm install --omit=dev
COPY loopback loopback COPY loopback loopback
COPY storage storage
COPY back back COPY back back
COPY modules modules COPY modules modules
COPY print print COPY print print

13
Jenkinsfile vendored
View File

@ -39,10 +39,7 @@ pipeline {
NODE_ENV = "" NODE_ENV = ""
} }
steps { steps {
nodejs('node-v20') { sh "docker build -f front/Dockerfile.test -t salix-front"
sh 'npm install --no-audit --prefer-offline'
sh 'gulp install --ci'
}
} }
} }
stage('Test') { stage('Test') {
@ -57,16 +54,12 @@ pipeline {
parallel { parallel {
stage('Frontend') { stage('Frontend') {
steps { steps {
nodejs('node-v20') { sh docker compose -f docker-compose.test.yml up front
sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=2'
}
} }
} }
stage('Backend') { stage('Backend') {
steps { steps {
nodejs('node-v20') { sh docker compose -f docker-compose.test.yml up back
sh 'npm run test:back:ci'
}
} }
} }
} }

View File

@ -1,11 +1,8 @@
FROM node:20-bullseye-slim FROM node:20-bullseye-slim
ENV TZ Europe/Madrid ENV TZ Europe/Madrid
ARG DEBIAN_FRONTEND=noninteractive ARG DEBIAN_FRONTEND=noninteractive
# Puppeteer # Puppeteer
RUN apt-get update \ RUN apt-get update \
&& apt-get install -y --no-install-recommends \ && apt-get install -y --no-install-recommends \
gnupg2 \ gnupg2 \
@ -19,15 +16,12 @@ RUN apt-get update \
fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
# Extra dependencies # Extra dependencies
RUN apt-get update \ RUN apt-get update \
&& apt-get install -y --no-install-recommends \ && apt-get install -y --no-install-recommends \
samba-common-bin samba-dsdb-modules\ samba-common-bin samba-dsdb-modules\
&& rm -rf /var/lib/apt/lists/* \ && rm -rf /var/lib/apt/lists/*
&& npm -g install pm2
# Salix # Salix
WORKDIR /salix WORKDIR /salix
COPY print/package.json print/package-lock.json print/ COPY print/package.json print/package-lock.json print/
@ -35,16 +29,15 @@ RUN npm --prefix ./print install ./print
COPY package.json package-lock.json ./ COPY package.json package-lock.json ./
COPY loopback/package.json loopback/ COPY loopback/package.json loopback/
RUN npm install RUN npm install --ci
COPY gulpfile.js ./ COPY gulpfile.js ./
COPY \ COPY \
LICENSE \ LICENSE \
README.md \ README.md \
./ ./
CMD ["npx", "gulp", "backOnly"] FROM scratch
WORKDIR /salix
HEALTHCHECK --interval=15s --timeout=10s \ CMD ["npx", "gulp", "backWatch"]
CMD curl -f http://localhost:3000/api/Applications/status || exit 1

9
back/Dockerfile.test Normal file
View File

@ -0,0 +1,9 @@
FROM back:local
COPY loopback loopback
COPY back back
COPY modules modules
COPY print print
COPY storage storage
CMD ["npx", "gulp", "backOnly"]

View File

@ -1,4 +1,4 @@
const Docker = require('../db/docker.js'); // const Docker = require('../db/docker.js');
let dataSources = require('../loopback/server/datasources.json'); let dataSources = require('../loopback/server/datasources.json');
process.on('warning', warning => { process.on('warning', warning => {
@ -11,23 +11,14 @@ process.on('exit', async function() {
if (container) await container.rm(); if (container) await container.rm();
}); });
let container;
async function test() { async function test() {
let isCI = false; let isCI = false;
if (process.argv[2] === 'ci') if (process.argv[2] === 'ci')
isCI = true; isCI = true;
container = new Docker();
await container.run(isCI);
dataSources = JSON.parse(JSON.stringify(dataSources)); dataSources = JSON.parse(JSON.stringify(dataSources));
Object.assign(dataSources.vn, {
host: container.dbConf.host,
port: container.dbConf.port
});
const bootOptions = {dataSources}; const bootOptions = {dataSources};
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
@ -73,7 +64,6 @@ async function test() {
await jasmine.execute(); await jasmine.execute();
if (app) await app.disconnect(); if (app) await app.disconnect();
if (container) await container.rm();
console.log('App disconnected & container removed'); console.log('App disconnected & container removed');
} }

View File

@ -1,12 +1,15 @@
version: "3.7" version: "3.7"
services: services:
db: db:
image: salix-db image: db:local
restart: unless-stopped
build: build:
context: db context: db
dockerfile: Dockerfile dockerfile: Dockerfile
ports:
- 3306:3306
front: front:
image: front image: front:local
restart: unless-stopped restart: unless-stopped
build: build:
context: . context: .
@ -20,17 +23,13 @@ services:
- ./dist:/salix/dist - ./dist:/salix/dist
- ./front:/salix/front - ./front:/salix/front
- ./loopback:/salix/loopback - ./loopback:/salix/loopback
x-develop:
watch:
- action: sync
- path: ./modules
- target: /modules
back: back:
image: salix-back image: back:local
restart: unless-stopped restart: unless-stopped
build: build:
context: . context: .
dockerfile: Dockerfile.local dockerfile: back/Dockerfile.local
ports: ports:
- 3000:3000 - 3000:3000
environment: environment:
@ -43,14 +42,7 @@ services:
- ./modules:/salix/modules - ./modules:/salix/modules
- ./back:/salix/back - ./back:/salix/back
- ./print:/salix/print - ./print:/salix/print
x-develop:
watch:
- action: sync
- path: ./back
- target: /back
- action: sync
- path: ./models
- target: /models
networks: networks:
salix-stack-network: salix-stack-network:
driver: host driver: host

33
docker-compose.test.yml Normal file
View File

@ -0,0 +1,33 @@
version: "3.7"
services:
db:
image: salix-db
restart: always
build:
context: db
dockerfile: Dockerfile
front:
image: salix-front
restart: always
command: ["npm", "run", "test:front:ci"]
build:
context: .
dockerfile: front/Dockerfile.test
depends_on:
- back
back:
image: salix-back
restart: always
command: ["npm", "run", "test:back:ci"]
build:
context: .
dockerfile: back/Dockerfile.test
environment:
- NODE_ENV
depends_on:
- db
networks:
salix-stack-network:
driver: host

View File

@ -1,13 +1,10 @@
FROM salix-back FROM salix-back
EXPOSE 5000 EXPOSE 5000
COPY /dist dist
COPY /front front
COPY /front/gulpfile.js ./ COPY /front/gulpfile.js ./
COPY /front/webpack.config.js ./ COPY /front/webpack.config.js ./
COPY /front/package.json ./front/
RUN cd front && npm install RUN cd front && npm install --ci
# RUN npx gulp build
# RUN npx gulp front
CMD ["npx", "gulp", "front"] CMD ["npx", "gulp", "front"]

17
front/Dockerfile.test Normal file
View File

@ -0,0 +1,17 @@
FROM salix-back
EXPOSE 5000
COPY front front
RUN cd front && npm install --ci
COPY modules modules
COPY dist dist
COPY jest-front.js ./
COPY jest.front.config.js ./
COPY fileMock.js ./
COPY /front/gulpfile.js ./
COPY /front/webpack.config.js ./
CMD ["npx", "gulp", "front"]

View File

@ -4,6 +4,7 @@
"author": "Verdnatura Levante SL", "author": "Verdnatura Levante SL",
"description": "Salix frontend", "description": "Salix frontend",
"license": "GPL-3.0", "license": "GPL-3.0",
"type": "module",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://gitea.verdnatura.es/verdnatura/salix" "url": "https://gitea.verdnatura.es/verdnatura/salix"

View File

@ -59,6 +59,13 @@ function backWatch(done) {
} }
backWatch.description = `Starts backend in watcher mode`; backWatch.description = `Starts backend in watcher mode`;
function backTest(done) {
let app = require(`./loopback/server/server`);
app.start();
app.on('started', done);
}
backOnly.description = `Starts backend service`;
const back = gulp.series(dockerStart, backWatch); const back = gulp.series(dockerStart, backWatch);
back.description = `Starts backend and database service`; back.description = `Starts backend and database service`;

View File

@ -107,13 +107,16 @@
}, },
"scripts": { "scripts": {
"dbtest": "nodemon -q db/tests.js -w db/tests", "dbtest": "nodemon -q db/tests.js -w db/tests",
"test:back": "nodemon -q back/tests.js --config back/nodemonConfig.json", "test:back": "docker compose -f docker-compose.test.yml run --build back npm run test:back:ci",
"test:back:ci": "node back/tests.js ci", "test:back:ci": "node back/tests.js ci",
"test:e2e": "node e2e/helpers/tests.js", "test:e2e": "node e2e/helpers/tests.js",
"test:front": "jest --watch", "test:front": "docker compose -f docker-compose.test.yml up front --build",
"test:front:ci": "jest --ci --maxWorkers=2",
"back": "nodemon --inspect -w modules ./node_modules/gulp/bin/gulp.js back", "back": "nodemon --inspect -w modules ./node_modules/gulp/bin/gulp.js back",
"lint": "eslint ./ --cache --ignore-pattern .gitignore", "lint": "eslint ./ --cache --ignore-pattern .gitignore",
"docker": "docker build --progress=plain -t salix-db ./db" "docker": "docker build --progress=plain -t salix-db ./db",
"start": "docker compose -f docker-compose.local.yml up",
"restart": "docker compose -f docker-compose.local.yml up --build"
}, },
"jest": { "jest": {
"projects": [ "projects": [

View File

@ -1,2 +0,0 @@
gulp build
docker-compose -f "docker-compose.local.yml" up --build

View File

@ -1,159 +0,0 @@
require('require-yaml');
const webpack = require('webpack');
const path = require('path');
const merge = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
let env = process.env.NODE_ENV || 'development';
let mode = env == 'development' ? env : 'production';
let baseConfig = {
entry: {salix: 'salix'},
mode,
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/'
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-syntax-dynamic-import']
}
}, {
test: /\.yml$/,
use: ['json-loader!yaml-loader']
}, {
test: /\.html$/,
loader: 'html-loader',
options: {
attrs: [
'img:src',
'link:href'
]
}
}, {
test: /\.css$/,
use: ['style-loader', 'css-loader']
}, {
test: /\.scss$/,
use: [
'style-loader', 'css-loader', {
loader: 'sass-loader',
options: {
// XXX: Don't work in Firefox
// https://github.com/webpack-contrib/style-loader/issues/303
// sourceMap: true,
sassOptions: {
includePaths: [
path.resolve(__dirname, 'front/core/styles/')
]
}
}
}
]
}, {
test: /\.(woff(2)?|ttf|eot|svg|png)(\?v=\d+\.\d+\.\d+)?$/,
type: 'asset/resource',
}, {
test: /manifest\.json$/,
type: 'javascript/auto',
loader: 'file-loader',
options: {
esModule: false,
}
}
]
},
optimization: {
runtimeChunk: true,
splitChunks: {
chunks: 'all',
}
},
resolve: {
modules: [
`front`,
`modules`,
`front/node_modules`,
`node_modules`
],
alias: {
'vn-loopback': `${__dirname}/loopback`
}
},
watchOptions: {
ignored: [
'node_modules',
'./modules/*/back/**'
]
},
plugins: [
new HtmlWebpackPlugin({
template: 'front/salix/index.ejs',
favicon: 'front/salix/favicon.ico',
filename: 'index.html',
chunks: ['salix']
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env)
})
],
devtool: 'source-map',
stats: {
assets: false,
modules: false,
children: false,
entrypoints: false,
colors: true
}
};
let prodConfig = {
output: {
filename: '[name].[chunkhash].js',
chunkFilename: '[id].[chunkhash].js'
},
plugins: [
new webpack.ids.HashedModuleIdsPlugin()
],
performance: {
maxEntrypointSize: 2000000,
maxAssetSize: 2000000
}
};
let devConfig = {
output: {
filename: '[name].js',
chunkFilename: '[id].js'
},
plugins: [
new webpack.HotModuleReplacementPlugin()
],
devServer: {
host: '0.0.0.0',
port: 5000,
publicPath: '/',
contentBase: 'dist',
quiet: false,
noInfo: false,
hot: true,
inline: true,
stats: baseConfig.stats,
proxy: {
'/api': 'http://back:3000',
'/*/api/**': {
target: 'http://back:3000',
pathRewrite: {'^/[\\w-]+': ''}
}
}
}
};
let mrgConfig = mode === 'development' ? devConfig : prodConfig;
module.exports = merge(baseConfig, mrgConfig);