RustFS: 6. GitLab CI

本文件是在 CI/CD 中自動啟用與測試 RustFS 服務指南的一部分。請在此處查看完整指南:透過 GitHub Actions 或 GitLab CI pipeline 啟動真實的 RustFS 服務,執行測試並自動銷毀。

👋 歡迎使用 Stackhero 文件!

Stackhero 提供即時可用的 RustFS Object Storage 平台,專為高可靠性與高速效能設計。主要優勢包括:

  • 無限制資料傳輸,無任何隱藏費用。
  • 簡單、可預測且透明的計價。
  • 以HTTPS 保護的自訂網域名稱(例如 https://object-storage.your-company.com)。
  • 一鍵即可關閉網頁主控台與管理 API 的網際網路存取。
  • 一鍵升級,全自動、無需人工操作。
  • 專屬私有基礎架構,確保高效能與安全性。
  • 支援🇪🇺 歐洲與🇺🇸 美國地區。

簡化您的工作流程,縮短部署時間:您只需 5 分鐘即可完成 Stackhero RustFS Object Storage hosting 的部署。

請將下列內容儲存為 .gitlab-ci.yml。每次 pipeline 執行時都會建立一個全新的 RustFS 實例供測試使用。

test:
  image: ubuntu:24.04
  timeout: 30m
  variables:
    STACK: "CI"                           # 步驟 2 建立的 stack
    INSTANCE: "100G"   # 可依需求調整(見步驟 4)
    REGION: "europe"
    SERVICE_STORE: "rustfs"
  # STACKHERO_TOKEN 來自您於步驟 1 建立的 CI/CD 變數。
  script:
    - set -euo pipefail
    - apt-get update && apt-get install -y --no-install-recommends ca-certificates jq curl awscli
    - curl -fsSL https://www.stackhero.io/install.sh | sh
    - SERVICE_ID=$(stackhero --format=script service-add --stack="$STACK" --service-store="$SERVICE_STORE" --instance="$INSTANCE" --region="$REGION")
    - echo "SERVICE_ID=$SERVICE_ID" > service.env
    - timeout 15m stackhero service-wait-for --service="$SERVICE_ID"
    - config=$(stackhero service-configuration-get --service="$SERVICE_ID" --format=json)
    - host=$(echo "$config" | jq -r '.configuration.domain')
    - accessKey=$(echo "$config" | jq -r '.configuration.credentials.rootUser')
    - secretKey=$(echo "$config" | jq -r '.configuration.credentials.rootPassword')
    # List the buckets with the AWS CLI (S3-compatible).
    - AWS_ACCESS_KEY_ID="$accessKey" AWS_SECRET_ACCESS_KEY="$secretKey" \
    -   aws --endpoint-url "https://$host" s3 ls
    - echo "✅ RustFS 已可從 CI 存取。"
    # 您也可以在此使用上述認證資訊執行自訂測試 ...
  after_script:
    - test -f service.env && . ./service.env || true
    - >
      if [ -n "${SERVICE_ID:-}" ]; then
        stackhero service-delete --service="$SERVICE_ID" --confirm
      fi

在 GitLab 中,刪除服務的動作會寫在 after_script。這個區塊即使在 job 失敗時也會執行,確保您的 RustFS 服務被移除,不會產生不必要的費用。

在 GitLab,after_script 會在全新 shell中執行。為了處理這種情況,腳本會在新增服務時將服務 ID 寫入 service.env,刪除前再讀取。即使 job 執行中途失敗,也能確保服務被正確刪除。