version: '3.7'

services:

app: &app
  build:
    context: .
    dockerfile: ./Dockerfile.dev
    args:
      RUBY_VERSION: '2.7.0'
      ALPINE_VERSION: ''
      BUNDLER_VERSION: '2.1.2'
  image: <%= "#{app_name}:1.0.0" %>
  tmpfs:
    - /tmp

backend: &backend
  <<: *app
  stdin_open: true
  tty: true
  environment:
    NODE_ENV: development
    RAILS_ENV: ${RAILS_ENV:-development}
    PSQL_HISTFILE: /app/log/.psql_history
    WEBPACKER_DEV_SERVER_HOST: webpacker
    EDITOR: vi
  volumes:
    - .:/app:cached
    - rails_cache:/app/tmp/cache
    - bundle:/bundle
    - node_modules:/app/node_modules
    - packs:/app/public/packs
  depends_on:
    - postgres

runner:
  <<: *backend
  command: /bin/bash
  ports:
    - '3000:3000'
    - '3002:3002'

rails:
  <<: *backend
  command: bundle exec rails server -b 0.0.0.0
  ports:
    - '3000:3000'

postgres:
  image: postgres:12-alpine
  environment:
    POSTGRES_USER: postgres
    POSTGRES_PASSWORD: postgres
    PSQL_HISTFILE: /root/log/.psql_history
  ports:
    - 5432:5432
  volumes:
    - .psqlrc:/root/.psqlrc:ro
    - postgres:/var/lib/postgresql/data
    - ./log:/root/log:cached

webpacker:
  <<: *app
  command: ./bin/webpack-dev-server
  ports:
    - '3035:3035'
  volumes:
    - .:/app:cached
    - bundle:/bundle
    - node_modules:/app/node_modules
    - packs:/app/public/packs
  environment:
    - NODE_ENV=${NODE_ENV:-development}
    - RAILS_ENV=${RAILS_ENV:-development}
    - WEBPACKER_DEV_SERVER_HOST=0.0.0.0

volumes:

postgres:
bundle:
node_modules:
rails_cache:
packs: