From 4380ea595d98798722090191aaef18deb8ecc47d Mon Sep 17 00:00:00 2001 From: Ajay Ganapathy Date: Tue, 16 Feb 2016 19:59:49 -0500 Subject: [PATCH 01/14] Changed installation settings changed the generator that gets installed from webapp and angular to mcfly-ng2, exposed port 3000 instead of 9000, and also added gulp and bower to installed tools Signed-off-by: Ajay Ganapathy --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8ba10cc..6384f28 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,9 @@ RUN add-apt-repository ppa:chris-lea/node.js -y \ && apt-get -yq update \ && apt-get -yq install nodejs \ && npm install yo -g \ - && npm install -g generator-webapp generator-angular + && npm install -g generator-mcfly-ng2 \ + && npm install gulp \ + && npm install bower # Add a yeoman user because grunt doesn't like being root RUN adduser --disabled-password --gecos "" yeoman; \ echo "yeoman ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers @@ -18,6 +20,6 @@ ENV HOME /home/yeoman USER yeoman WORKDIR /home/yeoman # Expose the port -EXPOSE 9000 +EXPOSE 3000 # Always run as the yeoman user CMD ['/bin/bash'] From a0b86e19fda79734a5396fd78a388b4367fc5e99 Mon Sep 17 00:00:00 2001 From: Ajay Ganapathy Date: Tue, 16 Feb 2016 20:42:00 -0500 Subject: [PATCH 02/14] exposed home directory now, files from the host system will show up in the docker container's /home/yeoman Signed-off-by: Ajay Ganapathy --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 6384f28..baff056 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,6 +19,7 @@ RUN adduser --disabled-password --gecos "" yeoman; \ ENV HOME /home/yeoman USER yeoman WORKDIR /home/yeoman +VOLUME /home/yeoman # Expose the port EXPOSE 3000 # Always run as the yeoman user From ac75af4e54999e2ab70bb29ece314d8b78e5d86b Mon Sep 17 00:00:00 2001 From: Ajay Ganapathy Date: Wed, 17 Feb 2016 01:17:58 -0500 Subject: [PATCH 03/14] resolved permissions issues with non-root user gave non-root user "yeoman" the correct BASH shell and set permissions on the work directory. Signed-off-by: Ajay Ganapathy --- Dockerfile | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index baff056..ab8670d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,30 @@ # Yeoman with some generators and prerequisites -FROM ubuntu:saucy +FROM ubuntu:latest MAINTAINER Kevin Littlejohn RUN apt-get -yq update && apt-get -yq upgrade # Install pre-requisites RUN apt-get -yq install python-software-properties software-properties-common \ python g++ make git ruby-compass libfreetype6 # Install node.js, then npm install yo and the generators -RUN add-apt-repository ppa:chris-lea/node.js -y \ - && apt-get -yq update \ +RUN apt-get install -yq curl \ + && curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash - \ && apt-get -yq install nodejs \ + && apt-get -yq update \ && npm install yo -g \ && npm install -g generator-mcfly-ng2 \ && npm install gulp \ - && npm install bower + && npm install bower \ + && npm update # Add a yeoman user because grunt doesn't like being root -RUN adduser --disabled-password --gecos "" yeoman; \ +# RUN apt-get -yq install bash +RUN adduser --disabled-password --gecos "" --shell /bin/bash yeoman; \ echo "yeoman ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers ENV HOME /home/yeoman +RUN mkdir /home/yeoman/src && chmod -R 777 /home/yeoman/src +WORKDIR /home/yeoman/src +VOLUME /home/yeoman/src USER yeoman -WORKDIR /home/yeoman -VOLUME /home/yeoman # Expose the port EXPOSE 3000 # Always run as the yeoman user -CMD ['/bin/bash'] +CMD ["/bin/bash"] From e38dfba7add56f83df28c0a755ffea6ecee998db Mon Sep 17 00:00:00 2001 From: Ajay Ganapathy Date: Wed, 17 Feb 2016 19:59:45 -0500 Subject: [PATCH 04/14] fixed exposed port error generator-mcfly-ng2 uses port 5000 to serve the web app, not port 3000 Signed-off-by: Ajay Ganapathy --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ab8670d..40912a6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,6 +25,6 @@ WORKDIR /home/yeoman/src VOLUME /home/yeoman/src USER yeoman # Expose the port -EXPOSE 3000 +EXPOSE 5000 # Always run as the yeoman user CMD ["/bin/bash"] From 3b127786e959c7353663a0b86c084e8993863614 Mon Sep 17 00:00:00 2001 From: Ajay Ganapathy Date: Mon, 22 Feb 2016 12:31:43 -0500 Subject: [PATCH 05/14] fixed permissions issue with bower /usr directory now has RWX permissions for all users. This isn't a very secure solution, but it's a stopgap for now. Yeoman user can now run npm and install packages to /usr Signed-off-by: Ajay Ganapathy --- Dockerfile | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index ab8670d..e41beac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,31 @@ -# Yeoman with some generators and prerequisites +# Yeoman on ubuntu with pre-requisites FROM ubuntu:latest MAINTAINER Kevin Littlejohn RUN apt-get -yq update && apt-get -yq upgrade # Install pre-requisites -RUN apt-get -yq install python-software-properties software-properties-common \ - python g++ make git ruby-compass libfreetype6 +RUN apt-get -yq install python-software-properties \ + software-properties-common \ + python \ + g++ \ + make \ + git \ + ruby-compass \ + libfreetype6 # Install node.js, then npm install yo and the generators RUN apt-get install -yq curl \ && curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash - \ && apt-get -yq install nodejs \ && apt-get -yq update \ && npm install yo -g \ - && npm install -g generator-mcfly-ng2 \ - && npm install gulp \ - && npm install bower \ && npm update -# Add a yeoman user because grunt doesn't like being root +# Add a yeoman user because yeoman doesn't like being root # RUN apt-get -yq install bash RUN adduser --disabled-password --gecos "" --shell /bin/bash yeoman; \ echo "yeoman ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers ENV HOME /home/yeoman -RUN mkdir /home/yeoman/src && chmod -R 777 /home/yeoman/src +RUN mkdir /home/yeoman/src && chmod -R 777 /home/yeoman/src && chmod -R 777 /usr WORKDIR /home/yeoman/src VOLUME /home/yeoman/src USER yeoman -# Expose the port -EXPOSE 3000 # Always run as the yeoman user CMD ["/bin/bash"] From 6b059f8986892f276f877b1f4c3843b09dc10f46 Mon Sep 17 00:00:00 2001 From: Ajay Ganapathy Date: Tue, 23 Feb 2016 02:44:01 -0500 Subject: [PATCH 06/14] removed gulp generator-mcfly-ng2 does NOT use gulp. It uses webpack, so I removed gulp from the dockerfile Signed-off-by: Ajay Ganapathy --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 40912a6..0610434 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,6 @@ RUN apt-get install -yq curl \ && apt-get -yq update \ && npm install yo -g \ && npm install -g generator-mcfly-ng2 \ - && npm install gulp \ && npm install bower \ && npm update # Add a yeoman user because grunt doesn't like being root From 6042fcd5fc00cbddfd410c16048b72a672c39c98 Mon Sep 17 00:00:00 2001 From: Ajay Ganapathy Date: Thu, 25 Feb 2016 00:40:10 -0500 Subject: [PATCH 07/14] exposed browsersync UI port browsersync UI runs on port 3001, so I exposed the port to make it easy to configure it while it's running --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0610434..c78c3a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,7 +23,9 @@ RUN mkdir /home/yeoman/src && chmod -R 777 /home/yeoman/src WORKDIR /home/yeoman/src VOLUME /home/yeoman/src USER yeoman -# Expose the port +# Expose browsersync port EXPOSE 5000 +# Expose browsersync UI port +EXPOSE 3001 # Always run as the yeoman user CMD ["/bin/bash"] From ae726a5577d5d1e04a2f3d51c8b071133001f189 Mon Sep 17 00:00:00 2001 From: Ajay Ganapathy Date: Thu, 25 Feb 2016 02:21:30 -0500 Subject: [PATCH 08/14] installed generator-gulp-angular installed generator-gulp-angular, gulp, and bower. Then, exposed ports 3000 and 3001 for browsersync --- Dockerfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e41beac..997594d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,10 @@ RUN apt-get install -yq curl \ && curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash - \ && apt-get -yq install nodejs \ && apt-get -yq update \ - && npm install yo -g \ + && npm install -g yo \ + gulp \ + bower \ + generator-gulp-angular \ && npm update # Add a yeoman user because yeoman doesn't like being root # RUN apt-get -yq install bash @@ -27,5 +30,6 @@ RUN mkdir /home/yeoman/src && chmod -R 777 /home/yeoman/src && chmod -R 777 /usr WORKDIR /home/yeoman/src VOLUME /home/yeoman/src USER yeoman +EXPOSE 3000-3001 # Always run as the yeoman user CMD ["/bin/bash"] From 8e3a6345b8fad7a357141720438cf970825a4ce2 Mon Sep 17 00:00:00 2001 From: Ajay Ganapathy Date: Sun, 28 Feb 2016 20:33:14 -0500 Subject: [PATCH 09/14] fixed permissions vulnerability /usr is no longer accessible by any user. Instead, npm now installs global packages to the yeoman user's home directory --- Dockerfile | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 997594d..678771f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ -# Yeoman on ubuntu with pre-requisites +#Build an image that can run generator-gulp-angular FROM ubuntu:latest -MAINTAINER Kevin Littlejohn +MAINTAINER Ajay Ganapathy RUN apt-get -yq update && apt-get -yq upgrade +# # Install pre-requisites RUN apt-get -yq install python-software-properties \ software-properties-common \ @@ -9,9 +10,9 @@ RUN apt-get -yq install python-software-properties \ g++ \ make \ git \ - ruby-compass \ libfreetype6 -# Install node.js, then npm install yo and the generators +# +# Install node.js, yo, gulp, bower, and generator-gulp-angular RUN apt-get install -yq curl \ && curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash - \ && apt-get -yq install nodejs \ @@ -21,15 +22,25 @@ RUN apt-get install -yq curl \ bower \ generator-gulp-angular \ && npm update +# # Add a yeoman user because yeoman doesn't like being root -# RUN apt-get -yq install bash RUN adduser --disabled-password --gecos "" --shell /bin/bash yeoman; \ echo "yeoman ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers ENV HOME /home/yeoman -RUN mkdir /home/yeoman/src && chmod -R 777 /home/yeoman/src && chmod -R 777 /usr -WORKDIR /home/yeoman/src -VOLUME /home/yeoman/src +# +# set up a directory that will hold the files we sync from the host machine +RUN mkdir /home/yeoman/senior-studio-site \ + # set up a directory for global npm packages that does not require root access + && mkdir /home/yeoman/.npm_global \ + && chmod -R 777 /home/yeoman +# && chmod -R 777 /usr +ENV NPM_CONFIG_PREFIX /home/yeoman/.npm_global +WORKDIR /home/yeoman/senior-studio-site +VOLUME /home/yeoman/senior-studio-site +# +# allow the host machine to access browsersync on the guest machine +EXPOSE 9000 +# +# drop to yeoman user and a bash shell USER yeoman -EXPOSE 3000-3001 -# Always run as the yeoman user CMD ["/bin/bash"] From e2a2f09c67129024364a4522acc6cffd73ec0587 Mon Sep 17 00:00:00 2001 From: Ajay Ganapathy Date: Sun, 28 Feb 2016 21:01:16 -0500 Subject: [PATCH 10/14] exposed browsersync un-exposed port 9000, and exposed ports 3000 and 3001 since that's where the generator set up browsersync to serve --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 678771f..20401f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,13 +33,12 @@ RUN mkdir /home/yeoman/senior-studio-site \ # set up a directory for global npm packages that does not require root access && mkdir /home/yeoman/.npm_global \ && chmod -R 777 /home/yeoman -# && chmod -R 777 /usr ENV NPM_CONFIG_PREFIX /home/yeoman/.npm_global WORKDIR /home/yeoman/senior-studio-site VOLUME /home/yeoman/senior-studio-site # # allow the host machine to access browsersync on the guest machine -EXPOSE 9000 +EXPOSE 3000-3001 # # drop to yeoman user and a bash shell USER yeoman From 5f437f147e95666fd10b0b4908e62cb603d13fec Mon Sep 17 00:00:00 2001 From: Ajay Ganapathy Date: Tue, 8 Mar 2016 13:03:03 -0500 Subject: [PATCH 11/14] Updated README the README for this generator now includes all of the instructions you will need to set up this docker box. --- README.md | 79 +++++++++++++++++++------------------------------------ 1 file changed, 27 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index a9c0a56..8f653d5 100644 --- a/README.md +++ b/README.md @@ -1,59 +1,34 @@ -## yeoman - - -**Dockerfile** for base yeoman install, with a few generators pre-installed. - +# Dockerized-Yeoman +This dockerfile builds a container with [yeoman](http://yeoman.io), [generator-gulp-angular](https://github.com/swiip/generator-gulp-angular#readme). I wrote this dockerfile because yeoman does not run as the root, and default docker containers run executables as root. This means that if you spin up a docker container and then try to run yeoman, [it will fail](https://github.com/yeoman/yeoman.github.io/issues/282). ### Installation - -1. Install [Docker](https://www.docker.io/). - -2. `docker run -i -t silarsis/yeoman` - - (alternatively, build from github: `docker build -t="silarsis/yeoman" github.com/silarsis/yeoman`) +1. [Set up Docker on Mac OS X.](https://docs.docker.com/mac/ "Docker for Mac Quick Start") +2. Open the Docker CLI from within Kitematic ![Cursor pressing the ‘docker CLI’ button in the lower-left-hand corner of the kitematic window](https://i.imgur.com/quKAxcG.gif) +3. Then change the directory to the `yeoman-docker` folder in this project's root: +```shell +cd ~/my-repository/yeoman-docker +``` +Replace `my-repository` with project's root. This folder should contain a file named `dockerfile`. + +4. Build the docker image with the following command: + ```shell + docker build . + ``` + The output of this command should look like [this](https://asciinema.org/a/36633). +5. Once the docker image has built, run it: + ```shell + docker run -dit my-image-hash + ``` + Replace `my-image-hash` with the unique identifier that docker gave to your image after building it e.g. [`fa817ac6674d`](https://asciinema.org/a/36633?t=10&autoplay=0). ### Usage -`docker run -i -t silarsis/yeoman` - -This will run the container and log you in as the "yeoman" user, ready to "yo". - -`docker run -i -t silarsis/yeoman -c grunt serve` - -This will run the grunt server inside the container. - -### Notes - -"sudo" works - if you need root, `sudo -s` will get you there. - -The default grunt port (9000) is exposed by default. - -Docker hints: - - - `docker start -a -i ` will restart a stopped container and re-attach you to the bash process - - `docker inspect -format '{{ .NetworkSettings.IPAddress }}' ` will give you the IP address of the currently running container - - `docker run -P -i -t silarsis/yeoman` will map port 9000 to a port on the host, and `docker port 9000` will show you what port that ends up on - -This Dockerfile should provide a good base image for development work - as an example, based on the [Docker Node.js example](http://docs.docker.io/en/latest/examples/nodejs_web_app/), you could have a Dockerfile that looks like (**untested**, assumes your code is in the same directory as your Dockerfile): - -``` - FROM silarsis/yeoman - MAINTAINER Kevin Littlejohn "kevin@littlejohn.id.au" - ADD . /src - RUN cd /src; npm install - EXPOSE 9000 - USER yeoman - CMD ["grunt", "serve"] +1. Sync your project's root folder to the docker container's shared volume with Kitematic ![Cursor switching to the docker container’s ‘settings’ tab, then selecting the ‘volumes’ sub-tab, and finally pressing the ‘change’ button next to the volume to connect](https://i.imgur.com/tdJd9qV.gif) +2. Shell into the docker container. ![Cursor pressing the ‘exec’ button in kitematic](https://i.imgur.com/krIbsQg.gif) +3. serve the site with the following command: +```shell +gulp serve ``` +4. Find the IP Address to which the site is being served in kitematic, and enter it into your browser’s URL bar to navigate to the running site. ![`gulp serve` command entered into the docker container shell, followed by cursor switching to the ‘settings’ tab and ‘ports’ sub-tab before hovering over the IP address listed under ‘configure ports’ ](https://i.imgur.com/uT14x81.gif) -and run with `docker build -t /yeoman-dev .`; `docker run -P -d /yeoman-dev` - - -In application source, put in Gruntfile.js hostname:0.0.0.0 for expose port 9000 on the host for any IP: - connect: { - options: { - port: 9000, - // Change this to '0.0.0.0' to access the server from outside. - hostname: '0.0.0.0', - livereload: 35729 - }, +### Notes \ No newline at end of file From c12d3bc6a0ee6169ff7ee2d05fd1797cae6ee530 Mon Sep 17 00:00:00 2001 From: Ajay Ganapathy Date: Tue, 8 Mar 2016 22:10:44 -0500 Subject: [PATCH 12/14] Updated README the readme was missing instructions for mapping the ports on the docker container to the host, so I added those instructions in, and included a helpful .gif Signed-off-by: Ajay Ganapathy --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8f653d5..7b9f50c 100644 --- a/README.md +++ b/README.md @@ -23,12 +23,17 @@ Replace `my-repository` with project's root. This folder should contain a file n ### Usage 1. Sync your project's root folder to the docker container's shared volume with Kitematic ![Cursor switching to the docker container’s ‘settings’ tab, then selecting the ‘volumes’ sub-tab, and finally pressing the ‘change’ button next to the volume to connect](https://i.imgur.com/tdJd9qV.gif) -2. Shell into the docker container. ![Cursor pressing the ‘exec’ button in kitematic](https://i.imgur.com/krIbsQg.gif) +2. Map the docker container ports to the docker host. In this docker container, ports `3000` and `3001` are exposed. Port `3000` is where browser sync serves the site, and port `3001` is where it serves its own control panel. To keep things simple, you might want to map the port on the docker container to the same port number in Kitematic, *i.e.* port `3000` on the docker container maps to the IP address and port `192.168.99.100:3000` in Kitematic, and port `3001` maps to `192.168.99.100:3001`. However, if those ports are already mapped to another application, such as a MongoDB server or docker container, you can map them to whatever available ports you have.![Cursor selecting docker container, then ‘settings’ tab, then ‘ports’ sub-tab, then entering port numbers 3000 and 3001 in the text input fields underneath the ‘MAC IP:PORT’ header](https://i.imgur.com/r2cv7zE.gif) +3. Shell into the docker container. ![Cursor pressing the ‘exec’ button in kitematic](https://i.imgur.com/krIbsQg.gif) 3. serve the site with the following command: ```shell gulp serve ``` 4. Find the IP Address to which the site is being served in kitematic, and enter it into your browser’s URL bar to navigate to the running site. ![`gulp serve` command entered into the docker container shell, followed by cursor switching to the ‘settings’ tab and ‘ports’ sub-tab before hovering over the IP address listed under ‘configure ports’ ](https://i.imgur.com/uT14x81.gif) +### Roadmap +This is not a full-fledged project with semantic versioning. However, I might add the following features later if it is convenient for me: +- bash completions +- automatically run `npm install && bower install` on container startup as yeoman user, before dropping to a shell. -### Notes \ No newline at end of file +> If you take the time to add these features, just send me a PR and I’ll merge them in! \ No newline at end of file From 5d249d1fa344de7b72856f2189e92f968ae77a11 Mon Sep 17 00:00:00 2001 From: Ajay Ganapathy Date: Sun, 1 May 2016 21:06:15 -0400 Subject: [PATCH 13/14] Changed the source image Source image ubuntu:latest failed upon building, so I changed the image to ubuntu:trusty. ubuntu:trusty is officially supported by node js Signed-off-by: Ajay Ganapathy --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 20401f9..c4b4f10 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ #Build an image that can run generator-gulp-angular -FROM ubuntu:latest +FROM ubuntu:trusty MAINTAINER Ajay Ganapathy RUN apt-get -yq update && apt-get -yq upgrade # From a0532fd10f398764da56a78d9c0a7def031e68ea Mon Sep 17 00:00:00 2001 From: Ajay Ganapathy Date: Mon, 30 May 2016 18:10:09 -0400 Subject: [PATCH 14/14] added modernizr the container now comes with modernizr pre-installed Signed-off-by: Ajay Ganapathy --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index c4b4f10..42d5ff8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,6 +21,7 @@ RUN apt-get install -yq curl \ gulp \ bower \ generator-gulp-angular \ + modernizr \ && npm update # # Add a yeoman user because yeoman doesn't like being root