From 46e8aa518db06d5271ce5d3251273c820ed4a7ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Tr=C3=A9panier?= Date: Mon, 10 Jul 2017 15:36:27 -0400 Subject: [PATCH] Rethinkdb (#85) * Fixed EACCES exception thrown when install node packages * Added compose override file for 2 node example * Updated .gitignore to only remove root override file * Added RethinkDB --- .gitignore | 2 +- README.md | 1 + _examples/2-nodes/docker-compose.override.yml | 17 ++++++++++++++ _examples/rethinkdb/README.md | 23 +++++++++++++++++++ _examples/rethinkdb/index.js | 21 +++++++++++++++++ _examples/rethinkdb/package.json | 15 ++++++++++++ docker-compose.yml | 11 +++++++++ node/Dockerfile | 3 +++ node/scripts/run-nodock.sh | 2 +- rethinkdb/Dockerfile | 3 +++ 10 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 _examples/2-nodes/docker-compose.override.yml create mode 100755 _examples/rethinkdb/README.md create mode 100755 _examples/rethinkdb/index.js create mode 100644 _examples/rethinkdb/package.json create mode 100644 rethinkdb/Dockerfile diff --git a/.gitignore b/.gitignore index 675d566..b1fa533 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,4 @@ jspm_packages # Project Specific data -docker-compose.override.yml +./docker-compose.override.yml diff --git a/README.md b/README.md index 13457f4..b78d76b 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ We provide examples of configurations you might use for a specific stack. Each e * [Mongo](https://github.com/Osedea/nodock/tree/master/_examples/mongo) - MongoDB + Node + NGINX * [RabbitMQ](https://github.com/Osedea/nodock/tree/master/_examples/rabbitmq) - RabbitMQ + Node + NGINX * [Memcached](https://github.com/Osedea/nodock/tree/master/_examples/memcached) - Memcached + Node + NGINX +* [RethinkDB](https://github.com/Osedea/nodock/tree/master/_examples/rethinkdb) - RethinkDB + Node + NGINX * [2 Node Apps](https://github.com/Osedea/nodock/tree/master/_examples/2-nodes) - Node + Node + NGINX diff --git a/_examples/2-nodes/docker-compose.override.yml b/_examples/2-nodes/docker-compose.override.yml new file mode 100644 index 0000000..2d8eb22 --- /dev/null +++ b/_examples/2-nodes/docker-compose.override.yml @@ -0,0 +1,17 @@ +# docker-compose.override.yml + +version: '2' + +services: + node2: # name of new container + extends: node # extends the settings from the "node" container + build: + context: ./node + args: + - PROJECT_PATH=second-app + entrypoint: run-nodock "node index.js" # the entrypoint for the "node2" container + nginx: + ports: + - "10000:10000" # the port(s) to forward for the "node2" container + links: + - node2 # link "nginx" to "node2" \ No newline at end of file diff --git a/_examples/rethinkdb/README.md b/_examples/rethinkdb/README.md new file mode 100755 index 0000000..0155f8e --- /dev/null +++ b/_examples/rethinkdb/README.md @@ -0,0 +1,23 @@ +## RethinkDB Service + +### Setup + +Copy the index file in this folder to the project root: + +```bash +cd / + +cp -r nodock/_examples/rethinkdb/* . +``` + +### Usage + +```bash +cd nodock/ + +docker-compose up -d node rethinkdb nginx +``` + +By going to `127.0.0.1` in your browser you should be seeing a nice greeting! + +You can access the RethinkDB GUI via `127.0.0.1:28080`. diff --git a/_examples/rethinkdb/index.js b/_examples/rethinkdb/index.js new file mode 100755 index 0000000..34887bf --- /dev/null +++ b/_examples/rethinkdb/index.js @@ -0,0 +1,21 @@ +var express = require('express'); +var app = express(); +var r = require('rethinkdb'); + +app.get('/', function(req, res) { + r.connect({ + host: 'rethinkdb', + port: 28015, + authKey: '', + }, function(err) { + + if (!err) { + res.send('You are amazing'); + } else { + res.send('Could not connect to RethinkDB :('); + } + + }); +}); + +app.listen(8000); diff --git a/_examples/rethinkdb/package.json b/_examples/rethinkdb/package.json new file mode 100644 index 0000000..afd1dd0 --- /dev/null +++ b/_examples/rethinkdb/package.json @@ -0,0 +1,15 @@ +{ + "name": "example-rethinkdb-node-docker", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "MIT", + "dependencies": { + "express": "^4.14.0", + "rethinkdb": "^2.3.3" + } +} diff --git a/docker-compose.yml b/docker-compose.yml index 52d4e64..b774b22 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -90,6 +90,17 @@ services: expose: - "11211" + rethinkdb: + build: + context: ./rethinkdb + volumes: + - ./data/rethinkdb:/data + expose: + - "28015" + - "29015" + ports: + - "28080:8080" + volumes: image: tianon/true volumes: diff --git a/node/Dockerfile b/node/Dockerfile index 4fd579d..b16573d 100644 --- a/node/Dockerfile +++ b/node/Dockerfile @@ -17,6 +17,9 @@ ENV NODE_ENV=$NODE_ENV RUN groupadd -r www-app &&\ useradd -r -g www-app www-app +RUN mkdir -p /home/www-app &&\ + chmod 777 /home/www-app -R + # Install the specified NODE_VERSION or grab latest RUN n "$NODE_VERSION" diff --git a/node/scripts/run-nodock.sh b/node/scripts/run-nodock.sh index fa6093e..64fa6ce 100644 --- a/node/scripts/run-nodock.sh +++ b/node/scripts/run-nodock.sh @@ -13,7 +13,7 @@ cd $PROJECT_PATH if [[ $YARN = true ]]; then su -c "cd $PROJECT_PATH; yarn" -s /bin/bash www-app else - su -c "cd $PROJECT_PATH; npm i" -s /bin/bash www-app + su -c "cd $PROJECT_PATH; npm i --force" -s /bin/bash www-app fi su -c "cd $PROJECT_PATH; $SCRIPT" -s /bin/bash www-app diff --git a/rethinkdb/Dockerfile b/rethinkdb/Dockerfile new file mode 100644 index 0000000..033c2db --- /dev/null +++ b/rethinkdb/Dockerfile @@ -0,0 +1,3 @@ +FROM rethinkdb + +CMD ["rethinkdb", "--bind", "all"]