diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..a44836d35 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM node:stretch-slim +RUN npm install -g @quasar/cli +WORKDIR /app +COPY dist/spa ./ +CMD ["quasar", "serve", "./", "--history", "--hostname", "localhost"] \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..178fbcbcc --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,100 @@ +#!/usr/bin/env groovy +pipeline { + agent any + options { + disableConcurrentBuilds() + } + environment { + PROJECT_NAME = 'lilium' + STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}" + } + stages { + stage('Checkout') { + steps { + script { + switch (env.BRANCH_NAME) { + // case 'master': + // env.NODE_ENV = 'production' + // env.BACK_REPLICAS = 1 + // break + case 'test': + env.NODE_ENV = 'test' + env.BACK_REPLICAS = 1 + break + } + } + setEnv() + } + } + stage('Install') { + environment { + NODE_ENV = "" + } + steps { + nodejs('node-v14') { + sh 'npm install -g @quasar/cli' + sh 'npm install --no-audit --prefer-offline' + } + } + } + stage('Test') { + when { not { anyOf { + branch 'test' + branch 'master' + }}} + environment { + NODE_ENV = "" + } + parallel { + stage('Frontend') { + steps { + nodejs('node-v14') { + sh 'npm run test:unit:ci' + } + } + } + } + } + stage('Build') { + when { anyOf { + branch 'test' + // branch 'master' + }} + environment { + CREDENTIALS = credentials('docker-registry') + } + steps { + nodejs('node-v14') { + sh 'quasar build' + } + dockerBuild() + } + } + stage('Deploy') { + when { anyOf { + branch 'test' + // branch 'master' + }} + environment { + DOCKER_HOST = "${env.SWARM_HOST}" + } + steps { + sh "docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${env.STACK_NAME}" + } + } + } + post { + always { + script { + if (!['master', 'test'].contains(env.BRANCH_NAME)) { + try { + junit 'junitresults.xml' + junit 'junit.xml' + } catch (e) { + echo e.toString() + } + } + } + } + } +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..0ab098249 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3.7' +services: + main: + image: registry.verdnatura.es/salix-frontend:${BRANCH_NAME:?} + build: + context: . + dockerfile: ./Dockerfile + ports: + - 4000 + deploy: + replicas: 2 + placement: + constraints: + - node.role == worker \ No newline at end of file diff --git a/jest.config.js b/jest.config.js index e18a46123..0a4ace8b1 100755 --- a/jest.config.js +++ b/jest.config.js @@ -16,8 +16,9 @@ module.exports = { // cache: false, // verbose: true, // watch: true, + reporters: ['default', 'jest-junit'], collectCoverage: false, - coverageDirectory: '/test/jest/coverage', + coverageDirectory: '/tests/jest/coverage', collectCoverageFrom: ['/src/**/*.vue', '/src/**/*.js', '/src/**/*.jsx'], // Needed in JS codebases too because of feature flags coveragePathIgnorePatterns: ['/node_modules/', '.d.ts$'], diff --git a/package-lock.json b/package-lock.json index f3531bdf7..e2889a0d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,7 @@ "eslint-plugin-jest": "^25.2.2", "eslint-plugin-vue": "^8.5.0", "eslint-webpack-plugin": "^3.1.1", + "jest-junit": "^13.0.0", "prettier": "^2.5.1" }, "engines": { @@ -11604,6 +11605,33 @@ "node": ">=8" } }, + "node_modules/jest-junit": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/jest-junit/-/jest-junit-13.0.0.tgz", + "integrity": "sha512-JSHR+Dhb32FGJaiKkqsB7AR3OqWKtldLd6ZH2+FJ8D4tsweb8Id8zEVReU4+OlrRO1ZluqJLQEETm+Q6/KilBg==", + "dev": true, + "dependencies": { + "mkdirp": "^1.0.4", + "strip-ansi": "^6.0.1", + "uuid": "^8.3.2", + "xml": "^1.0.1" + }, + "engines": { + "node": ">=10.12.0" + } + }, + "node_modules/jest-junit/node_modules/mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "dev": true, + "bin": { + "mkdirp": "bin/cmd.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/jest-leak-detector": { "version": "26.6.2", "resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-26.6.2.tgz", @@ -19831,6 +19859,12 @@ } } }, + "node_modules/xml": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz", + "integrity": "sha1-eLpyAgApxbyHuKgaPPzXS0ovweU=", + "dev": true + }, "node_modules/xml-name-validator": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz", @@ -28669,6 +28703,26 @@ } } }, + "jest-junit": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/jest-junit/-/jest-junit-13.0.0.tgz", + "integrity": "sha512-JSHR+Dhb32FGJaiKkqsB7AR3OqWKtldLd6ZH2+FJ8D4tsweb8Id8zEVReU4+OlrRO1ZluqJLQEETm+Q6/KilBg==", + "dev": true, + "requires": { + "mkdirp": "^1.0.4", + "strip-ansi": "^6.0.1", + "uuid": "^8.3.2", + "xml": "^1.0.1" + }, + "dependencies": { + "mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "dev": true + } + } + }, "jest-leak-detector": { "version": "26.6.2", "resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-26.6.2.tgz", @@ -34879,6 +34933,12 @@ "dev": true, "requires": {} }, + "xml": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz", + "integrity": "sha1-eLpyAgApxbyHuKgaPPzXS0ovweU=", + "dev": true + }, "xml-name-validator": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz", diff --git a/package.json b/package.json index 46ad4e919..b9a5c8e08 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "format": "prettier --write \"**/*.{js,vue,scss,html,md,json}\" --ignore-path .gitignore", "test": "echo \"See package.json => scripts for available tests.\" && exit 0", "test:unit": "jest --watchAll", - "test:unit:ci": "jest --ci", + "test:unit:ci": "jest --ci --reporters=default --reporters=jest-junit --maxWorkers=2", "test:unit:coverage": "jest --coverage", "serve:test:coverage": "quasar serve test/jest/coverage/lcov-report/ --port 8788", "concurrently:dev:jest": "concurrently \"quasar dev\" \"jest --watch\"", @@ -38,7 +38,8 @@ "eslint-plugin-jest": "^25.2.2", "eslint-plugin-vue": "^8.5.0", "eslint-webpack-plugin": "^3.1.1", - "prettier": "^2.5.1" + "prettier": "^2.5.1", + "jest-junit": "^13.0.0" }, "browserslist": [ "last 10 Chrome versions", @@ -56,4 +57,4 @@ "npm": ">= 6.13.4", "yarn": ">= 1.21.1" } -} +} \ No newline at end of file diff --git a/src/components/__tests__/UserPanel.spec.js b/src/components/__tests__/UserPanel.spec.js index 8778ffcec..dbf9ea3bd 100644 --- a/src/components/__tests__/UserPanel.spec.js +++ b/src/components/__tests__/UserPanel.spec.js @@ -1,5 +1,5 @@ import { describe, expect, it, jest } from '@jest/globals'; -import { createWrapper, axios, flushPromises } from 'app/test/jest/jestHelpers'; +import { createWrapper, axios, flushPromises } from 'app/tests/jest/jestHelpers'; import UserPanel from '../UserPanel.vue'; const mockPush = jest.fn(); diff --git a/src/pages/Login/__tests__/Login.spec.js b/src/pages/Login/__tests__/Login.spec.js index 11e5b5b83..1778a6002 100644 --- a/src/pages/Login/__tests__/Login.spec.js +++ b/src/pages/Login/__tests__/Login.spec.js @@ -1,5 +1,5 @@ import { jest, describe, expect, it, beforeAll } from '@jest/globals'; -import { createWrapper, axios } from 'app/test/jest/jestHelpers'; +import { createWrapper, axios } from 'app/tests/jest/jestHelpers'; import Login from '../Login.vue'; const mockPush = jest.fn(); diff --git a/test/cypress/.gitignore b/tests/cypress/.gitignore similarity index 100% rename from test/cypress/.gitignore rename to tests/cypress/.gitignore diff --git a/test/cypress/fixtures/example.json b/tests/cypress/fixtures/example.json similarity index 100% rename from test/cypress/fixtures/example.json rename to tests/cypress/fixtures/example.json diff --git a/test/cypress/integration/login.spec.js b/tests/cypress/integration/login.spec.js similarity index 100% rename from test/cypress/integration/login.spec.js rename to tests/cypress/integration/login.spec.js diff --git a/test/cypress/plugins/index.js b/tests/cypress/plugins/index.js similarity index 100% rename from test/cypress/plugins/index.js rename to tests/cypress/plugins/index.js diff --git a/test/cypress/support/commands.js b/tests/cypress/support/commands.js similarity index 100% rename from test/cypress/support/commands.js rename to tests/cypress/support/commands.js diff --git a/test/cypress/support/index.js b/tests/cypress/support/index.js similarity index 100% rename from test/cypress/support/index.js rename to tests/cypress/support/index.js diff --git a/test/cypress/support/unit.js b/tests/cypress/support/unit.js similarity index 100% rename from test/cypress/support/unit.js rename to tests/cypress/support/unit.js diff --git a/test/cypress/wrappers/DialogWrapper.vue b/tests/cypress/wrappers/DialogWrapper.vue similarity index 100% rename from test/cypress/wrappers/DialogWrapper.vue rename to tests/cypress/wrappers/DialogWrapper.vue diff --git a/test/cypress/wrappers/LayoutContainer.vue b/tests/cypress/wrappers/LayoutContainer.vue similarity index 100% rename from test/cypress/wrappers/LayoutContainer.vue rename to tests/cypress/wrappers/LayoutContainer.vue diff --git a/test/jest/.eslintrc.js b/tests/jest/.eslintrc.js similarity index 100% rename from test/jest/.eslintrc.js rename to tests/jest/.eslintrc.js diff --git a/test/jest/.gitignore b/tests/jest/.gitignore similarity index 100% rename from test/jest/.gitignore rename to tests/jest/.gitignore diff --git a/test/jest/jestHelpers.js b/tests/jest/jestHelpers.js similarity index 100% rename from test/jest/jestHelpers.js rename to tests/jest/jestHelpers.js