Skip to content
Merged
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
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3.2'
services:
place-my-order-api:
build:
context: .
dockerfile: Dockerfile-api
ports:
- "7070:7070"
expose:
- 7070

place-my-order:
build: .
ports:
- "8080:8080"
expose:
- 8080
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
104 changes: 78 additions & 26 deletions docker.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,57 @@
# PMO Docker

Wrapping PMO in Docker.
Wrapping PMO in Docker with docker-compose

Sections:
- [Benefits](#benefits)
- [Prerequisites](#prerequisites)
- [Dockerfiles](#dockerfiles)
- [Building Docker](#building-docker)
- [Running the app](#running-the-app)
- [Developing the app](#developing-the-app)
- [References](#references)

## Benefits

### Environment Parity
If you're using microservices deployed with a container orchestrator like Kubernetes, docker-compose is a great way of locally emulating the communiction between microservices.

### No host dependencies
No need to install various dependencies on your host machine (node, databases, etc).

In fact, maintaining the mindset of "I don't have anything on my machine except for a text editor and docker", it'll be very helpful in ensuring that your microservices are easily deployable.

### Onboarding
New developers can get started more easily than following a set of steps to get their local environment set up. It should be as simple as:
```
git clone https://github.com/donejs/place-my-order.git
cd place-my-order
docker-compose up
```
Visit http://localhost:8080



## Prerequisites

- Docker
- [Docker](https://www.docker.com/products/docker-desktop)


## Quick Start
```
git clone https://github.com/donejs/place-my-order.git
cd place-my-order
docker-compose up
```
Visit http://localhost:8080

## Dockerfiles

We'll specify 3 `Dockerfile`s:

- `Dockerfile` - UI
- `Dockerfile-api` - API
- `Dockerfile-ci` - CI (tests, etc)
- `Dockerfile-ci` - CI (tests, etc) - TODO

### Dockerfile

Expand Down Expand Up @@ -78,44 +111,63 @@ CMD [ "donejs", "api" ]

### Dockerfile-ci

This dockerfile will run CI things (tests, build & tag, etc).
TODO

Only tests implemented currently:
## Building Docker

Build both the api (`Dockerfile-api`) and the ui (`Dockerfile`) containers:
```
docker-compose build
```
FROM node:10.0

# Create app directory
WORKDIR /usr/src/app

# get files
COPY . .

# install dependencies
RUN npm install donejs -g
RUN npm install
## Running the app

# run the tests
RUN donejs test
```
docker-compose up
```

## Building Docker
> **Note:** You can also rebuild the app prior to running via `docker-compose up --build`

## Stopping the app

Build both the api (`Dockerfile-api`) and the ui (`Dockerfile`) containers:
```
./scripts-docker/build
docker-compose down
```

## Running the app
## Developing the app

Run both the api (`Dockerfile-api`) and the ui (`Dockerfile`) containers:
### Mounting the repo into the container
The repo files are bound from the host to the container with volumes.
The `volumes` section of the `place-my-order` service in `docker-compose.yml`:
```
./scripts-docker/run
services:
place-my-order:
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
```

## Stopping the app
- `.:/usr/src/app` shares the current working directory on the host (where `docker-compose` is executed) to `/usr/src/app` in the container.
- `/usr/src/app` is defined in the Dockerfile via the `WORKDIR` directive
- `/usr/src/app/node_modules` - This will mount the node_modules directory to the host machine using the buildtime directory.
- [More info](https://jdlm.info/articles/2016/03/06/lessons-building-node-app-docker.html#the-node_modules-volume-trick)

With this approach, the following will be true:
- `node_modules` will be available within the container
- Changes to app code will be reflected within the running container

Stop both the api (`Dockerfile-api`) and the ui (`Dockerfile`) containers:
### Running scripts

Sometimes it's necessary to execute scripts against the running services.
This can be achieved using `docker-compose run <service-name> <script>`.

For example, say a new dependency is required for the `place-my-order` defined in `docker-compose.yml`. It can be added like this:
```
./scripts-docker/stop
docker-compose run place-my-order npm install jsdoc --save
```


## References
- https://blog.codeship.com/using-docker-compose-for-nodejs-development/
- https://jdlm.info/articles/2016/03/06/lessons-building-node-app-docker.html#the-node_modules-volume-trick
- https://stackoverflow.com/questions/30043872/docker-compose-node-modules-not-present-in-a-volume-after-npm-install-succeeds
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ npm install donejs -g
npm install
```

### Docker

To develop with Docker, see the [Docker guide](./docker.md)

## Running tests

Tests can be run with
Expand Down
12 changes: 0 additions & 12 deletions scripts-docker/build

This file was deleted.

22 changes: 0 additions & 22 deletions scripts-docker/run

This file was deleted.

15 changes: 0 additions & 15 deletions scripts-docker/stop

This file was deleted.