Skip to content

Commit b5a629e

Browse files
committed
feat(gen) add Dockerfile and docker-compose.yml support
Add support to run generated Angular-Fullstack applications as Docker containers by including Dockerfile, docker-compose.yml and .dockerignore. When the application is built with grunt build, these files are copied to the dist directory. The Docker container can then be built and started there with the "docker-compose up" command. When Mongoose is used, Docker Compose will also launch a MongoDB container, eliminating the need to install MongoDB on the local machine. Note that Docker and Docker Compose must be installed for Docker support to work. They are available on Linux, OS X and Windows.
1 parent 4f4543e commit b5a629e

File tree

8 files changed

+54
-5
lines changed

8 files changed

+54
-5
lines changed

Gruntfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ module.exports = function (grunt) {
160160
testing: 'jasmine',
161161
auth: true,
162162
oauth: ['googleAuth', 'twitterAuth'],
163-
socketio: true
163+
socketio: true,
164+
docker: false
164165
};
165166

166167
var deps = [

app/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,17 @@ var AngularFullstackGenerator = yeoman.generators.Base.extend({
212212
return answers.odms && answers.odms.length !== 0;
213213
},
214214
default: true
215+
}, {
216+
type: 'confirm',
217+
name: 'docker',
218+
message: 'Would you like to include Docker support?',
219+
when: function (answers) {
220+
return answers.odms && answers.odms.length !== 0;
221+
},
222+
default: false
215223
}], function (answers) {
216224
if(answers.socketio) this.filters.socketio = true;
225+
if(answers.docker) this.filters.docker = true;
217226
if(answers.auth) this.filters.auth = true;
218227
if(answers.odms && answers.odms.length > 0) {
219228
var models;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
node_modules

app/templates/Dockerfile(docker)

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Production Dockerfile - Used in the dist directory after grunt build
2+
FROM node:0.12-onbuild
3+
ENV NODE_ENV production
4+
EXPOSE 8080

app/templates/Gruntfile.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,10 @@ module.exports = function (grunt) {
391391
}, {
392392
expand: true,
393393
dest: '<%%= yeoman.dist %>',
394-
src: [
394+
src: [<% if (filters.docker) { %>
395+
'Dockerfile',
396+
'.dockerignore',
397+
'docker-compose.yml',<% } %>
395398
'package.json',
396399
'server/**/*'
397400
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This file works in the dist directory after grunt build is finished.
2+
# Usage:
3+
# pip install docker-compose
4+
# docker-compose up
5+
<% if (filters.mongoose) { %>
6+
<%= _.slugify(appname) %>mongodb:
7+
image: mongo:latest<% } %>
8+
<%= _.slugify(appname) %>:
9+
build: .
10+
links:
11+
- "<%= _.slugify(appname) %>mongodb:mongodb"
12+
ports:
13+
- "8080:8080"

app/templates/server/config/environment/production.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ module.exports = {
1818
uri: process.env.MONGOLAB_URI ||
1919
process.env.MONGOHQ_URL ||
2020
process.env.OPENSHIFT_MONGODB_DB_URL +
21-
process.env.OPENSHIFT_APP_NAME ||
21+
process.env.OPENSHIFT_APP_NAME ||<% if (filters.docker) { %>
22+
(process.env.MONGODB_PORT_27017_TCP_ADDR ? 'mongodb://' +
23+
process.env.MONGODB_PORT_27017_TCP_ADDR + ':' +
24+
process.env.MONGODB_PORT_27017_TCP_PORT +
25+
'/<%= _.slugify(appname) %>' : null) ||<% } %>
2226
'mongodb://localhost/<%= _.slugify(appname) %>'
2327
}
2428
};

test/test-file-creation.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ describe('angular-fullstack generator', function () {
2222
odms: [ 'mongoose' ],
2323
auth: true,
2424
oauth: [],
25-
socketio: true
25+
socketio: true,
26+
docker: false
2627
}, dependenciesInstalled = false;
2728

2829
function copySync(s, d) { fs.writeFileSync(d, fs.readFileSync(s)); }
@@ -304,6 +305,15 @@ describe('angular-fullstack generator', function () {
304305
]);
305306
}
306307

308+
/* Docker support files */
309+
if (ops.docker) {
310+
files = files.concat([
311+
'Dockerfile',
312+
'.dockerignore',
313+
'docker-compose.yml'
314+
]);
315+
}
316+
307317
return files;
308318
}
309319

@@ -502,6 +512,7 @@ describe('angular-fullstack generator', function () {
502512
auth: true,
503513
oauth: ['twitterAuth', 'facebookAuth', 'googleAuth'],
504514
socketio: true,
515+
docker: false,
505516
bootstrap: true,
506517
uibootstrap: true
507518
};
@@ -574,6 +585,7 @@ describe('angular-fullstack generator', function () {
574585
auth: true,
575586
oauth: ['twitterAuth', 'facebookAuth', 'googleAuth'],
576587
socketio: true,
588+
docker: false,
577589
bootstrap: true,
578590
uibootstrap: true
579591
};
@@ -647,6 +659,7 @@ describe('angular-fullstack generator', function () {
647659
auth: false,
648660
oauth: [],
649661
socketio: false,
662+
docker: false,
650663
bootstrap: false,
651664
uibootstrap: false
652665
};
@@ -720,6 +733,7 @@ describe('angular-fullstack generator', function () {
720733
auth: false,
721734
oauth: [],
722735
socketio: false,
736+
docker: false,
723737
bootstrap: true,
724738
uibootstrap: true
725739
};
@@ -767,7 +781,6 @@ describe('angular-fullstack generator', function () {
767781
// runTest('grunt test:e2e:prod', this, done, 240000);
768782
//});
769783
}
770-
771784
});
772785
});
773786
});

0 commit comments

Comments
 (0)