Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit 8e50c18

Browse files
committed
Setup docker for local development and debugging
Write README
1 parent 4fe0986 commit 8e50c18

File tree

6 files changed

+81
-32
lines changed

6 files changed

+81
-32
lines changed

Dockerfile

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,21 @@ RUN apk update && apk upgrade
66
RUN rm -rf /var/cache/apk/*
77
RUN yarn global add pm2
88

9-
# expose the app port
10-
EXPOSE 3030
11-
12-
# set environment variables
13-
# ENV NPM_CONFIG_PRODUCTION=false
14-
# ENV HOST=0.0.0.0
15-
ENV NODE_ENV=production
16-
ENV API_PORT=3030
17-
18-
# start the application in a autohealing cluster
19-
# NOTE: quick fix for server issues, restart api when reaching max of 300 MB Memory Usage (happens in conjunction with 100% CPU Usage)
20-
# TODO: find better way of dealing with that issue
21-
CMD NODE_ENV=production pm2 start server/index.js -n api --attach --max-memory-restart 1024M
22-
# CMD NODE_ENV=production pm2 start server/index.js -n api -i 2 --attach
23-
# as we have issues with pm2 currently in conjunction with nuxt, we use the standard approach here
24-
# CMD NODE_ENV=production node server/index.js
25-
269
# create working directory
27-
RUN mkdir -p /var/www/
28-
WORKDIR /var/www/
10+
RUN mkdir -p /API
11+
WORKDIR /API
2912

3013
# install app dependencies
31-
COPY package.json /var/www/
32-
COPY yarn.lock /var/www/
14+
COPY package.json /API
15+
COPY yarn.lock /API
3316
RUN yarn install --frozen-lockfile --non-interactive
3417

3518
# copy the code to the docker image
36-
COPY . /var/www/
19+
COPY . /API
20+
21+
# setup local configuration
22+
COPY ./config/docker/* /API/config/
23+
24+
# expose the app port
25+
EXPOSE 3030
26+
EXPOSE 9229

README.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,42 @@ The API for a better world. More information under [human-connection.org](https:
1717

1818
> **Note:** This is only the API part of Human-Connection, you have to also checkout the [WebApp](https://github.com/Human-Connection/WebApp) which uses this API.
1919
20+
## Installation via docker
21+
22+
Make sure you have a recent version of [docker](https://www.docker.com/) and [docker-compose](https://docs.docker.com/compose/).
23+
24+
Run:
25+
```bash
26+
$ docker-compose up --build
27+
```
28+
Now, your API should be running at [http://localhost:3030](http://localhost:3030)
29+
and you can see some contributions at [http://localhost:3030/contributions](http://localhost:3030/contributions).
30+
31+
For debugging you can run:
32+
```bash
33+
$ docker-compose run --rm --service-ports api yarn run dev:debug
34+
```
35+
And debug your app with [Chrome Dev Tools](chrome://inspect).
36+
37+
### Configuration in Docker
38+
39+
Change configuration in `config/docker/local-development.json` or
40+
`config/docker/local.json` and rerun `docker-compose up --build`.
41+
42+
### Testing in Docker
43+
44+
Run the entire test suite with:
45+
```bash
46+
$ docker-compose run --rm api yarn run test
47+
```
48+
49+
If you want you can run specific tests:
50+
```bash
51+
$ docker-compose run --rm api yarn run mocha
52+
$ docker-compose run --rm api yarn run cucumber
53+
```
54+
55+
2056
## Local installation
2157

2258
> we recommand to install the project locally for the best development ease and performance
@@ -103,7 +139,7 @@ Getting up and running is as easy as 1, 2, 3, 4 ... 5.
103139

104140
> Do not forget to always start it if you choose that setup or otherwise you will not see any pictures at all.
105141
106-
### Local configuration
142+
### Local Configuration
107143

108144
You can override any default configuration in `config/local.json`. You can find
109145
a list of availabe defaults in `config/default.json`.
@@ -121,7 +157,7 @@ replace `localhost` in your settings with your IP address in the local network:
121157

122158
```
123159

124-
## Testing
160+
### Local Testing
125161

126162
Run the entire test suite with:
127163
```bash

config/docker/local-development.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"mongodb": "mongodb://mongo:27017/hc_api",
3+
"seeder": {
4+
"runOnInit": true,
5+
"dropDatabase": false
6+
}
7+
}

config/docker/local-test.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mongodb": "mongodb://mongo:27017/hc_api_test"
3+
}

config/docker/local.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"host": "0.0.0.0",
3+
"smtpConfig": {
4+
"host": "maildev",
5+
"port": 25,
6+
"ignoreTLS": true
7+
}
8+
}

docker-compose.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
version: '2'
1+
version: '3'
22

33
services:
4-
mongo-cluster:
5-
image: mongo
6-
ports:
7-
- "27017:27017"
8-
command: "--smallfiles --logpath=/dev/null"
94
api:
105
build: .
116
ports:
127
- "3030:3030"
8+
- "9229:9229" # node inspect
139
links:
14-
- mongo-cluster
10+
- mongo
1511
environment:
16-
PORT: 3030
12+
- NODE_ENV=development
13+
command: yarn run dev
14+
mongo:
15+
image: mongo
16+
command: "--smallfiles --logpath=/dev/null"
17+
maildev:
18+
image: djfarrelly/maildev
19+
ports:
20+
- "1080:80"
21+
- "1025:25"

0 commit comments

Comments
 (0)