# The template for the sky serve controller

name: {{service_name}}

setup: |
  {{ sky_activate_python_env }}
  # Disable the pip version check to avoid the warning message, which makes the
  # output hard to read.
  export PIP_DISABLE_PIP_VERSION_CHECK=1

  # Install all cloud dependencies.
  # This is for multicloud support. To allow controller launch on all clouds,
  # we need to install all cloud dependencies.
  {%- for cmd in cloud_dependencies_installation_commands %}
  {{cmd}}
  {%- endfor %}

  # Install serve dependencies.
  # TODO(tian): Gather those into serve constants.
  pip list | grep uvicorn > /dev/null 2>&1 || pip install uvicorn > /dev/null 2>&1
  pip list | grep fastapi > /dev/null 2>&1 || pip install fastapi > /dev/null 2>&1
  pip list | grep httpx > /dev/null 2>&1 || pip install httpx > /dev/null 2>&1

file_mounts:
  {{remote_task_yaml_path}}: {{local_task_yaml_path}}
  {%- if local_user_config_path is not none %}
  {{remote_user_config_path}}: {{local_user_config_path}}
  {%- endif %}
  {%- for remote_catalog_path, local_catalog_path in modified_catalogs.items() %}
  {{remote_catalog_path}}: {{local_catalog_path}}
  {%- endfor %}
{%- if use_tls %}
  {{remote_tls_keyfile}}: {{local_tls_keyfile}}
  {{remote_tls_certfile}}: {{local_tls_certfile}}
{%- endif %}

run: |
  # Activate the Python environment, so that cloud SDKs can be found in the
  # PATH.
  {{ sky_activate_python_env }}
  # Start sky serve service.
  python -u -m sky.serve.service \
    --service-name {{service_name}} \
    --task-yaml {{remote_task_yaml_path}} \
    --job-id $SKYPILOT_INTERNAL_JOB_ID \
    >> {{controller_log_file}} 2>&1

envs:
{%- for env_name, env_value in controller_envs.items() %}
  {{env_name}}: {{env_value}}
{%- endfor %}
