【问题标题】:Github action to deploy in Azure : Error: Cannot find module '@actions/core'要在 Azure 中部署的 Github 操作:错误:找不到模块 \'@actions/core\'
【发布时间】:2022-11-23 14:45:56
【问题描述】:

尝试使用此操作“azure/docker-login@v1”构建和推送 docker 映像时,我收到以下错误消息:

Run azure/docker-login@v1
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module '@actions/core'
Require stack:
- /home/runner/work/_actions/azure/docker-login/v1/lib/login.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/runner/work/_actions/azure/docker-login/v1/lib/login.js:13:14)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) ***
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/home/runner/work/_actions/azure/docker-login/v1/lib/login.js' ]
***

这是我的 yaml 工作流程的相关部分:

build-and-deploy:
        needs: [deploy_checks]
        environment: ${{ needs.deploy_checks.outputs.env_name }}
        runs-on: ubuntu-latest
        steps:
        # checkout the repo
        - name: 'Checkout GitHub Action'
          uses: actions/checkout@main
          
        - name: 'Login via Azure CLI'
          uses: azure/login@v1
          with:
            creds: ${{ secrets.AZURE_CREDENTIALS }}
        
        - name: 'Build and push image'
          uses: azure/docker-login@v1
          with:
            login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }}
            username: ${{ secrets.REGISTRY_USERNAME }}
            password: ${{ secrets.REGISTRY_PASSWORD }}
        - run: |
            docker build . -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/image_name:${{ github.sha }}
            docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/image_name:${{ github.sha }}

请注意,直到今天我遇到这个问题之前,工作流程运行良好。

【问题讨论】:

    标签: azure github-actions azure-pipelines-yaml


    【解决方案1】:

    似乎存在依赖模块或权限问题;确保 GitHub 操作具有足够的权限来运行工作流。

    检查服务主体的信息。

    步骤1:

    az ad sp create-for-rbac 
      --name <SERVICE_PRINCIPAL_NAME> 
      --role "contributor" 
      --scopes /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP_NAME> 
      --sdk-auth
    

    结果输出如下:

    {
        "clientId": "<GUID>",
        "clientSecret": "<GUID>",
        "subscriptionId": "<GUID>",
        "tenantId": "<GUID>",
    }
    

    第2步: 需要授予 GitHub Actions SP 拉取和推送图像到 ACR 的权限。

    # Get the id 
    registryId=$(az acr show --name <registry-name> --query id --output tsv)
    
    # Grant the 'AcrPush' role to SP
    az role assignment create --assignee <ClientId> --scope $registryId --role AcrPush
    
    # Grant the 'AcrPull' role to SP
    az role assignment create --assignee <ClientId> --scope $registryId --role AcrPull
    

    如果使用 Docker-login 操作,请确保登录服务器与图像的完整路径匹配。如果它使用完全限定路径,请指定图像示例的整个路径,例如 docker push xxx.docker.io/repo/image

    **注意:安装依赖项的操作没有那么快,这是理所当然的,但至少您不需要提交依赖项。确保维护正确的依赖项版本。 **

    【讨论】:

      猜你喜欢
      • 2021-05-01
      • 2022-10-13
      • 2020-10-16
      • 1970-01-01
      • 2020-09-19
      • 1970-01-01
      • 2021-01-27
      • 2019-12-12
      • 2017-11-05
      相关资源
      最近更新 更多