我正在尝试构建一个 docker 映像并将其推送到 gcp 工件。但它在 github 操作中失败了。这是我的工作流程 yaml 文件:
on:
push:
branches:
- main
- featurev1
name: Build and Deploy to Cloud Run
env:
REGION: 'europe-west1'
PROJECT_ID: 'myproject'
CLUSTER_NAME: 'myproject-cluster'
LOCATION: 'europe-west1'
ZONE: 'europe-west1'
ARTIFACT_REGISTRY: 'myproject-cust-seg'
TARGET_ENV: 'INT'
NAMESPACE: 'integration'
jobs:
deploy:
runs-on: [ self-hosted ]
# Add "id-token" with the intended permissions.
#permissions:
# contents: 'read'
# id-token: 'write'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup gcloud environment
uses: google-github-actions/setup-gcloud@v0
with:
service_account_key: ${{ secrets.INT_PLATFORM_SERVICE_ACCOUNT_KEY }}
project_id: ${{ env.PROJECT_ID }}
# Alternative option - authentication via credentials json
#- id: 'auth'
# uses: 'google-github-actions/auth@v0'
# with:
# credentials_json: ${{ secrets.INT_PLATFORM_SERVICE_ACCOUNT_KEY }}
- name: Authorize Docker push
run: gcloud auth configure-docker
- name: Build and Push Container
env:
GIT_TAG: ${{ github.run_id }}
run: |-
docker build -t $LOCATION-docker.pkg.dev/$PROJECT_ID/$ARTIFACT_REGISTRY/custapi:$TARGET_ENV-v$GIT_TAG .
docker push $LOCATION-docker.pkg.dev/$PROJECT_ID/$ARTIFACT_REGISTRY/custapi:$TARGET_ENV-v$GIT_TAG
但我有一个错误:
运行 google-github-actions/setup-gcloud@v0 错误:google-github-actions/setup-gcloud 失败:执行命令失败
gcloud --quiet config set project myproject
:警告:无法在 /home/master/.config/gcloud/logs 中设置日志文件, (Could not create directory [/home/master/.config/gcloud/logs/2022.02.10]: Permission denied. 请确认您有写入父目录的权限。配置目录可能不可写。要了解更多信息,请参阅https://cloud.google.com/sdk/docs/configurations#creating_a_configuration 错误:(gcloud.config.set)无法创建默认配置。确保您拥有正确的权限:[/home/master/.config/gcloud/configurations]。无法创建目录 [/home/master/.config/gcloud/configurations]:权限被拒绝。请验证您是否有权写入父目录。
现在我已经在 GitHub 操作中使用服务密钥 json 文件作为机密,因为无密钥身份验证将在不久的将来完成,在第 1 阶段的成功试点之后。所以你可以找到上面的详细信息。
在这里,我将 run-on 称为“自托管”,这是我们的本地 github 操作运行器。