Ruby: 配置 GitHub Actions 工作流
本文档属于使用 GitHub Actions 部署指南的一部分。您可以在此处查看完整指南:如何使用 GitHub Actions 部署您的 Ruby 代码。
👋 欢迎来到 Stackhero 文档!
Stackhero 提供了一种即用型 Ruby 云 解决方案,具有众多优势,包括:
- 通过简单的
git push在几秒钟内 部署您的应用程序。- 使用您自己的域名,并享受 HTTPS 证书的自动配置以增强安全性。
- 享受自动备份、一键更新以及简单、透明和可预测的定价带来的安心。
- 通过私有和专用的 VM获得最佳的性能和强大的安全性。
节省时间并简化您的生活:尝试 Stackhero 的 Ruby 云托管 解决方案只需 5 分钟!
在本地机器的 Git 仓库中,创建一个名为 .github/workflows 的目录。在该目录下新建一个名为 deploy-to-stackhero.yml 的文件。
# 文件:.github/workflows/deploy-to-stackhero.yml
name: Deploy to Stackhero
run-name: Deploy branch "${{ github.ref_name }}" to Stackhero
on:
push:
# 下面的分支列表会在 git push 时触发部署操作。
# 请确保在 GitHub 的 "Settings"/"Environments" 中为每个分支创建对应的环境。
# 然后在该环境下添加相应的密钥 "STACKHERO_SSH_PRIVATE_KEY" 和变量 "STACKHERO_ENDPOINT"。
branches: [ "production", "staging" ]
jobs:
Deploy:
environment: ${{ github.ref_name }}
runs-on: ubuntu-latest
steps:
- uses: stackhero-io/github-actions-deploy-to-stackhero@v1
with:
# 密钥 "STACKHERO_SSH_PRIVATE_KEY" 和变量 "STACKHERO_ENDPOINT" 需要在 GitHub 的 "Settings"/"Environments" 下对应分支的环境中定义。
ssh_private_key: ${{ secrets.STACKHERO_SSH_PRIVATE_KEY }}
endpoint: ${{ vars.STACKHERO_ENDPOINT }}
创建好工作流文件后,您可以提交更改。
git add -A .
git commit -m "Add GitHub Actions to deploy to Stackhero"
接下来,创建 production 分支。
git checkout -b production
最后,将更改推送到 GitHub。
git push --set-upstream origin production
最后一次 git push 会将您的代码上传到 GitHub 的 production 分支。GitHub Actions 会自动启动并将您的代码部署到 Stackhero 实例。
要查看工作流执行情况,请访问项目的 GitHub 页面并点击 Actions。
GitHub Actions 部署到生产环境
恭喜,您已成功通过 GitHub Actions 实现了生产环境的持续部署。