version: '3'

services:

  nginx:
    container_name: vtn-nginx
    ports: 
      - 44443:443
    image: nginx:latest
    volumes:
      - "./nginx.conf:/etc/nginx/conf.d/default.conf"
      - "./ssl.crt:/etc/ssl/ssl.crt"
      - "./ssl.key:/etc/ssl/ssl.key"
    depends_on:
      - rails
    restart: unless-stopped

  db:
    container_name: vtn-db
    image: postgres:9.5
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: ${RAILS_DB_DATABASE}
      POSTGRES_USER: ${RAILS_DB_USERNAME}
      POSTGRES_PASSWORD: ${RAILS_DB_PASSWORD}
    restart: unless-stopped

  rails:
    container_name: vtn-rails
    build: .
    expose:
      - 9292
    depends_on:
      - db
    restart: on-failure
    # command: initdb
    environment:
      - RAILS_ENV=${RAILS_ENV}
      - RAILS_SECRET_TOKEN=${RAILS_SECRET_TOKEN}
      - RAILS_DB_USERNAME=${RAILS_DB_USERNAME}
      - RAILS_DB_PASSWORD=${RAILS_DB_PASSWORD}
      - RAILS_DB_DATABASE=${RAILS_DB_DATABASE}
      - RAILS_DB_HOSTNAME=vtn-db

volumes:
  postgres_data:
