version: '3'

services:
  base:
    build:
      context: .
      dockerfile: "${PWD}/services/Dockerfile-base"
    image: base:latest
  
  db:
    image: postgres
    ports:
      - "5432:5432"
    volumes:
      - "${PWD}/services/postgresql/postgres.conf:/etc/postgresql/postgresql.conf"
      - "db:/var/lib/postgresql/data:rw"
    env_file: ${PWD}/.env
  redis:
    image: redis:5.0.3
    ports:
      - "6379:6379"
  web:
    build:
      context: .
      dockerfile: "${PWD}/services/Dockerfile-web"
    env_file: ${PWD}/.env
    ports:
      - "80:80"
      - "8000:8000"
      - "443:443"
    depends_on:
      - db
      - redis
      - base
    environment:
      - DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
      - REDIS_URL=redis://${REDIS_HOST}:${REDIS_PORT}/${REDIS_DB}
    volumes:
      - ${PWD}/config:/code/config
      - ${PWD}/geeksbot_web:/code/geeksbot_web
      - ${PWD}/geeksbot_v2:/code/geeksbot_v2
  geeksbot:
    build:
      context: .
      dockerfile: "${PWD}/services/Dockerfile-geeksbot"
    env_file: ${PWD}/.env
    depends_on:
      - db
      - redis
      - base
      - web
    volumes:
      - ${PWD}/geeksbot:/code/geeksbot
      - ~/.ssh/id_rsa:/root/.ssh/id_rsa
      - ~/.ssh/id_rsa.pub:/root/.ssh/authorized_keys
      - ~/.ssh/known_hosts:/root/.ssh/known_hosts

volumes:
  db:
    external: true
