services:
  affine:
    image: ghcr.io/toeverything/affine:0.26.4
    container_name: ${CONTAINER_NAME}
    restart: unless-stopped
    ports:
      - ${PANEL_APP_PORT_HTTP}:3010
    volumes:
      - ./data/storage:/root/.affine/storage
      - ./data/config:/root/.affine/config
    networks:
      - 1panel-network
    environment:
      - REDIS_SERVER_HOST=${PANEL_REDIS_HOST}
      - REDIS_SERVER_PORT=6379
      - REDIS_SERVER_PASSWORD=${PANEL_REDIS_ROOT_PASSWORD}
      - DATABASE_URL=postgres://${PANEL_DB_USER}:${PANEL_DB_USER_PASSWORD}@${PANEL_DB_HOST}:${PANEL_DB_PORT}/${PANEL_DB_NAME}
      - AFFINE_INDEXER_ENABLED=false
    depends_on:
      affine_migration:
        condition: service_completed_successfully
    labels:
      createdBy: "Apps"
      
  affine_migration:
    image: ghcr.io/toeverything/affine:0.26.4
    container_name: ${CONTAINER_NAME}_migration_job
    volumes:
      - ./data/storage:/root/.affine/storage
      - ./data/config:/root/.affine/config
    command: [ 'sh', '-c', 'node ./scripts/self-host-predeploy.js' ]
    networks:
      - 1panel-network
    environment:
      - REDIS_SERVER_HOST=${PANEL_REDIS_HOST}
      - REDIS_SERVER_PORT=6379
      - REDIS_SERVER_PASSWORD=${PANEL_REDIS_ROOT_PASSWORD}
      - DATABASE_URL=postgres://${PANEL_DB_USER}:${PANEL_DB_USER_PASSWORD}@${PANEL_DB_HOST}:${PANEL_DB_PORT}/${PANEL_DB_NAME}
      - AFFINE_INDEXER_ENABLED=false
    labels:
      createdBy: "Apps"
      skipStatusCheck: "true"
networks:
  1panel-network:
    external: true
