跳至內容
服務設定

服務設定

每個服務位於控制器存放庫中的一個頂層目錄內。服務目錄包含 composia-meta.yaml 和一個或多個 Docker Compose 檔案。

最小服務:

composia-meta.yaml
name: my-app
nodes:
  - main

使用預設行為時,Composia 會在同一目錄中尋找 docker-compose.yaml

頂層鍵

型別必要說明
namestring唯一的服務名稱。
project_namestringDocker Compose 專案名稱覆蓋。預設為正規化的服務名稱。
compose_files[]stringCompose 檔案路徑,相對於服務目錄。
enabledbool服務是否啟用。預設為 true
nodes[]string目標節點 ID。每個必須存在於 controller.nodes 中。
infraobject宣告此服務為 Caddy、Rustic 或純設定基礎架構。
networkobjectCaddy 和 DNS 設定。
updateobject映像檔更新設定。
data_protectobject備份和還原資料定義。
backupobject受保護資料的排程備份。
migrateobject啟用遷移的受保護資料。
auto_deploybool存放庫變更後自動部署此服務。

compose_files 項目必須是相對路徑、必須保持在服務目錄內,且不得重複。

基礎架構服務

infra.caddy

宣告存放庫的 Caddy 基礎架構服務。

infra:
  caddy:
    compose_service: caddy
    config_dir: /etc/caddy
型別說明
compose_servicestringCompose 服務名稱。預設為 caddy
config_dirstringCaddy 設定目錄。預設為 /etc/caddy

只有一個服務可以宣告為 Caddy 基礎架構。

infra.rustic

宣告存放庫的 Rustic 基礎架構服務。

infra:
  rustic:
    compose_service: rustic
    profile: default
    data_protect_dir: /data-protect
    init_args:
      - --set-version
      - "2"
型別說明
compose_servicestringCompose 服務名稱。預設為 rustic
profilestringRustic 設定檔名稱。
data_protect_dirstringRustic 容器內對應代理端 {StateDir}/data-protect 的路徑。
init_args[]string傳遞給 rustic init 的額外參數。空白項目會被拒絕。

只有一個服務可以宣告為 Rustic 基礎架構。

infra.config

宣告一個純設定基礎架構服務。

infra:
  config: {}

純設定服務不能與 infra.caddyinfra.rustic 合併使用。它們的 data_protect 操作只能使用 files.copy

網路

network.caddy

network:
  caddy:
    enabled: true
    source: Caddyfile
型別必要說明
enabledbool啟用 Caddy 管理。預設為 false
sourcestring條件必要Caddyfile 路徑,相對於服務目錄。啟用時為必要項。

network.dns

network:
  dns:
    provider: cloudflare
    hostname: app.example.com
    record_type: A
    value: 203.0.113.10
    proxied: true
    ttl: 120
    comment: Managed by Composia
型別必要說明
providerstringcloudflarealidnsdnspodroute53huaweicloud
hostnamestringDNS 主機名稱。
record_typestring空白、AAAAACNAME
valuestringDNS 記錄值。多節點服務應明確設定此項。
proxiedbool提供者特定的代理開關,目前與 Cloudflare 相關。
ttluint32DNS TTL。
commentstringDNS 記錄備註。

映像檔更新

update:
  enabled: true
  auto_apply: false
  check_schedule: "0 */6 * * *"
  backup_before_update: true
  digest_pin: false
  backup_data:
    - name: db
      enabled: true
  discovery_sources:
    upstream:
      sources:
        - type: github
          repo: owner/repo
      combine: first_success
      include_prerelease: false
  images:
    app:
      image: ghcr.io/example/app
      current:
        env:
          file: .env
          key: APP_VERSION
      discovery: upstream
      filter:
        type: semver
        allow:
          - patch
          - minor

update

型別說明
enabledbool為此服務啟用更新檢查。
auto_applybool自動套用偵測到的更新。
check_schedulestring更新檢查的 cron 排程。
backup_before_updatebool在套用更新前執行備份。
backup_data[]object更新前要備份的受保護資料項目。
digest_pinbool以摘要固定映像檔。
discovery_sourcesmap[string]object可重用的發現來源。具名來源不能引用另一個來源。
imagesmap[string]object每個映像檔的更新定義。

update.backup_data[]

型別說明
namestring受保護資料項目名稱。
enabledbool包含或排除此項目。

update.images.<name>

型別必要說明
imagestring映像檔存放庫。
auto_applybool每個映像檔的自動套用覆蓋。
check_schedulestring每個映像檔的檢查排程。
backup_before_updatebool每個映像檔的備份開關。
digest_pinbool每個映像檔的摘要固定開關。
currentobject目前版本來源。
discoveryobjectstring發現設定或具名發現來源引用。
filterobject條件必要除非發現為 digest,否則為必要項。

current

恰好指定以下之一:

說明
tag靜態目前標籤。
env.file + env.key從 env 檔案讀取目前標籤。file 必須是相對路徑且保持在服務目錄內。
yaml.file + yaml.path從 YAML 檔案讀取目前標籤。file 必須是相對路徑且保持在服務目錄內。

discovery

型別說明
sources[]object至少一個來源。
combinestring空白、mergefirst_success
include_prereleasebool包含預發行版本。

發現來源型別:

型別必要鍵備註
autorepo_url 是可選的,若設定必須是有效 URL。必須是唯一來源。
probe當存在過濾器時需要 semver 過濾器。
registry登錄庫標籤發現。
digest必須是唯一來源。必須省略 filter
githubreporepoowner/repo
gitlabprojectGitLab 專案 ID 或路徑。
forgejoreporepoowner/repo

filter

型別必要鍵備註
semverallow 可包含 patchminormajor
dateformat用於解析標籤的日期格式。
regexpatternorderorder 必須為 numericlexicographic
latest使用最新的候選項。

資料保護

data_protect:
  data:
    - name: db
      backup:
        strategy: database.pgdumpall
        service: postgres
      restore:
        strategy: database.pgimport
        service: postgres
    - name: uploads
      backup:
        strategy: files.copy_after_stop
        include:
          - ./uploads
      restore:
        strategy: files.copy
        include:
          - ./uploads

data_protect.data[]

型別必要說明
namestring唯一的資料項目名稱。
backupobject備份操作。
restoreobject還原操作。

資料操作

型別必要說明
strategystringfiles.copyfiles.copy_after_stopdatabase.pgdumpalldatabase.pgimport
servicestring條件必要database.* 策略的必要項。Compose 服務名稱。
include[]string條件必要files.* 策略的必要項。使用 ./... 或包含 / 的路徑表示服務路徑;裸名表示 Docker 磁碟區名稱。

備份

backup:
  data:
    - name: db
      provider: rustic
      enabled: true
      schedule: "0 2 * * *"
型別必要說明
namestring必須引用具有備份操作的 data_protect.data[].name
providerstring備份提供者名稱。
enabledbool啟用或停用此備份項目。
schedulestringCron 排程。

遷移

migrate:
  data:
    - name: db
      enabled: true
型別必要說明
namestring必須引用同時具有備份和還原操作的 data_protect.data[].name
enabledbool啟用或停用此項目的遷移。
最後更新於 • Renovate Bot