Skip to content
This repository has been archived by the owner on Apr 21, 2020. It is now read-only.

Docker env #74

Merged
11 commits merged into from
Dec 12, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ $ Ignore the .env file for the server
*.log

dist

docker/data/
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ API for the Trust Ethereum Wallet.
## Deploy on Heroku
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://www.heroku.com/deploy/?template=https://github.com/TrustWallet/trust-wallet-backend)

## Locally
## Locally (without docker)
* Install required modules:
```$ npm install```
* Compile TypeScript:
Expand All @@ -40,6 +40,26 @@ API for the Trust Ethereum Wallet.
* Run tests:
```$ npm run build && npm test```

## Docker containers
Install docker and docker-compose.

Set in *~/.bashrc*
```export COMPOSE_FILE=docker-compose.yml:docker-compose.dev.yml```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to mount volumes and expose ports - yes.
You can export COMPOSE_FILE in your terminal before using ./trust build and ./trust run.


Dev tool:

* Run build for npm install and build
```./trust build```

* Start app in docker
```./trust run```

* Stop docker containers
```./trust stop```

* App logs
```./trust logs```

## Authors

* [Philipp Rieger](https://github.com/rip32700)
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.1'

services:

app:
volumes:
- ./:/opt/server
ports:
- 8000:8000

mongodb:
volumes:
- ./docker/data/mongodb:/data/db
ports:
- 27017:27017
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.1'

services:

app:
build: ./docker
env_file: .env
links:
- mongodb

mongodb:
image: mongo:latest
environment:
- MONGO_DATA_DIR=/data/db
7 changes: 7 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:6.12.1

COPY ./entrypoints /entrypoints

WORKDIR /opt/server

CMD /entrypoints/run
4 changes: 4 additions & 0 deletions docker/entrypoints/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -ex

npm start
59 changes: 59 additions & 0 deletions trust
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

set -e

build() {
echo "Building..."

docker-compose pull
docker-compose build

_in_docker app npm install
_in_docker app npm run build

if [ "$?" -ne 0 ]; then
echo "Failed build"
else
echo "Build OK"
fi
}

run() {
docker-compose up -d --remove-orphans $*
}

stop() {
docker-compose stop $*
}

logs() {
docker-compose logs -f app
}

_in_docker() {
service="$1"
cmd="${@:2}"

docker-compose run --rm --no-deps $service bash -c "sleep 0.1; $cmd"
}

help() {
echo -e "build Build npm modules"
echo -e "run Run docker containers"
echo -e "stop Stop docker containers"
echo -e "logs App logs"
}

main() {
declare cmd="$1"

case "$cmd" in
run) shift; run "$@";;
stop) shift; stop "$@";;
build) shift; build;;
logs) shift; logs;;
*) help "$@";;
esac
}

main "$@"