# Include syntax requires Docker compose > 2.20.3
# https://docs.docker.com/compose/release-notes/#2203
include:
  # Creates the internal MongoDB replica set
  - path: ps-mongo.yaml

services:
  # Main PowerSync service
  powersync:
    depends_on:
      - mongo
    image: journeyapps/powersync-service:latest
    # The unified service runs an API server and replication worker in the same container.
    # These services can be executed in different containers by using individual entry commands e.g.
    # Start only the API server with
    #   command: ['start', '-r', 'api']
    # Start only the replication worker with
    #   command: ['start', '-r', 'sync']

    # Migations occur automatically by default. Default migrations can be disabled in `powersync.yaml`:
    #  migrations:
    #   disable_auto_migration: true
    #
    # Service migrations can be manually triggered by starting a container with the
    # following command:
    #     command: ['migrate', 'up']
    # Note that this container must finish executing before starting the sync or unified container.
    command: ["start", "-r", "unified"]
    volumes:
      # Mounts the specified config folder to the container
      # This folder should contain `powersync.yaml and sync_rules.yaml
      - ./powersync.yaml:/app/powersync.yaml:ro
      - ./config:/app/config:ro
      - ./config:/config:ro
    environment:
      # This is the path (inside the container) to the YAML config file
      # Alternatively the config path can be specified in the command
      # e.g:
      #- ./powersync.yaml:/app/powersync.yaml:ro
      #
      # The config file can also be specified in Base 64 encoding
      # e.g.: Via an environment variable
      #   POWERSYNC_CONFIG_B64: [base64 encoded content]
      # or e.g.: Via a command line parameter
      #    command: ['start', '-r', 'unified', '-c64', '[base64 encoded content]']
      #POWERSYNC_CONFIG_PATH: /config/powersync.yaml

      # Sync rules can be specified as base 64 encoded YAML
      # e.g: Via an environment variable
      # POWERSYNC_SYNC_RULES_B64: "[base64 encoded sync rules]"
      # or e.g.: Via a command line parameter
      #     command: ['start', '-r', 'unified', '-sync64', '[base64 encoded content]']

      # The following will be inserted into the powersync.yaml file via templating
      # Templates are used for filesystem and base64 configuration files
      PS_PG_URI: postgres://${PG_DATABASE_USER}:${PG_DATABASE_PASSWORD}@{PG_DATABASE_HOST}:${PG_DATABASE_PORT}/${PG_DATABASE_NAME}
      PS_MONGO_URI: mongodb://mongo:27017/powersync_datafy?replicaSet=rs0&connectTimeoutMS=30000&socketTimeoutMS=30000

      # The port which the PowerSync API server should run on
      PS_PORT: ${PS_PORT}

      #  CA certificate for Postgres connection
      # PS_PG_CA_CERT:

      # Client certificate for Postgres connection
      # PS_PG_CLIENT_CERT:

      # Client private key for Postgres connection
      # PS_PG_CLIENT_PRIVATE_KEY:

      # Potential JWKs public key template
      # PS_JWK_N:
      # PS_JWK_E:
      # PS_JWK_KID:

    ports:
      - ${PS_PORT}:${PS_PORT}
    network_mode: "bridge"
