要在Azure中部署的Github操作:错误:找不到模块"@actions/core "

y4ekin9u  于 2022-11-25  发布在  Git
关注(0)|答案(1)|浏览(171)

我在尝试使用此操作“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 }}

请注意,工作流运行良好,直到今天我才遇到此问题。

67up9zun

67up9zun1#

似乎存在依赖模块或权限问题;请确保GitHub操作有足够的权限运行工作流。
检查服务主体的信息。
第一步:

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操作,请确保login-server与映像的完整路径匹配。如果使用完全限定路径,请指定映像示例的完整路径,如docker push xxx.docker.io/repo/image

注意:安装依赖项的操作可能没有那么快,但至少不需要提交依赖项。请确保维护正确的依赖项版本。

相关问题