version: "3.3"
    
services:
  db:
    container_name: postgrescalcContainer
    image: postgres
    restart: always  
    hostname: postgres-calc
    labels:
      - traefik.enable=false
    volumes:
      - postgrescalc:/data/postgres
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
      PGDATA: /data/postgres
    networks:
      - calc-network
    
  calendso:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        - BASE_URL=${BASE_URL}
        - NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL}
    labels:
      - traefik.enable=true
      - traefik.http.routers.calendar.rule=Host(`${URL_CALC}`)
      - traefik.http.routers.calendar.entrypoints=websecure
      - traefik.http.routers.calendar.tls=true
      - traefik.http.routers.calendar.tls.certresolver=lets-encrypt
      - traefik.http.routers.calendar.service=calendar-srv
      - traefik.http.services.calendar-srv.loadbalancer.server.port=3000
      - traefik.docker.network=${NETWORK_TRAEFIK}
    networks:
      - traefik-proxy
      - calc-network  
    image: calendso/docker
    container_name: calendso-app
    restart: always
#    ports:
#      - 3010:3000
    env_file: .env
    environment:
      - DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres-calc/${POSTGRES_DB}
    depends_on:
      - db

 

  studio:
    image: calendso/docker
    container_name: studio-calendso
    labels:
      - traefik.enable=true
      - traefik.http.routers.prismacalendar.rule=Host(`${URL_ADMIN_CONF}`)
      - traefik.http.routers.prismacalendar.entrypoints=websecure
      - traefik.http.routers.prismacalendar.tls=true
      - traefik.http.routers.prismacalendar.middlewares=test-auth
      - "traefik.http.middlewares.test-auth.basicauth.users=$creditentials"
      - traefik.http.routers.prismacalendar.tls.certresolver=lets-encrypt
      - traefik.http.routers.prismacalendar.service=prismacalendar-srv
      - traefik.http.services.prismacalendar-srv.loadbalancer.server.port=5555
      - traefik.docker.network=${NETWORK_TRAEFIK}
    env_file: .env
    environment:
      - DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres-calc/${POSTGRES_DB}
    depends_on:
      - db
    command:
      - npx
      - prisma
      - studio
    networks:
      - traefik-proxy
      - calc-network   

networks:
  traefik-proxy:
    external:
      name: ${NETWORK_TRAEFIK}
  calc-network:
    internal: true

volumes:
 postgrescalc:
    driver: local
    driver_opts:
      type: none
      device: ${VOLUME_POSTGRES_CALC}
      o: bind

