Skip to content

Instantly share code, notes, and snippets.

@altras
Last active June 11, 2018 15:06
Show Gist options
  • Save altras/418c1a3d7ab65564645219989baaba5a to your computer and use it in GitHub Desktop.
Save altras/418c1a3d7ab65564645219989baaba5a to your computer and use it in GitHub Desktop.
Ruler microservices
# Docker specific configs
# use only letters and numbers for the project name
COMPOSE_PROJECT_NAME=rulerdev
RULER_DOMAIN_NAME=localhost
# Global configs
DEVELOPMENT=1
JWT_SECRET=YCZseT-TlZemHz-GQCBZY_jNBmoKVBtYT-M34KniXyaaAEyvZu3sZ_mFjICiXoAJ
# DB connection details (used by all containers)
DB_HOST=localhost
DB_PORT=5432
DB_NAME=app
DB_SCHEMA=api
DB_USER=authenticator
DB_PASS=authenticatorpass
# PostgreSQL container config
# Use this to connect directly to the db running in the container
SUPER_USER=superuser
SUPER_USER_PASSWORD=superuserpass
PGPASSWORD=superuserpass
# OpenResty
POSTGREST_HOST=localhost
POSTGREST_PORT=3000
# PostgREST
DB_ANON_ROLE=anonymous
DB_POOL=10
MAX_ROWS=
PRE_REQUEST=
SERVER_PROXY_URI=http://localhost/rest/
# client
BUILD_ID=$(git describe)
API_URL=http://localhost/rest
NODE_ENV=development
NPM_RUN_TARGET=dev
#amazon sdk/ses, used in our notifier service
AWS_SES_FROM_ADDR=
AWS_SES_REGION=
AWS_SDK_ACC_KEY_ID=
AWS_SDK_SEC_ACC_KEY=
version: '2.1'
services:
#
db:
image: postgres:9.6
ports:
- "5432:5432"
volumes:
- "./db/src:/docker-entrypoint-initdb.d"
- "./db/src/.psqlrc:/root/.psqlrc"
environment:
# env vars specific to postgres image used on first boot
- POSTGRES_USER=${SUPER_USER}
- POSTGRES_PASSWORD=${SUPER_USER_PASSWORD}
- POSTGRES_DB=${DB_NAME}
# env vars useful for our sql scripts
- SUPER_USER=${SUPER_USER}
- SUPER_USER_PASSWORD=${SUPER_USER_PASSWORD}
- DB_NAME=${DB_NAME}
- DB_USER=${DB_USER}
- DB_PASS=${DB_PASS}
- DB_ANON_ROLE=${DB_ANON_ROLE}
- DEVELOPMENT=${DEVELOPMENT}
- JWT_SECRET=${JWT_SECRET}
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 3
# PostgREST instance, is responsible for communicating with the database
# and providing a REST api, (almost) every request that is sent to the database goes through it
postgrest:
image: postgrest/postgrest:v0.4.4.0
ports:
- "3000:3000"
network_mode: "host"
depends_on:
db:
condition: service_healthy
environment:
- PGRST_DB_URI=postgres://${DB_USER}:${DB_PASS}@${DB_HOST}:${DB_PORT}/${DB_NAME}
- PGRST_DB_SCHEMA=${DB_SCHEMA}
- PGRST_DB_ANON_ROLE=${DB_ANON_ROLE}
- PGRST_DB_POOL=${DB_POOL}
- PGRST_JWT_SECRET=${JWT_SECRET}
- PGRST_MAX_ROWS=${MAX_ROWS}
- PGRST_PRE_REQUEST=${PRE_REQUEST}
- PGRST_SERVER_PROXY_URI=${SERVER_PROXY_URI}
# OpenResty (Nginx + Lua) instance that sits in front of PostgREST.
# All the requests comming into the system are first hitting this component.
# After some processing/checks and transformation, the request is forwarded
# to PostgREST down the stack.
# As we're not very familiar with Lua we may want to change this but we still haven't found any suitable alternative
# Basically we want some request/response hooks https://github.com/subzerocloud/postgrest-starter-kit/wiki/HTTP-Request-Flow
openresty:
image: openresty/openresty:jessie
ports:
- "8080:80"
network_mode: "host"
depends_on:
- postgrest
entrypoint: /entrypoint.sh
volumes:
- "./openresty/entrypoint.sh:/entrypoint.sh"
- "./openresty/nginx/conf/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf"
- "./openresty/nginx/conf/includes:/usr/local/openresty/nginx/conf/includes"
- "./openresty/nginx/html:/usr/local/openresty/nginx/html"
- "./openresty/lualib/user_code:/usr/local/openresty/lualib/user_code"
environment:
- JWT_SECRET=${JWT_SECRET}
- DEVELOPMENT=${DEVELOPMENT}
- POSTGREST_HOST=${POSTGREST_HOST}
- POSTGREST_PORT=${POSTGREST_PORT}
- DB_HOST=${DB_HOST}
- DB_PORT=${DB_PORT}
- DB_NAME=${DB_NAME}
- DB_SCHEMA=${DB_SCHEMA}
- DB_USER=${DB_USER}
- DB_PASS=${DB_PASS}
- SERVER_PROXY_URI=${SERVER_PROXY_URI}
# Our server-side rendered (SSR) react nodejs app.
client:
image: client:latest
volumes:
- "./client:/client"
depends_on:
- openresty
network_mode: "host"
ports:
- "3001:80"
working_dir: /client
environment:
- API_URL=${API_URL}
- NPM_RUN_TARGET=${NPM_RUN_TARGET}
- NODE_ENV=${NODE_ENV}
- BUILD_ID=${BUILD_ID}
# Our nodejs app for listening on postgres notifications
# Right now we're planning to use it for sending transactional emails but it may grow in scope
notifier:
image: notifier:latest
depends_on:
db:
condition: service_healthy
environment:
- RULER_DOMAIN_NAME=${RULER_DOMAIN_NAME}
- NODE_ENV=${NODE_ENV}
- DB_HOST=${DB_HOST}
- DB_PORT=${DB_PORT}
- DB_NAME=${DB_NAME}
- DB_USER=${SUPER_USER}
- DB_PASS=${SUPER_USER_PASSWORD}
- AWS_SES_FROM_ADDR=${AWS_SES_FROM_ADDR}
- AWS_SES_REGION=${AWS_SES_REGION}
- AWS_SDK_ACC_KEY_ID=${AWS_SDK_ACC_KEY_ID}
- AWS_SDK_SEC_ACC_KEY=${AWS_SDK_SEC_ACC_KEY}
network_mode: host
working_dir: /notifier
ports:
- "4000:4000"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment