跳至內容

設定

此頁面涵蓋安裝層級的設定:控制器設定、代理設定、Web 環境變數與 age 金鑰設定。

服務定義位於 composia-meta.yaml 中。請參見服務指南了解該檔案。

設定檔結構

控制器和代理使用相同的 YAML 檔案格式。一個檔案可以包含任一區段或兩者:

controller:
  # 控制器設定

agent:
  # 代理設定

必須至少存在 controlleragent 其中之一。

當同一個設定檔同時包含兩個區段時,本地代理被視為內建節點:

  • agent.node_id 必須為 main
  • controller.nodes 必須包含一個帶有 id: main 的項目。
  • controller.repo_diragent.repo_dir 不得為相同路徑。

完整設定範本

此範本顯示每個支援的安裝層級鍵。它是結構參考,而非可直接複製貼上的預設值。移除您不使用的區段、移除空清單項目,並對每個類似密鑰的欄位使用內聯值或 _file 值。

config.yaml
controller:
  listen_addr: ":7001"
  repo_dir: "/data/repo-controller"
  state_dir: "/data/state-controller"
  log_dir: "/data/logs"

  access_tokens:
    - name: "web"
      token: "REPLACE_WITH_WEB_ACCESS_TOKEN"
      token_file: ""
      enabled: true
      comment: "Web UI 存取權杖"

  nodes:
    - id: "main"
      display_name: "Main"
      enabled: true
      public_ipv4: ""
      public_ipv6: ""
      token: "REPLACE_WITH_MAIN_AGENT_TOKEN"
      token_file: ""

  git:
    remote_url: ""
    branch: "main"
    pull_interval: ""
    author_name: "Composia"
    author_email: "composia@example.com"
    auth:
      username: ""
      token: ""
      token_file: ""

  backup:
    default_schedule: ""

  updates:
    default_check_schedule: ""
    auto_apply: false
    backup_before_update: true
    digest_pin: false
    semver:
      default_allow:
        - patch
        - minor
    forge_auth:
      github:
        url: "https://github.com"
        token: ""
        token_file: ""
        api_url: "https://api.github.com"
      gitlab:
        url: "https://gitlab.com"
        token: ""
        token_file: ""
        api_url: "https://gitlab.com/api/v4"
      forgejo:
        url: "https://forgejo.example.com"
        token: ""
        token_file: ""
        api_url: ""

  auto_deploy:
    infra: false
    services: false

  dns:
    cloudflare:
      api_token: ""
      api_token_file: ""
      zones: []
    alidns:
      access_key_id: ""
      access_key_id_file: ""
      access_key_secret: ""
      access_key_secret_file: ""
      security_token: ""
      security_token_file: ""
      region_id: ""
      zones: []
    dnspod:
      secret_id: ""
      secret_id_file: ""
      secret_key: ""
      secret_key_file: ""
      session_token: ""
      session_token_file: ""
      region: ""
      zones: []
    route53:
      access_key_id: ""
      access_key_id_file: ""
      secret_access_key: ""
      secret_access_key_file: ""
      session_token: ""
      session_token_file: ""
      region: ""
      profile: ""
      hosted_zone_id: ""
      zones: []
    huaweicloud:
      access_key_id: ""
      access_key_id_file: ""
      secret_access_key: ""
      secret_access_key_file: ""
      region_id: ""
      zones: []

  rustic:
    main_nodes:
      - "main"
    maintenance:
      forget_schedule: ""
      prune_schedule: ""

  secrets:
    provider: age
    identity_file: "/app/configs/age-identity.key"
    recipient_file: ""
    armor: true

  notifications:
    alertmanager:
      enabled: true
      listen_path: "/api/v1/alerts"
    smtp:
      enabled: false
      host: ""
      port: 587
      encryption: starttls
      username: ""
      password: ""
      password_file: ""
      from: ""
      to: []
      on: []
      task_sources: []
    telegram:
      enabled: false
      bot_token: ""
      bot_token_file: ""
      chat_id: ""
      on: []
      task_sources: []

agent:
  controller_addr: "http://controller:7001"
  controller_grpc: false
  controller_headers:
    - name: ""
      value: ""
      value_file: ""
  node_id: "main"
  token: "REPLACE_WITH_MAIN_AGENT_TOKEN"
  token_file: ""
  repo_dir: "/data/repo-agent"
  state_dir: "/data/state-agent"
  caddy:
    generated_dir: ""

請勿保留如含有空白 namecontroller_headers 等空清單項目。它們僅為記錄支援的物件結構而顯示。

Web 存取權杖和主要代理權杖必須不同。

Age 金鑰設定

controller.secrets 是可選的。僅在您使用 Composia 管理的加密密鑰時才設定它。

當設定了 controller.secrets 時,identity_file 為必要項。recipient_file 為可選。若省略,Composia 從私鑰衍生接收者。

產生私鑰:

age-keygen -o age-identity.key

可選的接收者檔案:

age-keygen -y age-identity.key > age-recipients.txt

在設定中使用私鑰:

secrets:
  provider: age
  identity_file: "/app/configs/age-identity.key"

或同時使用兩個檔案:

secrets:
  provider: age
  identity_file: "/app/configs/age-identity.key"
  recipient_file: "/app/configs/age-recipients.txt"

armor 是可選的,預設為 true

控制器設定參考

必要鍵

型別說明
listen_addrstring控制器監聽位址,例如 ":7001""127.0.0.1:7001"
repo_dirstring期望狀態 Git 存放庫路徑。
state_dirstring控制器狀態路徑。
log_dirstring任務日誌目錄。
nodes[]object已設定的代理節點。此鍵必須存在,即使是空的。

可選的頂層鍵

型別說明
access_tokens[]object用於 Web UI、CLI 和外部客戶端的 API 權杖。
backupobject全域備份預設值。
gitobject期望狀態存放庫遠端同步。
notificationsobjectAlertmanager、SMTP 和 Telegram 通知。
dnsobjectDNS 提供者憑證。
rusticobjectRustic 維護設定。
secretsobjectAge 加密設定。
updatesobject映像檔更新預設值和 forge API 驗證。
auto_deployobject全域自動部署開關。

nodes[]

型別必要說明
idstring唯一的節點 ID。
display_namestringUI 中顯示的名稱。
enabledbool不移除節點而停用它。
public_ipv4stringDNS 工作流程使用的公開 IPv4。
public_ipv6stringDNS 工作流程使用的公開 IPv6。
tokenstring是*代理驗證權杖。
token_filestring從檔案讀取權杖。

*使用 tokentoken_file,不能同時兩者。

access_tokens[]

型別必要說明
namestring權杖名稱。
tokenstring是*權杖值。
token_filestring從檔案讀取權杖。
enabledbool不移除權杖而停用它。
commentstring管理備註。

存取權杖不得與節點權杖或其他存取權杖重複。

git

型別必要說明
remote_urlstringGit 遠端 URL。
branchstring要同步的分支。
pull_intervalstring條件必要設定 remote_url 時為必要項。
author_namestring控制器寫入的提交作者名稱。
author_emailstring提交作者電子郵件。
auth.usernamestringGit 使用者名稱。
auth.tokenstringGit 權杖。
auth.token_filestring從檔案讀取 Git 權杖。

secrets

整個區段是可選的。若此區段存在,則以下規則適用:

型別必要說明
providerstring必須為 age
identity_filestringAge 私鑰路徑。
recipient_filestringAge 接收者檔案路徑。若省略,從 identity_file 衍生接收者。
armorboolASCII armoring 加密輸出。預設為 true

backup

型別說明
default_schedulestring服務備份的預設 cron 排程。

updates

型別說明
default_check_schedulestring映像檔更新檢查的預設 cron 排程。
auto_applybool預設自動套用更新。
backup_before_updatebool套用更新前備份資料。
digest_pinbool以摘要固定映像檔。
semver.default_allow[]string允許的 semver 版本升級層級:patchminormajor
forge_auth.githubobject[]objectGitHub API 驗證。
forge_auth.gitlabobject[]objectGitLab API 驗證。
forge_auth.forgejoobject[]objectForgejo API 驗證。

每個 forge 驗證項目支援:

型別說明
urlstringForge 基礎 URL。
tokenstringAPI 權杖。
token_filestring從檔案讀取 API 權杖。
api_urlstringAPI URL 覆蓋。

auto_deploy

型別說明
infraboolGit 變更後自動部署基礎架構服務。
servicesboolGit 變更後自動部署一般服務。

dns

提供者鍵憑證鍵共用鍵
cloudflareapi_tokenapi_token_filezones
alidnsaccess_key_idaccess_key_id_fileaccess_key_secretaccess_key_secret_filesecurity_tokensecurity_token_fileregion_idzones
dnspodsecret_idsecret_id_filesecret_keysecret_key_filesession_tokensession_token_fileregionzones
route53access_key_idaccess_key_id_filesecret_access_keysecret_access_key_filesession_tokensession_token_fileregionprofilehosted_zone_idzones
huaweicloudaccess_key_idaccess_key_id_filesecret_access_keysecret_access_key_fileregion_idzones

rustic

型別說明
main_nodes[]string執行 Rustic 操作的節點 ID。每個必須引用 controller.nodes
maintenance.forget_schedulestringrustic forget 的 cron 排程。
maintenance.prune_schedulestringrustic prune 的 cron 排程。

notifications.alertmanager

型別說明
enabledbool當區段存在時預設啟用。
listen_pathstringWebhook 路徑。預設為 /api/v1/alerts。必須以 / 開頭。

notifications.smtp

型別啟用時必要說明
enabledbool當區段存在時預設啟用。
hoststringSMTP 主機。
portintSMTP 連接埠,1 到 65535。
encryptionstringnonestarttlsssl_tls。預設為 starttls
usernamestringSMTP 使用者名稱。
passwordstringSMTP 密碼。
password_filestring從檔案讀取密碼。
fromstring寄件者地址。
to[]string收件者清單。
on[]string通知事件過濾器。
task_sources[]string任務來源過濾器:webcliothersschedulesystem

notifications.telegram

型別啟用時必要說明
enabledbool當區段存在時預設啟用。
bot_tokenstring是*Telegram 機器人權杖。
bot_token_filestring從檔案讀取機器人權杖。
chat_idstring目標聊天室 ID。
on[]string通知事件過濾器。
task_sources[]string任務來源過濾器。

代理設定參考

型別必要說明
controller_addrstring代理可連線的控制器 URL。
controller_grpcbool使用 gRPC 而非基於 HTTP 的 Connect。
controller_headers[]object發送給控制器的額外 HTTP 標頭。
node_idstring此代理的節點 ID。必須與 controller.nodes[].id 匹配。
tokenstring是*與控制器設定匹配的節點權杖。
token_filestring從檔案讀取節點權杖。
repo_dirstring代理服務存放庫路徑。
state_dirstring代理狀態目錄。
caddyobject代理端 Caddy 設定。

*使用 tokentoken_file,不能同時兩者。

controller_headers[]

型別必要說明
namestringHTTP 標頭名稱。標頭名稱以不區分大小寫的方式去重。
valuestring是*標頭值。
value_filestring從檔案讀取標頭值。

caddy

型別說明
generated_dirstring產生的 Caddy 設定目錄。預設為 <state_dir>/caddy/generated

Web 環境變數

Web 伺服器讀取環境變數。在 Docker Compose 中,這些透過 .env 設定。

變數必要說明
WEB_CONTROLLER_ADDR從 Web 伺服器處理程序看到的控制器位址。在 Docker Compose 中:http://controller:7001
WEB_BROWSER_CONTROLLER_ADDR從瀏覽器看到的控制器位址。
WEB_CONTROLLER_ACCESS_TOKEN控制器存取權杖。必須與 controller.access_tokens[].token 匹配。
WEB_CONTROLLER_HEADERSWeb 伺服器呼叫控制器時發送的額外標頭的 JSON 物件。
WEB_LOGIN_USERNAMEWeb 登入使用者名稱。
WEB_LOGIN_PASSWORD_HASHArgon2 密碼雜湊。
WEB_SESSION_SECRET隨機的會話簽名密鑰。
ORIGIN取決於部署Web 伺服器的公開來源。
HOST主機繫結位址。
PORTWeb 伺服器連接埠。

內聯值與 _file

許多類似密鑰的欄位同時支援內聯值和檔案引用。範例:

  • token / token_file
  • password / password_file
  • api_token / api_token_file
  • value / value_file

僅使用一種形式。若同時設定兩者,啟動會失敗。

最後更新於 • Renovate Bot