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

Commit e7c2d4d

Browse files
Merge pull request #148 from Human-Connection/fix-docker-setup
Fix docker setup
2 parents 5992bbb + 7cabe76 commit e7c2d4d

9 files changed

+162
-51
lines changed

Dockerfile

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
1-
FROM node:8.9-alpine
1+
FROM node:alpine
22
LABEL Description="This image is used to start the hc-api-feathers" Vendor="Human-Connection gGmbH" Version="1.0" Maintainer="Human-Connection gGmbH ([email protected])"
33

4-
# update unix packages
5-
RUN apk update && apk upgrade
6-
RUN rm -rf /var/cache/apk/*
7-
RUN yarn global add pm2
8-
94
# expose the app port
105
EXPOSE 3030
116

12-
# set environment variables
13-
# ENV NPM_CONFIG_PRODUCTION=false
14-
# ENV HOST=0.0.0.0
7+
# override configuration by instance name in docker container
8+
ENV NODE_APP_INSTANCE=docker
159
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
2510

2611
# create working directory
27-
RUN mkdir -p /var/www/
28-
WORKDIR /var/www/
12+
RUN mkdir -p /API
13+
WORKDIR /API
14+
15+
# --no-cache: download package index on-the-fly, no need to cleanup afterwards
16+
# --virtual: bundle packages, remove whole bundle at once, when done
17+
RUN apk --no-cache --virtual build-dependencies add python make g++
18+
19+
RUN yarn global add pm2
2920

3021
# install app dependencies
31-
COPY package.json /var/www/
32-
COPY yarn.lock /var/www/
33-
RUN yarn install --frozen-lockfile --non-interactive
22+
COPY package.json /API
23+
COPY yarn.lock /API
24+
RUN yarn install --production=false --frozen-lockfile --non-interactive
25+
26+
RUN apk del build-dependencies
27+
3428

3529
# copy the code to the docker image
36-
COPY . /var/www/
30+
COPY . /API
31+
32+
# start the application in a autohealing cluster
33+
# NOTE: quick fix for server issues, restart api when reaching max of 300 MB Memory Usage (happens in conjunction with 100% CPU Usage)
34+
# TODO: find better way of dealing with that issue
35+
CMD ["pm2", "start", "server/index.js", "-n", "api", "--attach", "--max-memory-restart", "1024M"]

README.md

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,49 @@ 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+
#### Local Staging Environment
43+
44+
To get an environment which is close to production, run the following:
45+
```sh
46+
$ docker-compose -f docker-compose.yml -f docker-compose.staging.yml up --build
47+
```
48+
49+
### Testing in Docker
50+
51+
Run the entire test suite with:
52+
```bash
53+
$ docker-compose run --rm api yarn run test
54+
```
55+
56+
If you want you can run specific tests:
57+
```bash
58+
$ docker-compose run --rm api yarn run mocha
59+
$ docker-compose run --rm api yarn run cucumber
60+
```
61+
62+
2063
## Local installation
2164

2265
> we recommand to install the project locally for the best development ease and performance
@@ -91,19 +134,8 @@ Getting up and running is as easy as 1, 2, 3, 4 ... 5.
91134
Now, your API should be running at [http://localhost:3030](http://localhost:3030).
92135
If you seeded your database, you will see some contributions at [http://localhost:3030/contributions](http://localhost:3030/contributions).
93136

94-
7. Setup and Start Thumbnail Service (optional)
95-
96-
We are using [Thumbor](https://github.com/thumbor/thumbor) as a Thumbnail Microservice.
97-
You can install it locally if you like but this is totally optional.
98-
99-
**Install OR use docker**
100-
101-
- At first you have to [install](http://thumbor.readthedocs.io/en/latest/installing.html) it locally and start it in the console with `thumbor` **OR** run it with docker `docker run -p 8000:8000 apsl/thumbor`
102-
- Set the `thumbor.url` in `config/local.json` to `http://localhost:8888` (with docker `http://localhost:8000`) if not defined differently. The `thumbor.key` does not necessarily have to be defined, it just makes the URL more secure.
103-
104-
> Do not forget to always start it if you choose that setup or otherwise you will not see any pictures at all.
105137

106-
### Local configuration
138+
### Local Configuration
107139

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

122154
```
123155

124-
## Testing
156+
### Local Testing
125157

126158
Run the entire test suite with:
127159
```bash

config/default-docker.json

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

config/local-staging-docker.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"baseURL": "http://172.25.0.11:3030",
3+
"seeder": {
4+
"runOnInit": true,
5+
"dropDatabase": true
6+
},
7+
"smtpConfig": {
8+
"host": "maildev",
9+
"port": 25,
10+
"ignoreTLS": true
11+
},
12+
"thumbor": {
13+
"url": "http://localhost:8000",
14+
"key": ""
15+
}
16+
}

config/test-docker.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+
}

docker-compose.override.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3'
2+
3+
services:
4+
api:
5+
environment:
6+
- NODE_ENV=development
7+
ports:
8+
- "3030:3030"
9+
- "9229:9229" # node inspect
10+
volumes:
11+
- .:/API
12+
- /API/node_modules
13+
command: yarn run dev

docker-compose.staging.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: '3'
2+
3+
services:
4+
api:
5+
image: humanconnection/api-feathers
6+
build:
7+
context: .
8+
environment:
9+
- NODE_ENV=staging
10+
depends_on:
11+
- maildev
12+
- thumbor
13+
ports:
14+
- "3030:3030"
15+
networks:
16+
hc-network:
17+
ipv4_address: 172.25.0.11
18+
thumbor:
19+
networks:
20+
hc-network:
21+
ipv4_address: 172.25.0.13
22+
maildev:
23+
image: djfarrelly/maildev
24+
networks:
25+
- hc-network
26+
ports:
27+
- "1080:80"
28+
- "1025:25"
29+
thumbor:
30+
image: apsl/thumbor
31+
networks:
32+
- hc-network
33+
ports:
34+
- "8000:8000"
35+
36+
networks:
37+
hc-network:
38+
driver: bridge
39+
ipam:
40+
driver: default
41+
config:
42+
-
43+
subnet: 172.25.0.0/16

docker-compose.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
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: .
11-
ports:
12-
- "3030:3030"
13-
links:
14-
- mongo-cluster
15-
environment:
16-
PORT: 3030
6+
depends_on:
7+
- mongo
8+
networks:
9+
- hc-network
10+
mongo:
11+
image: mongo
12+
networks:
13+
- hc-network
14+
command: "--smallfiles --logpath=/dev/null"
15+
16+
networks:
17+
hc-network:

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
"scripts": {
3636
"ci": "yarn run eslint && yarn run test:coverage",
37-
"clear": "rm -Rf tmp",
37+
"clean": "rm -Rf tmp",
3838
"mongo": "mongod --dbpath data --quiet",
3939
"mongo:win": "mongod --dbpath /data/db --quiet",
4040
"test": "yarn run mocha && yarn run cucumber",
@@ -43,7 +43,7 @@
4343
"start": "node server/",
4444
"dev": "cross-env DEBUG=feathers* nodemon server/",
4545
"dev:debug": "cross-env DEBUG=feathers* nodemon --inspect=0.0.0.0:9229 server/",
46-
"mocha": "yarn run clear && cross-env NODE_ENV=test mocha --recursive --timeout 10000 --exit",
46+
"mocha": "yarn run clean && cross-env NODE_ENV=test mocha --recursive --timeout 10000 --exit",
4747
"cucumber": "concurrently --kill-others --success first 'cross-env NODE_ENV=test node server/' 'wait-on tcp:3031 && cross-env NODE_ENV=test cucumber-js'"
4848
},
4949
"dependencies": {

0 commit comments

Comments
 (0)