From 0ed7e5ee25b289ae719d46a660913be3a2caba76 Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Fri, 2 Mar 2018 13:08:48 +0100 Subject: [PATCH] Jenkins --- .env.json | 6 ++++ Jenkinsfile | 8 ++++- gulpfile.js | 25 +++++++++++----- package.json | 1 + services/db/03-changes.sh | 2 +- services/db/Dockerfile | 4 ++- services/loopback/server/datasources.json | 36 +++++++++++++---------- services/nginx/logs/error.log | 4 +++ 8 files changed, 60 insertions(+), 26 deletions(-) create mode 100644 .env.json create mode 100644 services/nginx/logs/error.log diff --git a/.env.json b/.env.json new file mode 100644 index 000000000..de4ba70f8 --- /dev/null +++ b/.env.json @@ -0,0 +1,6 @@ +{ + "salixHost": "localhost", + "salixPort": 3306, + "salixUser": "root", + "salixPassword": "" +} \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index d004f86bc..617a4f8f9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,10 +6,16 @@ def branchTest = "test"; env.BRANCH_NAME = branchName; env.TAG = "${env.BUILD_NUMBER}"; +env.salixUser="${env.salixUser}"; +env.salixPassword="${env.salixPassword}"; +env.salixHost = "${env.productionSalixHost}"; +env.salixPort = "${env.productionSalixPort}"; switch (branchName){ case branchTest: env.NODE_ENV = "test"; + env.salixHost = "${env.testSalixHost}"; + env.salixPort = "${env.testSalixPort}"; break; case branchProduction: env.DOCKER_HOST = "tcp://172.16.255.29:2375"; @@ -20,7 +26,7 @@ switch (branchName){ node { stage ('Print environment variables'){ - echo "Branch ${branchName}, Build ${env.TAG}, NODE_ENV ${env.NODE_ENV} en docker Host ${env.DOCKER_HOST}" + echo "Branch ${branchName}, Build ${env.TAG}, salixHost ${env.salixHost}, NODE_ENV ${env.NODE_ENV} en docker Host ${env.DOCKER_HOST}" } stage ('Checkout') { checkout scm diff --git a/gulpfile.js b/gulpfile.js index 303b15bc2..6fc495412 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,6 +1,7 @@ require('require-yaml'); const gulp = require('gulp'); const runSequence = require('run-sequence'); +const gulpEnv = require('gulp-env'); const fs = require('fs-extra'); const exec = require('child_process').exec; const PluginError = require('plugin-error'); @@ -27,6 +28,7 @@ let devServerPort = wpConfig.devServerPort; let nginxDir = `${servicesDir}/nginx`; let proxyConf = require(`${nginxDir}/config.yml`); let proxyEnvFile = `${nginxDir}/config.${env}.yml`; +let environmentFile = './.env.json'; if (fs.existsSync(proxyEnvFile)) Object.assign(proxyConf, require(proxyEnvFile)); @@ -37,18 +39,24 @@ let defaultPort = proxyConf.defaultPort; // Development gulp.task('default', () => { - return gulp.start('services', 'client'); + return gulp.start('environment', 'services', 'client'); }); gulp.task('client', ['build-clean'], async () => { await runSequenceP(['routes', 'locales'], 'watch', 'webpack-dev-server'); }); +gulp.task('environment', () => { + gulpEnv({ + file: environmentFile, + }); +}); + /** * Starts all backend services, including the nginx proxy and the database. */ gulp.task('services', async () => { - await runSequenceP('docker-start', 'services-only', 'nginx'); + await runSequenceP('environment', 'docker-start', 'services-only', 'nginx'); }); /** @@ -391,7 +399,7 @@ gulp.task('watch', function() { * Rebuilds the docker and it's image, if these already exist, destroys and * rebuilds them. */ -gulp.task('docker-rebuild', async () => { +gulp.task('docker-rebuild', ['environment'], async () => { try { await execP('docker rm -f dblocal'); } catch (e) {} @@ -434,10 +442,10 @@ gulp.task('docker-run', async () => { try { await execP('docker image inspect -f "{{json .Id}}" dblocal'); } catch (err) { - await execP('docker build -t dblocal:latest ./services/db'); + await execP(`docker build -t dblocal:latest --build-arg rootPassword=${process.env.salixPassword} ./services/db`); } - await execP('docker run -d --name dblocal -p 3306:3306 dblocal'); + await execP(`docker run -d --name dblocal -p ${process.env.salixPort}:${process.env.salixPort} dblocal`); await runSequenceP('docker-wait'); }); @@ -451,6 +459,7 @@ gulp.task('docker-wait', callback => { let elapsedTime = 0; let maxInterval = 30 * 60; + console.log('process', process.env.salixPassword); log('Waiting for MySQL init process...'); checker(); @@ -469,8 +478,10 @@ gulp.task('docker-wait', callback => { return callback(new Error('Docker exited, please see the docker logs for more info')); let conn = mysql.createConnection({ - host: 'localhost', - user: 'root' + host: process.env.salixHost, + port: process.env.salixPort, + user: process.env.salixUser, + password: process.env.salixPassword }); conn.on('error', () => {}); conn.connect(err => { diff --git a/package.json b/package.json index 059a1bedd..7b4c19023 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "file-loader": "^1.1.6", "gulp": "^3.9.1", "gulp-concat": "^2.6.0", + "gulp-env": "^0.4.0", "gulp-extend": "^0.2.0", "gulp-install": "^1.1.0", "gulp-jasmine": "^3.0.0", diff --git a/services/db/03-changes.sh b/services/db/03-changes.sh index 4e0d23d3a..c372568b2 100644 --- a/services/db/03-changes.sh +++ b/services/db/03-changes.sh @@ -2,5 +2,5 @@ for file in changes/*/*.sql; do echo "Importing $file" - mysql -u root < $file + mysql -u root -p$salixPassword < $file done diff --git a/services/db/Dockerfile b/services/db/Dockerfile index 1cc2b17eb..a9845f2e1 100644 --- a/services/db/Dockerfile +++ b/services/db/Dockerfile @@ -1,6 +1,8 @@ FROM mysql:5.6.37 -ENV MYSQL_ALLOW_EMPTY_PASSWORD yes +ARG rootPassword +ENV salixPassword $rootPassword +ENV MYSQL_ROOT_PASSWORD $salixPassword ENV TZ GMT-1 WORKDIR /docker-entrypoint-initdb.d diff --git a/services/loopback/server/datasources.json b/services/loopback/server/datasources.json index da7bcd44a..945c81966 100644 --- a/services/loopback/server/datasources.json +++ b/services/loopback/server/datasources.json @@ -1,37 +1,41 @@ { "db": { + "name": "db", "connector": "memory" }, "vn": { + "name": "mysql", "connector": "mysql", "database": "vn", "debug": false, - "host": "localhost", - "port": 3306, - "username": "root", - "password": "", + "host": "${salixHost}", + "port": "${salixPort}", + "username": "${salixUser}", + "password": "${salixPassword}", "connectTimeout": 20000, "acquireTimeout": 20000 }, "salix": { + "name": "mysql", "connector": "mysql", "database": "salix", "debug": false, - "host": "localhost", - "port": 3306, - "username": "root", - "password": "", + "host": "${salixHost}", + "port": "${salixPort}", + "username": "${salixUser}", + "password": "${salixPassword}", "connectTimeout": 20000, "acquireTimeout": 20000 }, "account": { + "name": "mysql", "connector": "mysql", "database": "account", "debug": false, - "host": "localhost", - "port": 3306, - "username": "root", - "password": "", + "host": "${salixHost}", + "port": "${salixPort}", + "username": "${salixUser}", + "password": "${salixPassword}", "connectTimeout": 20000, "acquireTimeout": 20000 }, @@ -39,10 +43,10 @@ "connector": "mysql", "database": "edi", "debug": false, - "host": "localhost", - "port": 3306, - "username": "root", - "password": "", + "host": "${salixHost}", + "port": "${salixPort}", + "username": "${salixUser}", + "password": "${salixPassword}", "connectTimeout": 20000, "acquireTimeout": 20000 } diff --git a/services/nginx/logs/error.log b/services/nginx/logs/error.log new file mode 100644 index 000000000..a8a0e2953 --- /dev/null +++ b/services/nginx/logs/error.log @@ -0,0 +1,4 @@ +2018/03/02 09:31:59 [notice] 7044#10044: signal process started +2018/03/02 09:31:59 [notice] 3892#15188: signal process started +2018/03/02 09:39:40 [notice] 8636#14980: signal process started +2018/03/02 12:40:36 [notice] 8340#13172: signal process started