version: '3.6'

volumes:
  dbdata:

services:
  db:
    image: postgres:13.5-alpine
    restart: always
    # To preserve data between runs of docker-compose, we mount a folder from the host machine.
    volumes:
      - dbdata:/var/lib/postgresql/data
    ports:
      - 8081:5432 # Mapped to 8081 in case Postgres is already running locally on 5432
    environment:
      - POSTGRES_PASSWORD=password
      - POSTGRES_USER=postgres
      - POSTGRES_DB=data_collector

  app:
    build:
      context: .
      dockerfile: ./Dockerfile
      target: development
    platform: linux/amd64
    ports:
      - 8080:8080
    depends_on:
      - db
    environment:
      - DB_HOST=db
      - DB_DATABASE=data_collector
      - DB_USERNAME=postgres
      - DB_PASSWORD=password
      - RAILS_ENV=development
      - RAILS_SERVE_STATIC_FILES=true
      - RAILS_LOG_TO_STDOUT=true
      - SECRET_KEY_BASE=abcd1234