# documentation: https://help.teable.io/
# slogan: Teable is a powerful visual interface built on relational databases (PostgreSQL).
# category: productivity
# tags: airtable, teable, database, visual, interface, relational, postgresql
# logo: svgs/teable.png
# port: 3000

services:
  teable:
    image: ghcr.io/teableio/teable:latest
    volumes:
      - teable_data:/app/.assets:rw
    environment:
      - SERVICE_URL_TEABLE_3000
      - PUBLIC_ORIGIN=${SERVICE_URL_TEABLE}
      - POSTGRES_PASSWORD=${SERVICE_PASSWORD_POSTGRES}
      - SECRET_KEY=${SERVICE_PASSWORD_64_SECRET}
      - TZ=${TIMEZONE}
      - PRISMA_DATABASE_URL=postgresql://${SERVICE_USER_POSTGRES}:${SERVICE_PASSWORD_POSTGRES}@teable-db:${POSTGRES_PORT}/${POSTGRES_DB}
      - NEXT_ENV_IMAGES_ALL_REMOTE=true
      - PORT=3000
      - REDIS_PASSWORD=${SERVICE_PASSWORD_REDIS}
      - BACKEND_CACHE_PROVIDER=redis
      - BACKEND_CACHE_REDIS_URI=redis://default:${SERVICE_PASSWORD_REDIS}@teable-cache:6379/0
      - 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-cache:
        condition: service_healthy
    healthcheck:
      test:
        - CMD
        - curl
        - '-f'
        - 'http://127.0.0.1:3000'
      interval: 5s
      timeout: 20s
      retries: 10

  teable-db:
    image: postgres:15.4
    volumes:
      - teable_db_data:/var/lib/postgresql/data:rw
    environment:
      - TZ=${TIMEZONE}
      - POSTGRES_DB=${POSTGRES_DB:-teable}
      - POSTGRES_PASSWORD=${SERVICE_PASSWORD_POSTGRES}
      - POSTGRES_USER=${SERVICE_USER_POSTGRES}
      - POSTGRES_PORT=${POSTGRES_PORT:-5432}
    healthcheck:
      test:
        - CMD-SHELL
        - 'pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}'
      interval: 5s
      timeout: 20s
      retries: 10
  teable-db-migrate:
    image: ghcr.io/teableio/teable-db-migrate:latest
    restart: no
    environment:
      - TZ=${TIMEZONE}
      - PRISMA_DATABASE_URL=postgresql://${SERVICE_USER_POSTGRES}:${SERVICE_PASSWORD_POSTGRES}@teable-db:${POSTGRES_PORT}/${POSTGRES_DB}
    depends_on:
      teable-db:
        condition: service_healthy
  teable-cache:
    image: redis:7.2.4
    environment:
      - REDIS_PORT=6379
      - REDIS_DB=0
      - REDIS_PASSWORD=${SERVICE_PASSWORD_REDIS}
    volumes:
      - teable_cache_data:/data:rw
    command: redis-server --appendonly yes --requirepass ${SERVICE_PASSWORD_REDIS}
    healthcheck:
      test:
        - CMD
        - redis-cli
        - '--raw'
        - incr
        - ping
      interval: 10s
      timeout: 3s
      retries: 3
