我构建了一个Azure静态Web应用程序,它有一个API函数,只有一个依赖项。此依赖位于GitHub上的私有存储库中。在本地开发机器上,我可以通过使用SSH身份验证下载依赖项来构建函数应用程序。当尝试使用GitHub操作部署到Azure时,我得到了错误Host key verification failed。
我的GitHub操作工作流类似于authentication生成的默认工作流,添加了使用webfactory/ssh-agent在GitHub上进行SSH身份验证以检索私有存储库Y的功能,并为测试目的使用git clone运行步骤:
# ... Same as on https://learn.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://learn.microsoft.com/en-us/azure/static-web-apps/github-actions-workflow在我的私有存储库Y中,我添加了与私钥secrets.SSH_PRIVATE关联的公钥作为部署密钥。
运行工作流后,它将显示git clone命令正确运行,因为ls -la命令会在我的私有存储库中显示目录和文件。但是,my API (yarn install --prefer-offline --production)的构建过程会导致纱取包时出现错误Host key verification failed。因此,GitHub操作无法在我的私有存储库中下载依赖项,也无法构建API。这将以失败的工作流结束。
发布于 2021-04-02 05:46:09
在分析Azure/static-web-apps-deploy@v0.0.1-preview之后,我注意到它使用羚羊为Azure的构建过程启动了一个Docker容器。这个容器不知道在主机VM上使用webfactory/ssh-agent初始化的ssh代理。因此,在yarn install中触发的Azure/static-web-apps-deploy@v0.0.1-preview无法下载我的私有存储库中的依赖项,并导致安装失败。
为了避免这种情况,我重构了我的私有依赖项,将其作为git子模使用,因为子模块可以在构建过程之前使用actions/checkout加载。这是通过在Azure静态Web应用程序生成的工作流文件中添加两行代码来实现的。我在下面的工作流文件片段中用尾随的# 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
...https://stackoverflow.com/questions/66894919
复制相似问题