版本部署者工作流操作是用於連續集成 /連續部署(CI / CD)的自動版本部署。它旨在自動化Web應用程序的部署過程。此操作處理設置環境,安裝依賴項,構建項目(構建軟件包),將其部署到遠程服務器以及將通知發送到Slack。
| 輸入 | 描述 | 必需的 | 預設 |
|---|---|---|---|
| 站點 - 烏爾 | 部署網站URL | 是的 | N/A。 |
| github token | github令牌。這是由GitHub自動提供的。使用默認值$ {{necrets.github_token}}。更多信息 | 是的 | N/A。 |
| Deploy-Pat | 將部署應用程序的遠程服務器上的路徑。 | 是的 | N/A。 |
| 部署主持人 | 遠程服務器的主機名或IP地址。 | 是的 | N/A。 |
| 部署端口 | 遠程服務器的SSH端口(通常22)。 | 是的 | N/A。 |
| 部署用戶 | SSH訪問遠程服務器的用戶名。 | 是的 | N/A。 |
| 部署鍵 | 用於訪問遠程服務器的專用SSH鍵。生成一個SSH鍵 | 是的 | N/A。 |
| 標籤名 | 發行版構建的標籤名稱。 | 是的 | N/A。 |
| 小路 | GitHub Runner上構建目錄的路徑。 | 是的 | 構建/後備/ |
| 開關 | Rsync開關進行部署。這控制了文件同步過程的行為。 Rsync文檔 | 不 | -avzr -exclude =“*。env” -exclude =“ env” -exclude =“。github” -exclude =“。git” - exclude =“。gitignore”。 |
| 鬆弛的webhook | Slack Webhook URL通知。從您的鬆弛設置中獲取此功能。創建Slack Webhooks | 不 | N/A。 |
| 鬆弛通道 | 通知的鬆弛通道。 | 不 | 一般的 |
| 鬆懈的標題 | Slack Notification的標題。 | 不 | 部署了Web應用程序 |
| 鬆懈 | 消息主體,用於鬆弛通知。 | 不 | 部署過程完成。檢查日誌以獲取詳細信息。 |
| Slack-username | 用戶名將顯示為Slack Notification的發件人。 | 不 | WebApp部署機器人 |
| 鬆散的腳 | 步入式通知的頁腳文字。 | 不 | Web應用程序更新狀態 |
| php-version | PHP版本設置 | 不 | 7.4 |
| php延伸 | 安裝的PHP擴展名 | 不 | PCOV |
| 節點version | node.js版本設置 | 不 | 16 |
| 使用php | 是否設置PHP | 不 | 真的 |
| 使用節點 | 是否設置node.js | 不 | 真的 |
| 使用遠重型式安裝 | 是否執行遠程SSH安裝/更新 | 不 | 錯誤的 |
| 上傳釋放資源 | 是否要上傳釋放資產 | 不 | 真的 |
| 釋放文件 | 上傳的文件 | 不 | build.zip; changelog.md |
| 用例 | 是否將緩存用於依賴關係 | 不 | 錯誤的 |
| 上傳藝術 | 是否上傳工件 | 不 | 錯誤的 |
| 人工製品名稱 | 上傳工件的名稱 | 不 | 建築物 |
| 文物路徑 | 工件上傳的途徑 | 不 | 構建/後備/ |
要在工作流中使用此操作,請在github操作工作流文件中包含以下步驟。如果您是GitHub Action的新手,請在存儲庫的根部創建一個.github/workflows目錄,然後添加帶有以下內容的YAML文件(例如, release-deployer.yml ):
基本示例:
name : Release Deployer
on :
pull_request :
types :
- closed
workflow_dispatch :
jobs :
release :
runs-on : ubuntu-latest
steps :
- name : Run release-please
uses : googleapis/release-please-action@v4
id : release
with :
token : ${{ secrets.GITHUB_TOKEN }}
command : manifest
default-branch : main
- name : Run Custom Deployer Action
if : ${{ steps.release.outputs.releases_created }}
uses : devuri/rdx-release-deployer-action@v1
with :
site-url : ${{ secrets.SITE_URL }} # Deployment site URL
github-token : ${{ secrets.GITHUB_TOKEN }} # GitHub Token
deploy-path : ${{ secrets.DEPLOY_PATH }} # Remote deploy path
deploy-host : ${{ secrets.DEPLOY_HOST }} # Remote deploy host
deploy-port : ${{ secrets.DEPLOY_PORT }} # Remote deploy port
deploy-user : ${{ secrets.DEPLOY_USER }} # Remote deploy user
deploy-key : ${{ secrets.DEPLOY_KEY }} # Remote deploy key
tag-name : ${{ steps.release.outputs.tag_name }} # Release tag name
path : build/trunk/ # Path to the build directory on the GitHub runner (default: build/trunk/)
slack-webhook : ${{ secrets.SLACK_WEBHOOK }} # Slack webhook URL for notifications每個參數的註釋示例:
name : Release Deployer
on :
pull_request :
types :
- closed
workflow_dispatch :
jobs :
release :
runs-on : ubuntu-latest
steps :
- name : Run release-please
uses : googleapis/release-please-action@v4
id : release
with :
token : ${{ secrets.GITHUB_TOKEN }}
command : manifest
default-branch : main
- name : Run Custom Deployer Action
if : ${{ steps.release.outputs.releases_created }}
uses : devuri/rdx-release-deployer-action@v1
with :
# Required parameters
site-url : ${{ secrets.SITE_URL }} # Deployment site URL
github-token : ${{ secrets.GITHUB_TOKEN }} # GitHub Token
deploy-path : ${{ secrets.DEPLOY_PATH }} # Remote deploy path
deploy-host : ${{ secrets.DEPLOY_HOST }} # Remote deploy host
deploy-port : ${{ secrets.DEPLOY_PORT }} # Remote deploy port
deploy-user : ${{ secrets.DEPLOY_USER }} # Remote deploy user
deploy-key : ${{ secrets.DEPLOY_KEY }} # Remote deploy key
tag-name : ${{ steps.release.outputs.tag_name }} # Release tag name
# Optional parameters with defaults
path : build/trunk/ # Path to the build directory on the GitHub runner (default: build/trunk/)
switches : ' -avzr --exclude="*.env" --exclude="env" --exclude=".github" --exclude=".git" --exclude=".gitignore" --exclude=".user.ini" ' # Rsync switches for deployment (default: '-avzr --exclude="*.env" --exclude="env" --exclude=".github" --exclude=".git" --exclude=".gitignore" --exclude=".user.ini"')
slack-webhook : ${{ secrets.SLACK_WEBHOOK }} # Slack webhook URL for notifications
slack-channel : general # Slack channel for notifications (default: general)
slack-title : " Web Application Deployed " # Title for the Slack notification (default: "Web Application Deployed")
slack-message : " Deployment process completed. " # Message body for the Slack notification (default: "Deployment process completed. Check logs for details.")
slack-username : " WebApp Deploy Bot " # Username that will appear as the sender of the Slack notification (default: "WebApp Deploy Bot")
slack-footer : " Web Application Update Status " # Footer text for the Slack notification (default: "Web Application Update Status")
# Optional setup parameters with defaults
php-version : ' 7.4 ' # PHP version to setup (default: '7.4')
php-extensions : ' pcov ' # PHP extensions to install (default: 'pcov')
node-version : ' 16 ' # Node.js version to setup (default: '16')
# Boolean flags
use-php : true # Whether to setup PHP (default: true)
use-node : true # Whether to setup Node.js (default: true)
use-remote-install : true # Whether to execute remote SSH updates (default: false)
upload-release-assets : true # Whether to upload release assets (default: true)
# Files to upload to release
release-files : ' build.zip;CHANGELOG.md ' # Files to upload to release (default: 'build.zip;CHANGELOG.md')
在此示例中,工作流程觸發封閉請求的觸發器,也可以通過“ GitHub Action”選項卡手動觸發。它使用googleapis/release-please-action來管理髮行版,然後在創建版本時運行自定義部署操作。
警告
switches中的--delete選項可能很危險,因為它可能導致刪除服務器上重要的文件或內容。
構建目錄: path輸入(默認build/trunk/ )指定使用rsync將文件複製到遠程服務器的目錄。確保構建過程將必要的文件輸出到此目錄,或相應地調整path輸入以匹配您的構建輸出位置。
rsync --delete選項: switches輸入中的--delete選項用於通過刪除不再在本地存在的遠程服務器上的文件來使遠程目錄與本地構建目錄保持同步。這可能是危險的,因為這可能會導致服務器上重要的文件或內容的刪除,例如用戶刪除圖像或其他資產。謹慎使用此選項,以避免意外的數據丟失。考慮將不應通過將其添加到switches輸入中的--exclude列表中的目錄。請參閱:rsync刪除選項
rsync的開關將構建的工件部署到遠程服務器上。set -eo )上執行,該操作可確保如果上一步失敗,則不會執行後續步驟。| 秘密 | 描述 |
|---|---|
GITHUB_TOKEN | 用於身份驗證的github令牌(默認情況下在github操作中提供) |
DEPLOY_PATH | 遠程部署路徑 |
DEPLOY_HOST | 遠程部署主機 |
DEPLOY_PORT | 遠程部署端口 |
DEPLOY_USER | 遠程部署用戶 |
DEPLOY_KEY | 遠程部署密鑰 |
SLACK_WEBHOOK | Slack Webhook URL通知 |
為您的存儲庫添加秘密:
CI/CD是一種通過將自動化引入應用程序開發階段,將應用程序經常傳遞給客戶的方法。歸因於CI/CD的主要概念是連續集成,連續交付和連續部署。此操作通過自動化部署過程來幫助實現CI/CD,確保您的應用程序是
始終處於可部署狀態,並且更新會快速有效地交付給用戶。
通過將此操作納入您的工作流程,您可以實現更可靠,更安全的部署過程,改善開發工作流程,並確保您的應用程序始終如一,迅速地部署。
重要的
GitHub每個月提供一定數量的免費分鐘,具體取決於您的計劃,這對於中小型項目就足夠了。 GitHub操作使用情況是基於運行工作流所需的計算時間,這可能會根據所使用的跑步者和消耗的總分鐘而有所不同。有效地管理使用情況,優化您的工作流程,並考慮使用自託管跑步者進行大型項目。定價計算器。
該項目中的腳本和文檔是根據MIT許可發布的。