Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.
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
47 changes: 23 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
FROM node:8.9-alpine
FROM node:alpine
LABEL Description="This image is used to start the hc-api-feathers" Vendor="Human-Connection gGmbH" Version="1.0" Maintainer="Human-Connection gGmbH (developer@human-connection.org)"

# update unix packages
RUN apk update && apk upgrade
RUN rm -rf /var/cache/apk/*
RUN yarn global add pm2

# expose the app port
EXPOSE 3030

# set environment variables
# ENV NPM_CONFIG_PRODUCTION=false
# ENV HOST=0.0.0.0
# override configuration by instance name in docker container
ENV NODE_APP_INSTANCE=docker
ENV NODE_ENV=production
ENV API_PORT=3030

# start the application in a autohealing cluster
# NOTE: quick fix for server issues, restart api when reaching max of 300 MB Memory Usage (happens in conjunction with 100% CPU Usage)
# TODO: find better way of dealing with that issue
CMD NODE_ENV=production pm2 start server/index.js -n api --attach --max-memory-restart 1024M
# CMD NODE_ENV=production pm2 start server/index.js -n api -i 2 --attach
# as we have issues with pm2 currently in conjunction with nuxt, we use the standard approach here
# CMD NODE_ENV=production node server/index.js

# create working directory
RUN mkdir -p /var/www/
WORKDIR /var/www/
RUN mkdir -p /API
WORKDIR /API

# --no-cache: download package index on-the-fly, no need to cleanup afterwards
# --virtual: bundle packages, remove whole bundle at once, when done
RUN apk --no-cache --virtual build-dependencies add python make g++

RUN yarn global add pm2

# install app dependencies
COPY package.json /var/www/
COPY yarn.lock /var/www/
RUN yarn install --frozen-lockfile --non-interactive
COPY package.json /API
COPY yarn.lock /API
RUN yarn install --production=false --frozen-lockfile --non-interactive

RUN apk del build-dependencies


# copy the code to the docker image
COPY . /var/www/
COPY . /API

# start the application in a autohealing cluster
# NOTE: quick fix for server issues, restart api when reaching max of 300 MB Memory Usage (happens in conjunction with 100% CPU Usage)
# TODO: find better way of dealing with that issue
CMD ["pm2", "start", "server/index.js", "-n", "api", "--attach", "--max-memory-restart", "1024M"]
58 changes: 45 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,49 @@ The API for a better world. More information under [human-connection.org](https:

> **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.

## Installation via docker

Make sure you have a recent version of [docker](https://www.docker.com/) and [docker-compose](https://docs.docker.com/compose/).

Run:
```bash
$ docker-compose up --build
```
Now, your API should be running at [http://localhost:3030](http://localhost:3030)
and you can see some contributions at [http://localhost:3030/contributions](http://localhost:3030/contributions).

For debugging you can run:
```bash
$ docker-compose run --rm --service-ports api yarn run dev:debug
```
And debug your app with [Chrome Dev Tools](chrome://inspect).

### Configuration in Docker

Change configuration in `config/docker/local-development.json` or
`config/docker/local.json` and rerun `docker-compose up --build`.

#### Local Staging Environment

To get an environment which is close to production, run the following:
```sh
$ docker-compose -f docker-compose.yml -f docker-compose.staging.yml up --build
```

### Testing in Docker

Run the entire test suite with:
```bash
$ docker-compose run --rm api yarn run test
```

If you want you can run specific tests:
```bash
$ docker-compose run --rm api yarn run mocha
$ docker-compose run --rm api yarn run cucumber
```


## Local installation

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

7. Setup and Start Thumbnail Service (optional)

We are using [Thumbor](https://github.com/thumbor/thumbor) as a Thumbnail Microservice.
You can install it locally if you like but this is totally optional.

**Install OR use docker**

- 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`
- 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.

> Do not forget to always start it if you choose that setup or otherwise you will not see any pictures at all.

### Local configuration
### Local Configuration

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

```

## Testing
### Local Testing

Run the entire test suite with:
```bash
Expand Down
4 changes: 4 additions & 0 deletions config/default-docker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"mongodb": "mongodb://mongo:27017/hc_api",
"host": "0.0.0.0"
}
16 changes: 16 additions & 0 deletions config/local-staging-docker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"baseURL": "http://172.25.0.11:3030",
"seeder": {
"runOnInit": true,
"dropDatabase": true
},
"smtpConfig": {
"host": "maildev",
"port": 25,
"ignoreTLS": true
},
"thumbor": {
"url": "http://localhost:8000",
"key": ""
}
}
3 changes: 3 additions & 0 deletions config/test-docker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"mongodb": "mongodb://mongo:27017/hc_api_test"
}
13 changes: 13 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3'

services:
api:
environment:
- NODE_ENV=development
ports:
- "3030:3030"
- "9229:9229" # node inspect
volumes:
- .:/API
- /API/node_modules
command: yarn run dev
43 changes: 43 additions & 0 deletions docker-compose.staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: '3'

services:
api:
image: humanconnection/api-feathers
build:
context: .
environment:
- NODE_ENV=staging
depends_on:
- maildev
- thumbor
ports:
- "3030:3030"
networks:
hc-network:
ipv4_address: 172.25.0.11
thumbor:
networks:
hc-network:
ipv4_address: 172.25.0.13
maildev:
image: djfarrelly/maildev
networks:
- hc-network
ports:
- "1080:80"
- "1025:25"
thumbor:
image: apsl/thumbor
networks:
- hc-network
ports:
- "8000:8000"

networks:
hc-network:
driver: bridge
ipam:
driver: default
config:
-
subnet: 172.25.0.0/16
25 changes: 13 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
version: '2'
version: '3'

services:
mongo-cluster:
image: mongo
ports:
- "27017:27017"
command: "--smallfiles --logpath=/dev/null"
api:
build: .
ports:
- "3030:3030"
links:
- mongo-cluster
environment:
PORT: 3030
depends_on:
- mongo
networks:
- hc-network
mongo:
image: mongo
networks:
- hc-network
command: "--smallfiles --logpath=/dev/null"

networks:
hc-network:
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"scripts": {
"ci": "yarn run eslint && yarn run test:coverage",
"clear": "rm -Rf tmp",
"clean": "rm -Rf tmp",
"mongo": "mongod --dbpath data --quiet",
"mongo:win": "mongod --dbpath /data/db --quiet",
"test": "yarn run mocha && yarn run cucumber",
Expand All @@ -43,7 +43,7 @@
"start": "node server/",
"dev": "cross-env DEBUG=feathers* nodemon server/",
"dev:debug": "cross-env DEBUG=feathers* nodemon --inspect=0.0.0.0:9229 server/",
"mocha": "yarn run clear && cross-env NODE_ENV=test mocha --recursive --timeout 10000 --exit",
"mocha": "yarn run clean && cross-env NODE_ENV=test mocha --recursive --timeout 10000 --exit",
"cucumber": "concurrently --kill-others --success first 'cross-env NODE_ENV=test node server/' 'wait-on tcp:3031 && cross-env NODE_ENV=test cucumber-js'"
},
"dependencies": {
Expand Down