简体   繁体   English

将文件从 Docker 容器上传到 Google Cloud Storage

[英]File upload from Docker container to Google Cloud Storage

I'm putting together a CI/CD pipeline on GKE based on this guide by Google.我正在根据 Google 的本指南在 GKE 上构建 CI/CD 管道。

Everything is working well, except that as it's a Django project I also need to run the collectstatic command and upload the files to Google Storage.一切正常,除了因为它是一个 Django 项目,我还需要运行 collectstatic 命令并将文件上传到 Google Storage。

In the Dockerfile I have the following commands:在 Dockerfile 中,我有以下命令:

RUN python manage.py collectstatic --noinput
RUN gsutil rsync -R /home/vmagent/app/myapp/static gs://mystorage/static

Collectstatic works as expected, but the gsutil upload fails with the following error message: Collectstatic 按预期工作,但 gsutil 上传失败并显示以下错误消息:

ServiceException: 401 Anonymous caller does not have storage.objects.create access to mystorage/static/...

What's the best way to authenticate gsutil?对 gsutil 进行身份验证的最佳方法是什么?

If you are running your docker container on GCP (GKE), you use application credentials to authenticate a pod, which then has the same permissions as that service account.如果您在 GCP (GKE) 上运行您的 docker 容器,您可以使用应用程序凭据对 pod 进行身份验证,然后该 pod 具有与该服务帐户相同的权限。 More information about this can be found here .可以在此处找到有关此的更多信息。 Both GKE and other kubernetes clusters allow you to import key files as secrets. GKE 和其他 kubernetes 集群都允许您将密钥文件作为机密导入。 On all Kubernetes platforms this is done with the following commands.在所有 Kubernetes 平台上,这是通过以下命令完成的。 The full guide can be found here .完整指南可在此处找到。

kubectl create secret generic pubsub-key --from-file=key.json=PATH-TO-KEY-FILE.json

Then set the environment variable in your manifest like this:然后在清单中设置环境变量,如下所示:

 env:
    - name: GOOGLE_APPLICATION_CREDENTIALS
      value: /var/secrets/google/key.json

Too bad running pods under a certain role is not yet possible.太糟糕了,在某个角色下运行 Pod 是不可能的。 GCP operates with service accounts, not with roles like AWS. GCP 使用服务帐户运行,而不是使用 AWS 之类的角色。 In AWS you can assign a role to a task, which grants a container permissions under that role.在 AWS 中,您可以将角色分配给任务,从而授予该角色下的容器权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM