Skip to content

Commit

Permalink
example: example app using mongodb as a storage backend
Browse files Browse the repository at this point in the history
  • Loading branch information
esatterwhite committed Feb 19, 2018
1 parent b35b9f6 commit 19d367b
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 4 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
node_modules/
compose/
assets/
examples/
docs/
coverage/
tutorials/
Expand Down
32 changes: 32 additions & 0 deletions examples/mongo-storage/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -- BASE
FROM buildpack-deps:stretch-curl AS base
ENV storage__path /var/data/skyring
ENV NODE_ENV=production
RUN apt-get update && apt-get install -y \
build-essential curl g++ make tar python

ENV NODE_VERSION 8.7.0

RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz"
RUN tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1

# -- BUILD
FROM base AS build

COPY package*.json /opt/skyring/
WORKDIR /opt/skyring
RUN npm install && mv node_modules prod_node_modules

# -- RELEASE
FROM debian:stretch-slim as skyring
RUN mkdir -p /var/data/skyring
WORKDIR /opt/skyring
VOLUME /etc
VOLUME /var/data/skyring

COPY --from=build /usr/local/bin/node /usr/local/bin/node
COPY --from=build /usr/local/bin/npm /usr/local/bin/npm
COPY --from=build /usr/local/include/node /usr/local/include
COPY --from=build /opt/skyring/prod_node_modules ./node_modules
COPY . .
CMD ["node", "index.js"]
3 changes: 3 additions & 0 deletions examples/mongo-storage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## MONGO-STORAGE

Skying cluster using a mongodb instance for external storage
112 changes: 112 additions & 0 deletions examples/mongo-storage/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
version: '2'
services:
node-1:
build: ./
hostname: node-1
environment:
DEBUG: '*'
channel__host: 'node-1'
nats__hosts: 'nats-a:4222,nats-b:4222,nats-c:4222'
seeds: 'node-1:3455,node-2:3456'
storage__backend: 'mongodown'
storage__path: 'mongodb://mongo:27017/skyring'
storage__collection: 'skyring-1'
networks:
- mongoring
depends_on:
- nats-a
- nats-b
- nats-c
- mongo

node-2:
build: ./
hostname: node-2
environment:
DEBUG: '*'
seeds: 'node-1:3455,node-2:3456'
nats__hosts: 'nats-a:4222,nats-b:4222,nats-c:4222'
channel__host: 'node-2'
channel__port: 3456
storage__backend: 'mongodown'
storage__path: 'mongodb://mongo:27017/skyring'
storage__collection: 'skyring-2'
networks:
- mongoring
depends_on:
- nats-a
- nats-b
- nats-c
- mongo

node-3:
build: ./
hostname: node-3
environment:
DEBUG: '*'
seeds: 'node-1:3455,node-2:3456'
nats__hosts: 'nats-a:4222,nats-b:4222,nats-c:4222'
channel__host: 'node-3'
storage__backend: 'mongodown'
storage__path: 'mongodb://mongo:27017/skyring'
storage__collection: 'skyring-3'
networks:
- mongoring
depends_on:
- nats-a
- nats-b
- nats-c
- node-1
- node-2
- mongo

nats-a:
image: nats:latest
volumes:
- ./etc/nats:/tmp
command: >
-c /tmp/a.conf -D
networks:
- mongoring
nats-b:
image: nats:latest
volumes:
- ./etc/nats:/tmp
command: >
-c /tmp/b.conf -D
depends_on:
- nats-a
networks:
- mongoring
nats-c:
image: nats:latest
volumes:
- ./etc/nats:/tmp
depends_on:
- nats-a
command: >
-c /tmp/c.conf -D
networks:
- mongoring

mongo:
image: mongo:3.6
networks:
- mongoring

nginx:
image: 'nginx:latest'
volumes:
- ./etc/nginx/nginx.conf:/etc/nginx/nginx.conf
ports:
- "8080:80"
networks:
- mongoring
depends_on:
- node-1
- node-2
- node-3

networks:
mongoring:
driver: bridge
9 changes: 9 additions & 0 deletions examples/mongo-storage/etc/nats/a.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
port: 4222
cluster {
host: '0.0.0.0'
port: 6222
routes = [
nats-route://nats-b:6222
nats-route://nats-c:6222
]
}
9 changes: 9 additions & 0 deletions examples/mongo-storage/etc/nats/b.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
port: 4222
cluster {
host: '0.0.0.0'
port: 6222
routes = [
nats-route://nats-a:6222
nats-route://nats-c:6222
]
}
10 changes: 10 additions & 0 deletions examples/mongo-storage/etc/nats/c.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
port: 4222
cluster {
host: '0.0.0.0'
port: 6222
routes = [
nats-route://nats-a:6222
nats-route://nats-b:6222
]
}

54 changes: 54 additions & 0 deletions examples/mongo-storage/etc/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#user nobody;
worker_processes 8;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
worker_connections 2048;
}


http {
include mime.types;
default_type application/octet-stream;
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
#gzip on;
keepalive_timeout 65;
proxy_read_timeout 200;
gzip_http_version 1.0;
gzip_min_length 0;
gzip_types text/plain text/css text/javascript application/javascript application/json applicatin/x-javascript application/x-json;
gzip_buffers 16 8k;
gzip_comp_level 9;
gzip_vary on;
proxy_next_upstream error;

upstream skyring {
server node-1:3000;
server node-2:3000;
server node-3:3000;
}

server {
listen 80;
server_name skyring;

location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://skyring;
}
}
}
11 changes: 11 additions & 0 deletions examples/mongo-storage/mock-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict'

const http = require('http')
let count = 0
const server = http.createServer((req, res) => {
res.writeHead(204)
res.end('')
console.log(++count)
})

server.listen(process.env.PORT || 4000)
6 changes: 3 additions & 3 deletions examples/mongo-storage/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/mongo-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"license": "MIT",
"dependencies": {
"mongodown": "^1.2.0",
"skyring": "^5.1.0"
"skyring": "^6.0.0-alpha.1"
}
}

0 comments on commit 19d367b

Please sign in to comment.