gpt4 book ai didi

python - 从gitlab-ci推送到gcr.io,storage.buckets.在存储管理中获取权限

转载 作者:太空宇宙 更新时间:2023-11-03 20:42:59 24 4
gpt4 key购买 nike

我正在构建一个 gitlab CI 管道,用于构建、测试、推送和部署 React 应用程序。

现在一切都很好,除了将图像推送到 GCR。

这是我的管道部分:

image: docker:stable

stages:
- build
- test
- push-artifacts
- deploy-dev
- deploy-prod

services:
- docker:dind

...

publish:
stage: push-artifacts

script:
- echo "$GCLOUD_SERVICE_KEY" | base64 -d > /gcloud-service-key.json
- cat /gcloud-service-key.json | docker login -u _json_key --password-stdin https://$IMAGE_ROOT
- docker build -t $IMAGE_REPO:$CI_BUILD_REF -f builder/Dockerfile -t $IMAGE_REPO:latest .
- docker push $IMAGE_REPO

我正在使用 gitlab-ci 服务帐户,该帐户同时具有存储管理和存储对象管理 IAM。

我正在使用 dind 和 docker-builder。这是我的构建器 dockerfile

FROM docker:stable

# add dependencies
RUN apk add --update make ca-certificates openssl python curl bash tree git jq && \
update-ca-certificates

WORKDIR /
RUN cd / && wget https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz && \
tar zxvf google-cloud-sdk.tar.gz && \
./google-cloud-sdk/install.sh --usage-reporting=false --path-update=true

# add gcloud to PATH
ENV PATH="/google-cloud-sdk/bin/:${PATH}"

# update and auth
RUN gcloud --quiet components update && \
gcloud components install kubectl

# install helm
RUN curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash
ENV GOOGLE_APPLICATION_CREDENTIALS=/gcloud-service-key.json
RUN helm init --client-only && helm plugin install https://github.com/nouney/helm-gcs

react Dockerfile 只是一个常规的reactapp dockerfile,以 serve 作为命令。但推送部分仍然失败

Successfully built bd60c4bb569e
Successfully tagged eu.gcr.io/project_name/app:46d1e4beea041acef9ca003f452ee4cbda85d5dd
Successfully tagged eu.gcr.io/project_name/app:latest
$ docker push $IMAGE_REPO
The push refers to repository [eu.gcr.io/project_name/app]
11762a30dfcd: Preparing
f475c6042475: Preparing
526599eebb83: Preparing
c328c8c7f46b: Preparing
71d6c8e5f47f: Preparing
48b131779e9d: Preparing
4b2ccfc1ebff: Preparing
2f810bf9ddab: Preparing
968d46c1d20e: Preparing
b87598efb2f0: Preparing
f1b5933fe4b5: Preparing
48b131779e9d: Waiting
4b2ccfc1ebff: Waiting
2f810bf9ddab: Waiting
968d46c1d20e: Waiting
b87598efb2f0: Waiting
f1b5933fe4b5: Waiting
denied: Token exchange failed for project 'project_name'. Caller does not have permission 'storage.buckets.get'. To configure permissions, follow instructions at: https://cloud.google.com/container-registry/docs/access-control

登录成功,但仍然存在权限问题。为什么?

我的 base64 编码服务 token json key 位于 gitlab 环境变量中。

最佳答案

我可以看到您正在使用服务帐户或用户帐户(gcloud-service-key.json 的所有者)来访问您的项目,但您需要向您的帐户添加存储管理员角色,请检查此 link作为授予角色的引用。

关于python - 从gitlab-ci推送到gcr.io,storage.buckets.在存储管理中获取权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56755190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com