MySQL: 1. 建立 access token 並儲存為 CI 機密

此文件屬於GitHub Actions 及 GitLab CI指南的一部分。請在此處查看完整指南:直接於您的 GitHub Actions 或 GitLab CI pipeline 啟動一個真實的 MySQL 服務,執行測試,並自動清理資源

👋 歡迎瀏覽 Stackhero 文件!

Stackhero 提供全託管的 MySQL cloud 服務,讓生產環境的部署與管理變得更簡單:

  • 無限連線及數據傳輸。
  • 內建 phpMyAdmin 網頁介面,輕鬆管理資料庫。
  • 一鍵升級,更新無煩惱。
  • 專屬私有基礎設施上,確保穩定效能高度安全

使用 Stackhero,您只需幾分鐘即可擁有可靠的 MySQL 資料庫。減少安裝與維護的時間,專注於開發您的應用程式。立即體驗 Stackhero 的 MySQL cloud hosting

為了讓 CLI 能以非互動方式運作,您需要一組 access token(格式:usr-xxxxxx:tokenId)。這個 token 只需建立一次,然後將其加入您的 CI pipeline 作為安全加密的機密變數。

  1. 建立 token: 在您的 Stackhero 控制台,點擊右上角的個人頭像,進入 Your account,然後選擇 Access tokens,點擊 Create token
  2. GitHub Actions: 在您的 repository,前往 Settings > Secrets and variables > Actions > New repository secret,將 token 輸入為 STACKHERO_TOKEN
  3. GitLab CI: 在您的專案,前往 Settings > CI/CD > Variables > Add variable,將 key 設為 STACKHERO_TOKEN,並勾選 Masked(如您的 CI 僅於受保護分支執行,亦可勾選 Protected)。

請勿將 access token 直接寫入 pipeline 的 YAML 檔案。若 token 出現在 YAML 中,任何有 repository 存取權的人都可能看到,甚至會出現在 build log。將其儲存為 CI 機密可確保 token 加密且遮蔽,保障您的安全。