version: "3.9"

services:
  teable:
    image: ghcr.io/teableio/teable:1.3.1-alpha-build.460
    restart: always
    volumes:
      - teable-data:/app/.assets
      # you may use a bind-mounted host directory instead,
      # so that it is harder to accidentally remove the volume and lose all your data!
      # - ./docker/teable/data:/app/.assets:rw
    environment:
      - TZ=${TIMEZONE}
      - NEXT_ENV_IMAGES_ALL_REMOTE=true
      - PUBLIC_ORIGIN=${PUBLIC_ORIGIN}
      - PRISMA_DATABASE_URL=${PRISMA_DATABASE_URL}
      - PUBLIC_DATABASE_PROXY=${PUBLIC_DATABASE_PROXY}
      - BACKEND_MAIL_HOST=${BACKEND_MAIL_HOST}
      - BACKEND_MAIL_PORT=${BACKEND_MAIL_PORT}
      - BACKEND_MAIL_SECURE=${BACKEND_MAIL_SECURE}
      - BACKEND_MAIL_SENDER=${BACKEND_MAIL_SENDER}
      - BACKEND_MAIL_SENDER_NAME=${BACKEND_MAIL_SENDER_NAME}
      - BACKEND_MAIL_AUTH_USER=${BACKEND_MAIL_AUTH_USER}
      - BACKEND_MAIL_AUTH_PASS=${BACKEND_MAIL_AUTH_PASS}
    depends_on:
      teable-db-migrate:
        condition: service_completed_successfully

  teable-db:
    image: postgres:15.4
    restart: always
    ports:
      - "${TEABLE_DB_PORT}:${POSTGRES_PORT}"
    volumes:
      - teable-db:/var/lib/postgresql/data
      # you may use a bind-mounted host directory instead,
      # so that it is harder to accidentally remove the volume and lose all your data!
      # - ./docker/db/data:/var/lib/postgresql/data:rw
    environment:
      - TZ=${TIMEZONE}
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    networks:
      - dokploy-network
    healthcheck:
      test:
        [
          "CMD-SHELL",
          "sh -c 'pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}'",
        ]
      interval: 10s
      timeout: 3s
      retries: 3

  teable-db-migrate:
    image: ghcr.io/teableio/teable-db-migrate:latest
    environment:
      - TZ=${TIMEZONE}
      - PRISMA_DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
    networks:
      - dokploy-network
    depends_on:
      teable-db:
        condition: service_healthy

volumes:
  teable-data: {}
  teable-db: {}
