version: '3'
services:
  boltcard:
    build: 
      context: ./
      dockerfile: Dockerfile
    container_name: boltcard_main
    depends_on:
      - db
    restart: unless-stopped
    environment:
      - LOG_LEVEL=DEBUG
      - DB_HOST=db
      - DB_USER=cardapp
      - DB_PASSWORD=${DB_PASSWORD}
      - DB_PORT=5432    
      - DB_NAME=card_db
    expose: 
      - "9000"
    volumes:
      - ${PWD}/tls.cert:/boltcard/tls.cert
      - ${PWD}/admin.macaroon:/boltcard/admin.macaroon
    networks:
      - boltnet
  db:
    image: postgres
    container_name: boltcard_db
    restart: unless-stopped
    environment:
      - POSTGRES_USER=cardapp
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - POSTGRES_DB=card_db
      - PGDATA=/var/lib/postgresql/data/pgdata
    volumes:
      - db-data:/var/lib/postgresql/data
      - ./sql/select_db.sql:/docker-entrypoint-initdb.d/select_db.sql
      - ./sql/create_db.sql:/docker-entrypoint-initdb.d/create_db.sql
      - ./sql/settings.sql:/docker-entrypoint-initdb.d/settings.sql
    expose:
      - "5432"
    networks:
      - boltnet
  webserver:
    image: caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ${PWD}/Caddyfile_docker:/etc/caddy/Caddyfile
      - caddy_data:/data
      - caddy_config:/config
    networks:
      - boltnet
networks:
  boltnet:
volumes:
  db-data:
  caddy_data:
    external: true
  caddy_config: