From 72df7c9af15e8e800b4c42981f5c17efc1385502 Mon Sep 17 00:00:00 2001 From: olsynt Date: Fri, 14 Oct 2016 17:20:29 +0300 Subject: [PATCH] * Added dockerignore file to ignore node_modules * Created gulp task to run docker with mongo service --- .dockerignore | 1 + Dockerfile | 8 ++++---- docker-compose.yml | 2 +- gulpfile.babel.js | 28 ++++++++++++++++++++++++++++ server/app.js | 2 +- server/config/local.env.docker.js | 3 +++ server/config/local.env.sample.js | 2 +- 7 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 .dockerignore create mode 100644 server/config/local.env.docker.js diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8d87b1d --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules/* diff --git a/Dockerfile b/Dockerfile index 899f32a..06b221e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,12 +6,12 @@ RUN apt-get install -y nodejs nodejs-legacy npm RUN apt-get clean RUN npm install -g npm RUN npm install --global gulp -COPY ./package.json /src/ -RUN cd src && npm install +COPY ./package.json /src/ +RUN cd /src && npm install COPY . /src -WORKDIR src/ +WORKDIR /src/ -CMD ["gulp", "serve"] +CMD ["gulp", "serve:docker"] diff --git a/docker-compose.yml b/docker-compose.yml index 03080a5..190a1e3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,6 +4,6 @@ services: build: . image: web ports: - - 3000:3000 + - 3001:3000 mongo: image: mongo diff --git a/gulpfile.babel.js b/gulpfile.babel.js index af41517..f102f0b 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -173,6 +173,17 @@ gulp.task('env:all', () => { vars: localConfig }); }); +gulp.task('env:docker', () => { + let localConfig; + try { + localConfig = require(`./${serverPath}/config/local.env.docker`); + } catch (e) { + localConfig = {}; + } + plugins.env({ + vars: localConfig + }); +}); gulp.task('env:test', () => { plugins.env({ vars: {NODE_ENV: 'test'} @@ -350,6 +361,23 @@ gulp.task('serve', cb => { ); }); +gulp.task('serve:docker', cb => { + runSequence( + [ + 'clean:tmp', + 'lint:scripts', + 'inject', + 'copy:fonts:dev', + 'env:all', + 'env:docker' + ], + // 'webpack:dev', + ['start:server', 'start:client'], + 'watch', + cb + ); +}); + gulp.task('serve:debug', cb => { runSequence( [ diff --git a/server/app.js b/server/app.js index 634d48c..521f770 100644 --- a/server/app.js +++ b/server/app.js @@ -11,7 +11,7 @@ import config from './config/environment'; import http from 'http'; // Connect to MongoDB -mongoose.connect('mongo', config.mongo.options); +mongoose.connect(config.mongo.uri, config.mongo.options); mongoose.connection.on('error', function(err) { console.log("test"); console.error('MongoDB connection error: ' + err , config.mongo.uri); diff --git a/server/config/local.env.docker.js b/server/config/local.env.docker.js new file mode 100644 index 0000000..5d15e44 --- /dev/null +++ b/server/config/local.env.docker.js @@ -0,0 +1,3 @@ +module.exports = { + MONGO_DOCKER: 'mongo' +} diff --git a/server/config/local.env.sample.js b/server/config/local.env.sample.js index b8abb24..d88f4fb 100644 --- a/server/config/local.env.sample.js +++ b/server/config/local.env.sample.js @@ -8,7 +8,7 @@ module.exports = { DOMAIN: 'http://localhost:9000', SESSION_SECRET: 'b7beet-secret', - + // Control debug level for modules using visionmedia/debug DEBUG: '' };