如何配置GitHub操作以构建依赖于私有存储库的Azure Static Web App? [英] How can I configure GitHub Actions to build my Azure Static Web App with a dependency on a private repository?
本文介绍了如何配置GitHub操作以构建依赖于私有存储库的Azure Static Web App?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用一个具有一个依赖项的API函数构建了一个Azure Static Web App。该依赖项位于GitHub上的私有存储库中。在我的本地开发机器上,我能够通过使用SSH身份验证下载依赖项来构建函数应用程序。尝试使用GitHub操作部署到Azure时出现错误Host key verification failed
。
我的GitHub操作工作流类似于Azure Static Web App生成的默认工作流,除了使用webfactory/ssh-agent促进GitHub上的SSH身份验证以检索私有存储库Y和用于测试目的的git clone
运行步骤:
# ... Same as on https://docs.microsoft.com/en-us/azure/static-web-apps/github-actions-workflow
jobs:
build_and_deploy_job:
runs-on: ubuntu-latest
name: Build and Deploy Job
steps:
- uses: actions/checkout@v2
with:
submodules: true
persist-credentials: false
- uses: webfactory/ssh-agent@v0.5.1
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE }}
- run: |
git clone ssh://git@github.com/X/Y.git Z
ls -la Z
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v0.0.1-preview
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_TOKEN }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
action: "upload"
app_location: "/"
api_location: "api"
output_location: "build"
# ... Same as on https://docs.microsoft.com/en-us/azure/static-web-apps/github-actions-workflow
在我的专用存储库Y中,我已将与私钥secrets.SSH_PRIVATE
关联的公钥添加为部署密钥。
git clone
命令运行正确,因为ls -la
命令导致显示我的专用存储库中的目录和文件。但是,在我的接口(yarn install --prefer-offline --production
)的构建过程中,Year拉取包的时候会出现Host key verification failed
错误。因此,GitHub操作不能将依赖项下载到我的私有存储库中,也不能构建API。这以失败的工作流结束。
推荐答案
分析Azure/static-web-apps-deploy@v0.0.1-preview
后,我注意到它使用Oryx为Azure静态Web App的构建过程启动一个Docker容器。此容器不知道在主机VM上使用webfactory/ssh-agent
初始化的ssh代理。因此,在Azure/static-web-apps-deploy@v0.0.1-preview
中触发的yarn install
无法下载我的专用存储库中的依赖项,安装失败。
actions/checkout
加载子模块。这是通过向Azure Static Web Apps生成的工作流文件添加两行额外代码来实现的。在我的工作流文件的以下片段中,我用尾随的# ADDED
突出显示了这两行:
jobs:
build_and_deploy_job:
runs-on: ubuntu-latest
name: Build and Deploy Job
steps:
- uses: actions/checkout@v2
with:
ssh-known-hosts: "github.com" # ADDED
ssh-key: ${{ secrets.SSH_PRIVATE }} # ADDED
submodules: true
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v0.0.1-preview
...
这篇关于如何配置GitHub操作以构建依赖于私有存储库的Azure Static Web App?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文