Skip to content
Open
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
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get -y upgrade
RUN apt-get -y install git build-essential wget

# Prep the repo for NodeJS 11 (latest) rather than 10 (LTS)
RUN curl -sL https://deb.nodesource.com/setup_11.x | bash -
RUN apt-get install -y nodejs npm

# Bump up from npm 3 to 5.
RUN npm install -g npm@5

###
### Install our initial set of packages by temporarily pulling in the current state of the project.
###

## Guarantee the environment is dev, not prod.
#RUN npm config set -g production false
## Temporarily copy over a snapshot of the code.
#COPY * /usr/local/pp-pigpen-snapshot/
## Remove local node module cache.
#RUN rm -rf /usr/local/pp-pigpen-snapshot/node_modules
## Install all modules globally. “Globally” is a misnomer here, in that they install in-place, then get
## symlinks in /usr/local/lib to here, for some weird reason.
#RUN cd /usr/local/pp-pigpen-snapshot ; npm install -g
## Force-install dev, because that doesn't seem to install correctly, despite being not-prod?
#RUN cd /usr/local/pp-pigpen-snapshot ; npm install -g --only=dev

# Install Angular CLI.
RUN npm install -g @angular/cli
RUN npm link @angular/cli

# Define mount point for project from host. We'll map the live code folder to this at runtime.
VOLUME /pp-pigpen
# Define home directory.
WORKDIR /pp-pigpen
# Define web server port
EXPOSE 4200
40 changes: 40 additions & 0 deletions doc/Docker_Development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Docker Development

(placeholder doc)

## Theory of Operation

The Docker container gives a standalone runtime development environment, regardless of host OS. (Caveat: I've only tested this on under macOS.) Anything that would need to be installed globally — namely Node and npm — live inside the container, so as not to pollute your host OS. The webapp and its local dependencies live outside the container, bridged in to the Node runtimes. The Angular network port is also bridged across.

- The container is running a pared down version of the latest Ubuntu LTS.
- Node and NPM live inside the container. They're pinned to the appropriate versions.
- The webapp lives outside the container, mounted into it.
- All node modules are installed locally in the webapp, and therefore persist/cache in the `node_modules` folder outside the container. They're not blown away when the ephemeral container stops.

## Check Out the Code

- Obtain the project by cloning the github repo.
- If you were previously doing things in your local copy of the repository, ensure you don't have local cached node_modules from a previous run: `rm -rf node_modules; mkdir node_modules`

## Build the Development Environment

```
docker build -t pp-pigpen-dev .
```

This gives you a minimal Ubuntu, build tools, nodejs, and npm.

## Use the Development Environment

Interactive, with a Bash prompt:

```
docker run --rm --network=host -p 4200:4200 -v `pwd`:/pp-pigpen -it pp-pigpen-dev /bin/bash
```

This mounts the current directory (your local clone of `pp-pigpen`) to the folder `/pp-pigpen` inside the container. Any modifications you make in the host OS will be seen within the running container. Any modifications you make inside the running container will modify the files in the host OS.

At this point, you should run `npm install` to install all of the required packages. These will install in your clone of `pp-pigpen/node_modules`. Take note that if the architecture of your host operating system is different from what's running in Docker (Mac, Windows), then these modules may not work for you if used outside of the Docker container.

Next run `ng serve --host 0.0.0.0` to start the Angular server.