From a68b58888061584b532fe153b309270626a21e6c Mon Sep 17 00:00:00 2001 From: Matthias Luebken Date: Wed, 18 Jun 2014 15:59:24 +0200 Subject: [PATCH 01/10] first docker version with fig --- Dockerfile | 25 +++++++++++++++++++++++++ README.md | 11 +++++++++++ config/env/development.js | 4 +++- fig.yml | 10 ++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 fig.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..e45610cc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# +# Note "> /dev/null" workaround for fig-bug https://github.com/orchardup/fig/issues/239 +# +FROM dockerfile/nodejs + +MAINTAINER Matthias Luebken, matthias@catalyst-zero.com + +WORKDIR /home/mean + +# Install Mean.JS Prerequisites +RUN npm install -g grunt-cli > /dev/null +RUN npm install -g bower > /dev/null + +# Install Mean.JS packages +ADD package.json /home/mean/package.json +RUN npm install > /dev/null + +# Make everything available for start +ADD . /home/mean + +# currently only works for development +ENV NODE_ENV development + +EXPOSE 3000 +CMD ["grunt"] \ No newline at end of file diff --git a/README.md b/README.md index 05ac4b3b..b8687e63 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,17 @@ Your application should run on the 3000 port so in your browser just go to [http That's it! your application should be running by now, to proceed with your development check the other sections in this documentation. If you encounter any problem try the Troubleshooting section. +## Development and deployment With Docker + +* Install [Docker](http://www.docker.com/) +* Install [Fig](https://github.com/orchardup/fig) + +* For local development and testing: +``` +$ fig up +``` + + ## Getting Started With MEAN.JS You have your application running but there are a lot of stuff to understand, we recommend you'll go over the [Offical Documentation](http://meanjs.org/docs.html). In the docs we'll try to explain both general concepts of MEAN components and give you some guidelines to help you improve your development procees. We tried covering as many aspects as possible, and will keep update it by your request, you can also help us develop the documentation better by checking out the *gh-pages* branch of this repository. diff --git a/config/env/development.js b/config/env/development.js index 17470972..8f1c18b7 100644 --- a/config/env/development.js +++ b/config/env/development.js @@ -1,7 +1,9 @@ 'use strict'; +var DB_HOST = process.env.DB_1_PORT_27017_TCP_ADDR || 'localhost'; + module.exports = { - db: 'mongodb://localhost/mean-dev', + db: 'mongodb://' + DB_HOST + '/mean-dev', app: { title: 'MEAN.JS - Development Environment' }, diff --git a/fig.yml b/fig.yml new file mode 100644 index 00000000..08a4c26c --- /dev/null +++ b/fig.yml @@ -0,0 +1,10 @@ +web: + build: . + links: + - db + ports: + - "3000:3000" +db: + image: mongo + ports: + - "27017:27017" \ No newline at end of file From 04e74f20fedc4f9e84ad1fc4ed30faa39c892e95 Mon Sep 17 00:00:00 2001 From: Matthias Luebken Date: Wed, 18 Jun 2014 18:34:25 +0200 Subject: [PATCH 02/10] workaround manual bower install --- Dockerfile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e45610cc..3b926054 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,12 @@ RUN npm install -g bower > /dev/null # Install Mean.JS packages ADD package.json /home/mean/package.json -RUN npm install > /dev/null +RUN npm install + +ADD .bowerrc /home/mean/.bowerrc +ADD bower.json /home/mean/bower.json +# why doesnt this work via npm install? +RUN bower install --config.interactive=false --allow-root # Make everything available for start ADD . /home/mean From 9b81e3f98388b48d8afcc358483d833f48511ec8 Mon Sep 17 00:00:00 2001 From: Matthias Luebken Date: Wed, 18 Jun 2014 18:34:42 +0200 Subject: [PATCH 03/10] manual docker build and run --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b8687e63..cfe73da3 100644 --- a/README.md +++ b/README.md @@ -82,11 +82,19 @@ If you encounter any problem try the Troubleshooting section. * Install [Docker](http://www.docker.com/) * Install [Fig](https://github.com/orchardup/fig) -* For local development and testing: +* Local development and testing with fig: ``` $ fig up ``` +* Local development and testing with just Docker: +``` +$ docker build -t mean . +$ docker run -p 27017:27017 -d --name db mongo +$ docker run -p 3000:3000 --link db:db_1 mean +$ +``` + ## Getting Started With MEAN.JS You have your application running but there are a lot of stuff to understand, we recommend you'll go over the [Offical Documentation](http://meanjs.org/docs.html). From c62e1c1e4e1b0d9ee06412c50a8e3d068c9be08a Mon Sep 17 00:00:00 2001 From: Matthias Luebken Date: Wed, 18 Jun 2014 18:40:15 +0200 Subject: [PATCH 04/10] fig bug workaround --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3b926054..770bfe1a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ RUN npm install -g bower > /dev/null # Install Mean.JS packages ADD package.json /home/mean/package.json -RUN npm install +RUN npm install > /dev/null ADD .bowerrc /home/mean/.bowerrc ADD bower.json /home/mean/bower.json From c93abfeae7a8102e861c3cd353ab756ccdc68bd3 Mon Sep 17 00:00:00 2001 From: Matthias Luebken Date: Wed, 18 Jun 2014 18:47:08 +0200 Subject: [PATCH 05/10] workaround fig bug --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 770bfe1a..5e44a830 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,7 @@ RUN npm install > /dev/null ADD .bowerrc /home/mean/.bowerrc ADD bower.json /home/mean/bower.json # why doesnt this work via npm install? -RUN bower install --config.interactive=false --allow-root +RUN bower install --config.interactive=false --allow-root > /dev/null # Make everything available for start ADD . /home/mean From 7257f2e3c1b5e710a5ef00d7dad0e03c5dab25b0 Mon Sep 17 00:00:00 2001 From: Matthias Luebken Date: Fri, 20 Jun 2014 10:57:47 +0200 Subject: [PATCH 06/10] removed fig workaround --- Dockerfile | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5e44a830..edc61692 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,3 @@ -# -# Note "> /dev/null" workaround for fig-bug https://github.com/orchardup/fig/issues/239 -# FROM dockerfile/nodejs MAINTAINER Matthias Luebken, matthias@catalyst-zero.com @@ -8,17 +5,17 @@ MAINTAINER Matthias Luebken, matthias@catalyst-zero.com WORKDIR /home/mean # Install Mean.JS Prerequisites -RUN npm install -g grunt-cli > /dev/null -RUN npm install -g bower > /dev/null +RUN npm install -g grunt-cli +RUN npm install -g bower # Install Mean.JS packages ADD package.json /home/mean/package.json -RUN npm install > /dev/null +RUN npm install +# Manually trigger bower. Why doesnt this work via npm install? ADD .bowerrc /home/mean/.bowerrc ADD bower.json /home/mean/bower.json -# why doesnt this work via npm install? -RUN bower install --config.interactive=false --allow-root > /dev/null +RUN bower install --config.interactive=false --allow-root # Make everything available for start ADD . /home/mean From 0cbb6c5902f46fd53300689797952e1aa27f0982 Mon Sep 17 00:00:00 2001 From: Matthias Luebken Date: Tue, 24 Jun 2014 14:44:17 +0200 Subject: [PATCH 07/10] how to enable live reload --- Dockerfile | 4 +++- README.md | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index edc61692..96dc98b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,5 +23,7 @@ ADD . /home/mean # currently only works for development ENV NODE_ENV development -EXPOSE 3000 +# Port 3000 for server +# Port 35729 for livereload +EXPOSE 3000 35729 CMD ["grunt"] \ No newline at end of file diff --git a/README.md b/README.md index cfe73da3..dec285d1 100644 --- a/README.md +++ b/README.md @@ -83,18 +83,22 @@ If you encounter any problem try the Troubleshooting section. * Install [Fig](https://github.com/orchardup/fig) * Local development and testing with fig: -``` +```bash $ fig up ``` * Local development and testing with just Docker: -``` +```bash $ docker build -t mean . $ docker run -p 27017:27017 -d --name db mongo $ docker run -p 3000:3000 --link db:db_1 mean $ ``` +* To enable live reload forward 35729 port and mount /app and /public as volumes: +```bash +$ docker run -p 3000:3000 -p 35729:35729 -v /Users/mdl/workspace/mean-stack/mean/public:/home/mean/public -v /Users/mdl/workspa/mean-stack/mean/app:/home/mean/app --link db:db_1 mean +``` ## Getting Started With MEAN.JS You have your application running but there are a lot of stuff to understand, we recommend you'll go over the [Offical Documentation](http://meanjs.org/docs.html). From 1bd958e40de2498243785bf7d6fcc06b184c260d Mon Sep 17 00:00:00 2001 From: Matthias Luebken Date: Thu, 3 Jul 2014 09:50:29 +0200 Subject: [PATCH 08/10] env --- fig.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fig.yml b/fig.yml index 08a4c26c..ba9a926b 100644 --- a/fig.yml +++ b/fig.yml @@ -4,6 +4,8 @@ web: - db ports: - "3000:3000" + environment: + NODE_ENV: production db: image: mongo ports: From 83686b82d9a126374d3a36f3bb97a511bc11ef85 Mon Sep 17 00:00:00 2001 From: Matthias Luebken Date: Thu, 3 Jul 2014 10:04:11 +0200 Subject: [PATCH 09/10] - reading the right port in production - changed default back to development --- config/env/production.js | 4 +++- fig.yml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/config/env/production.js b/config/env/production.js index 26c97d77..2de715fe 100644 --- a/config/env/production.js +++ b/config/env/production.js @@ -1,7 +1,9 @@ 'use strict'; +var DB_HOST = process.env.DB_1_PORT_27017_TCP_ADDR || 'localhost'; + module.exports = { - db: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://localhost/mean', + db: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://' + DB_HOST + '/mean', assets: { lib: { css: [ diff --git a/fig.yml b/fig.yml index ba9a926b..4726a151 100644 --- a/fig.yml +++ b/fig.yml @@ -5,7 +5,7 @@ web: ports: - "3000:3000" environment: - NODE_ENV: production + NODE_ENV: development db: image: mongo ports: From c918f933203c76a96919238df46b1ebea28a7ae5 Mon Sep 17 00:00:00 2001 From: Matthias Luebken Date: Thu, 3 Jul 2014 14:52:25 +0200 Subject: [PATCH 10/10] checking for Env injected by fig/docker --- config/env/test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/env/test.js b/config/env/test.js index cc3f0aa4..03135e6c 100644 --- a/config/env/test.js +++ b/config/env/test.js @@ -1,7 +1,9 @@ 'use strict'; +var DB_HOST = process.env.DB_1_PORT_27017_TCP_ADDR || 'localhost'; + module.exports = { - db: 'mongodb://localhost/mean-test', + db: 'mongodb://' + DB_HOST + '/mean-test', port: 3001, app: { title: 'MEAN.JS - Test Environment'