Skip to content

feat(gen) add Dockerfile and docker-compose.yml support #938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ module.exports = function (grunt) {
testing: 'jasmine',
auth: true,
oauth: ['googleAuth', 'twitterAuth'],
socketio: true
socketio: true,
docker: false
};

var deps = [
Expand Down
9 changes: 9 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,17 @@ var AngularFullstackGenerator = yeoman.generators.Base.extend({
return answers.odms && answers.odms.length !== 0;
},
default: true
}, {
type: 'confirm',
name: 'docker',
message: 'Would you like to include Docker support?',
when: function (answers) {
return answers.odms && answers.odms.length !== 0;
},
default: false
}], function (answers) {
if(answers.socketio) this.filters.socketio = true;
if(answers.docker) this.filters.docker = true;
if(answers.auth) this.filters.auth = true;
if(answers.odms && answers.odms.length > 0) {
var models;
Expand Down
2 changes: 2 additions & 0 deletions app/templates/.dockerignore(docker)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
node_modules
4 changes: 4 additions & 0 deletions app/templates/Dockerfile(docker)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Production Dockerfile - Used in the dist directory after grunt build
FROM node:0.12-onbuild
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be using Node < 4

ENV NODE_ENV production
EXPOSE 8080
5 changes: 4 additions & 1 deletion app/templates/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,10 @@ module.exports = function (grunt) {
}, {
expand: true,
dest: '<%%= yeoman.dist %>',
src: [
src: [<% if (filters.docker) { %>
'Dockerfile',
'.dockerignore',
'docker-compose.yml',<% } %>
'package.json',
'server/**/*'
]
Expand Down
13 changes: 13 additions & 0 deletions app/templates/docker-compose.yml(docker)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file works in the dist directory after grunt build is finished.
# Usage:
# pip install docker-compose
# docker-compose up
<% if (filters.mongoose) { %>
<%= _.slugify(appname) %>mongodb:
image: mongo:latest<% } %>
<%= _.slugify(appname) %>:
build: .
links:
- "<%= _.slugify(appname) %>mongodb:mongodb"
ports:
- "8080:8080"
6 changes: 5 additions & 1 deletion app/templates/server/config/environment/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ module.exports = {
uri: process.env.MONGOLAB_URI ||
process.env.MONGOHQ_URL ||
process.env.OPENSHIFT_MONGODB_DB_URL +
process.env.OPENSHIFT_APP_NAME ||
process.env.OPENSHIFT_APP_NAME ||<% if (filters.docker) { %>
(process.env.MONGODB_PORT_27017_TCP_ADDR ? 'mongodb://' +
process.env.MONGODB_PORT_27017_TCP_ADDR + ':' +
process.env.MONGODB_PORT_27017_TCP_PORT +
'/<%= _.slugify(appname) %>' : null) ||<% } %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's all this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is code to make the docker node container see the mongo container https://www.thachmai.info/2015/05/10/docker-container-linking-mongo-node/

'mongodb://localhost/<%= _.slugify(appname) %>'
}
};
17 changes: 15 additions & 2 deletions test/test-file-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ describe('angular-fullstack generator', function () {
odms: [ 'mongoose' ],
auth: true,
oauth: [],
socketio: true
socketio: true,
docker: false
}, dependenciesInstalled = false;

function copySync(s, d) { fs.writeFileSync(d, fs.readFileSync(s)); }
Expand Down Expand Up @@ -304,6 +305,15 @@ describe('angular-fullstack generator', function () {
]);
}

/* Docker support files */
if (ops.docker) {
files = files.concat([
'Dockerfile',
'.dockerignore',
'docker-compose.yml'
]);
}

return files;
}

Expand Down Expand Up @@ -502,6 +512,7 @@ describe('angular-fullstack generator', function () {
auth: true,
oauth: ['twitterAuth', 'facebookAuth', 'googleAuth'],
socketio: true,
docker: false,
bootstrap: true,
uibootstrap: true
};
Expand Down Expand Up @@ -574,6 +585,7 @@ describe('angular-fullstack generator', function () {
auth: true,
oauth: ['twitterAuth', 'facebookAuth', 'googleAuth'],
socketio: true,
docker: false,
bootstrap: true,
uibootstrap: true
};
Expand Down Expand Up @@ -647,6 +659,7 @@ describe('angular-fullstack generator', function () {
auth: false,
oauth: [],
socketio: false,
docker: false,
bootstrap: false,
uibootstrap: false
};
Expand Down Expand Up @@ -720,6 +733,7 @@ describe('angular-fullstack generator', function () {
auth: false,
oauth: [],
socketio: false,
docker: false,
bootstrap: true,
uibootstrap: true
};
Expand Down Expand Up @@ -767,7 +781,6 @@ describe('angular-fullstack generator', function () {
// runTest('grunt test:e2e:prod', this, done, 240000);
//});
}

});
});
});