Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce docker-compose #166

Merged
merged 4 commits into from Dec 5, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -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 docker.md
@@ -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

@@ -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
@@ -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

This file was deleted.

This file was deleted.

This file was deleted.

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.