services:
  mongodb:
    image: mongo:latest
    container_name: pki-mongodb
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
      MONGO_INITDB_DATABASE: pki_db
    ports:
      - "27018:27017"
    volumes:
      - mongodb_data:/data/db
      - ./scripts/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
  pki-api:
    build: .
    container_name: pki-api
    restart: always
    depends_on:
      - mongodb
    ports:
      - "8080:8080"
    environment:
      MONGODB_URI: mongodb://${MONGO_INITDB_ROOT_USERNAME}:${MONGO_INITDB_ROOT_PASSWORD}@mongodb:27017/pki_db?authSource=admin
      JWT_SECRET: ${JWT_SECRET} 
    volumes:
      - ./certs:/app/certs
      - ./internal/web/static:/app/internal/web/static
      - ./internal/web/templates:/app/internal/web/templates

volumes:
  mongodb_data:
