# rustelo_website catalog component for this project instance.
#
# Consumed by provisioning/deploy.nu and the provisioning catalog runner.
# The catalog import path must include the provisioning repo root so that
# "catalog/components/rustelo_website/nickel/main.ncl" resolves.
#
# Override any field at deploy time by merging additional records:
#   nickel export --import-path $PROVISIONING component.ncl \
#     | { ..., env = { RUST_LOG = "debug" } }

let project = import "../../../provisioning/project.ncl" in
let _C      = import "catalog/components/rustelo_website/nickel/main.ncl" in

_C.make_rustelo_website {
  name               = project.name,
  namespace          = project.namespace,
  image              = project.image_base,
  image_tag          = project.image_tag,
  port               = project.port,
  domain             = project.domain,
  dns_zone           = project.dns_zone,
  acme_email         = project.acme_email,
  render_mode        = 'leptos_hydration,
  leptos_output_name = project.leptos_output_name,

  data_pvc = {
    enabled       = project.data_pvc.enabled,
    size          = project.data_pvc.size,
    # /var/www is the PV root; site/config/index.ncl must arrive here via the
    # publish tool before the entrypoint.sh loop unblocks.
    mount_path    = "/var/www",
    storage_class = project.data_pvc.storage_class,
  },

  # Non-secret runtime env injected into the Deployment alongside the
  # Dockerfile defaults. These override the image-baked values when present.
  #
  # Secret values (SESSION_SECRET, DATABASE_URL, etc.) come from a K8s Secret
  # mounted via envFrom — they are NOT listed here.
  env = {
    LEPTOS_ENV           = "PROD",
    RUST_LOG             = "info",
    SITE_CONFIG_PATH     = "/var/www/site/config/index.ncl",
    NICKEL_IMPORT_PATH   = "/usr/local/share/rustelo/nickel:/var/www/site/config",
    LEPTOS_SITE_ADDR     = "0.0.0.0:%{std.string.from_number project.port}",
    LEPTOS_SITE_ROOT     = "site",
    SITE_SERVER_CONTENT_URL   = "/r",
    SITE_SERVER_ROOT_CONTENT  = "r",
    SITE_SERVER_CONTENT_ROOT  = "site/r",
  },
}
