我正在使用 github 操作使用以下代码在 GCP 容器注册表中构建和推送 docker 映像。
- name: Login to Docker
shell: bash
run: |
echo ${{ secrets.SERVICE_ACCOUNT_KEY }} | docker login -u _json_key --password-stdin
- name: Build and push Docker image
run: |
docker build -t ${{ secrets.GCR_IMAGE_NAME }}:latest .
docker push ${{ secrets.GCR_IMAGE_NAME }}:latest
但是在“登录 Docker”步骤中出现以下错误
***
/home/runner/work/_temp/3ca1e410-1327-4979-bcf4-197df8b88472.sh: line 2: type:: command not found
Error: Process completed with exit code 127.
我已验证使用的 SERVICE_ACCOUNT_KEY 具有“存储管理员”角色。 这里可能有什么问题?
您可以使用市场中的操作来 docker 登录 gcr 或任何其他容器注册表
请参阅此文档了解更多信息 - https://github.com/docker/login-action?tab=readme-ov-file#google-container-registry-gcr
示例:
jobs:
login:
runs-on: ubuntu-latest
steps:
-
name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v1
with:
token_format: access_token
workload_identity_provider: <workload_identity_provider>
service_account: <service_account>
-
name: Login to GCR
uses: docker/login-action@v3
with:
registry: gcr.io
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}