-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
45 lines (38 loc) · 1.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var fs = require('fs');
module.exports = function(path) {
var pkg_path = path + '/package.json', path;
// Try to read package.json
try {
pkg = require(pkg_path);
} catch (e) {
throw new Error('Can\'t read package.json.');
}
// Default optional keys in pkg root
pkg.config = pkg.config || {};
pkg.scripts = pkg.scripts || {};
// Build options
var opt = {
port: pkg.config.port || 8080,
command: {
'start': pkg.scripts.start || '/usr/bin/node /var/service/app.js'
}
};
var dockerfile = [
'FROM ubuntu:precise',
'MAINTAINER node-dockgen',
'RUN apt-get update',
'RUN apt-get install -y python-software-properties python',
'RUN add-apt-repository ppa:chris-lea/node.js',
'RUN echo "deb http://us.archive.ubuntu.com/ubuntu/ precise universe" >> /etc/apt/sources.list',
'RUN apt-get update',
'RUN apt-get install -y nodejs',
'RUN mkdir /var/service',
'EXPOSE ' + opt.port,
'ENV PORT ' + opt.port,
'ADD ./ /var/service/',
'WORKDIR /var/service/',
'RUN cd /var/service/; npm install --unsafe-perm',
'CMD ' + 'PORT=' + opt.port + ' ' + opt.command.start
];
return(dockerfile.join('\n'));
};