services:
  postgres:
    container_name: "snaily-cad-postgres"
    image: postgres:latest
    environment:
      POSTGRES_PORT: ${DB_PORT}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    ports:
      - "${DB_PORT}:5432"
    networks:
      - cad_web
    volumes:
      - ./.data:/var/lib/postgresql/data
    restart: unless-stopped

  api:
    container_name: "snaily-cad-api"
    build:
      context: .
      dockerfile: ./Dockerfile
      target: api
    ports:
      - "${PORT_API}:${PORT_API}"
    expose:
      - ${PORT_API}
    depends_on:
      - postgres
    networks:
      - cad_web
    restart: always
    volumes:
      - ./apps/api/public:/snailycad/apps/api/public

  client:
    container_name: "snaily-cad-client"
    build:
      context: .
      dockerfile: ./Dockerfile
      target: client
    ports:
      - "${PORT_CLIENT}:${PORT_CLIENT}"
    expose:
      - ${PORT_CLIENT}
    depends_on:
      - postgres
    networks:
      - cad_web
    restart: always

networks:
  cad_web:
    external: true
