简体   繁体   English

我可以从 Google Cloud Storage artifacts 存储桶中删除容器映像吗?

[英]Can I delete container images from Google Cloud Storage artifacts bucket?

I have a Google App Engine app, which connects to Google Cloud Storage.我有一个 Google App Engine 应用程序,它连接到 Google Cloud Storage。

I noticed that the amount of data stored was unreasonably high (4.01 GB, when it should be 100MB or so).我注意到存储的数据量高得不合理(4.01 GB,应该是 100MB 左右)。

So, I looked at how much each bucket was storing, and I found that there was an automatically created bucket called us.artificats.因此,我查看了每个存储桶的存储量,发现有一个自动创建的存储桶,名为us.artificats. that was taking up most of the space.那占据了大部分空间。

I looked inside, and all it has is one folder: containers/images/ .我往里面看了看,里面只有一个文件夹: containers/images/

From what I've Googled, it seems like these images come from Google Cloud Build.从我用 Google 搜索的内容来看,这些图像似乎来自 Google Cloud Build。

My question is, can I delete them without compromising my entire application?我的问题是,我可以在不影响整个应用程序的情况下删除它们吗?

I have solved this problem by applying a deletion rule.我通过应用删除规则解决了这个问题。 Here's how to do it:这是如何做到的:

  1. Open the project in Google Cloud console在 Google Cloud Console 中打开项目
  2. Open the storage management (search for "Storage" for example).打开存储管理(例如搜索“存储”)。
  3. In the Browser tab, select the container us.artifacts... .浏览器选项卡中,选择容器us.artifacts...
  4. Now, open the Lifecycle section.现在,打开生命周期部分。 You should see something like:你应该看到类似的东西:

在此处输入图片说明

  1. Click on Add a rule and provide the following conditions:单击添加规则并提供以下条件:
    1. In the action, select Delete object在操作中,选择删除对象
    2. In the conditions, select Age and enter for example 3 days在条件中,选择年龄并输入例如3 天
  2. Click on create to confirm the creation点击创建确认创建

Now all objects older than 3 days will be automatically deleted.现在所有超过 3 天的对象都将被自动删除。 It might take a few minutes for this new rule to be applied by Google Cloud. Google Cloud 可能需要几分钟时间才能应用此新规则。

For those of you seeing this later on, I ended up deleting the folder, and everything was fine.对于那些稍后看到这一点的人,我最终删除了该文件夹,一切都很好。

When I ran Google Cloud Build again, it added items back into the bucket, which I had to delete later on.当我再次运行 Google Cloud Build 时,它将项目重新添加到存储桶中,我稍后不得不将其删除。

As @HarshitG mentioned, this can be set up to happen automatically via deletion rules in cloud storage.正如@HarshitG 提到的,这可以设置为通过云存储中的删除规则自动发生。 As for myself, I added a deletion step to my deployment GitHub action.至于我自己,我在我的部署 GitHub 操作中添加了删除步骤。

Here is the reference to the documentation.这是对文档的参考。 https://cloud.google.com/appengine/docs/standard/go/testing-and-deploying-your-app#managing_build_images https://cloud.google.com/appengine/docs/standard/go/testing-and-deploying-your-app#managing_build_images

Built container images are stored in the app-engine folder in Container Registry.构建的容器映像存储在 Container Registry 的 app-engine 文件夹中。 You can download these images to keep or run elsewhere.您可以下载这些图像以在其他地方保存或运行。 Once deployment is complete, App Engine no longer needs the container images.部署完成后,App Engine 不再需要容器映像。 Note that they are not automatically deleted, so to avoid reaching your storage quota, you can safely delete any images you don't need.请注意,它们不会自动删除,因此为避免达到您的存储配额,您可以安全地删除任何不需要的图像。 For more information about managing images in Container Registry, see the Container Registry documentation.有关在 Container Registry 中管理映像的更多信息,请参阅 Container Registry 文档。

This can be automated by adding a Lifecycle rules like @HarshitG mentioned.这可以通过添加像@HarshitG 提到的生命周期规则来自动化。 在此处输入图片说明

Same issue.同样的问题。 Thanks for the update, Caleb.感谢您的更新,凯勒。

I'm having the same issue, but I don't have an App running;我有同样的问题,但我没有运行应用程序; I just have:我只有:

  • Firebase Auth Firebase 身份验证
  • Firestore火店
  • Firebase Functions Firebase 函数
  • Cloud Storage云储存

Not sure why I have 4GB stored in those containers, and I'm not sure if I should delete them or if that would break my functions.不知道为什么我在这些容器中存储了 4GB,我不确定是否应该删除它们或者这是否会破坏我的功能。

UPDATE: I deleted the container folder and all still works.更新:我删除了容器文件夹,一切仍然有效。 Not sure if those are backups or whatnot, but I can't find anything online or in the docs.不确定这些是备份还是诸如此类,但我在网上或文档中找不到任何内容。 I will post here if something happens.如果发生什么事,我会在这里发布。 As soon as a cloud function ran, the folder had 33 files again.云功能一运行,该文件夹又包含 33 个文件。

You can add a trigger to your lifecycle rules on console.cloud.google.com .您可以在console.cloud.google.com上为生命周期规则添加触发器。

  1. Access the bucket with artifacts (default is "us.artifacts.yourAppName.appspot.com")使用工件访问存储桶(默认为“us.artifacts.yourAppName.appspot.com”)
  2. Go to "Life cycle".转到“生命周期”。
  3. Click on "Add a rule".单击“添加规则”。
  4. Check "Object delete" and press "Continue".选中“对象删除”,然后按“继续”。
  5. Check the filter to delete the bucket, I chose "age" and selected three days as the number of auto delete old elements (after element has 3 days of life it's auto deleted).检查过滤器以删除存储桶,我选择了“年龄”并选择了三天作为自动删除旧元素的数量(元素生命周期为 3 天后会自动删除)。
  6. Click on "Create" and the rule is working now, then you do not need to visit every day to clean the bucket.点击“创建”,现在规则生效了,那么你就不用每天都来清理桶了。

I recommend against setting up a lifecycle rules on your Storage buckets.我建议不要在您的存储桶上设置生命周期规则。 It will likely lead to breaking subsequent updates to the function (as described in Cloud Function build error - failed to get OS from config file for image )它可能会导致对函数的后续更新中断(如Cloud Function build error - failed to get OS from config file for image 中所述

If you are interested in cleaning up container images, you should instead delete container images stored in Google Cloud Registry https://console.cloud.google.com/gcr .如果您对清理容器镜像感兴趣,您应该删除存储在 Google Cloud Registry https://console.cloud.google.com/gcr 中的容器镜像。 Deleting container images on GCR repos will automatically cleanup objects stored in your Cloud Storage.删除 GCR 存储库上的容器映像将自动清理存储在 Cloud Storage 中的对象。

https://issuetracker.google.com/issues/186832976 has relevant information from a Google Cloud Functions engineer. https://issuetracker.google.com/issues/186832976有来自 Google Cloud Functions 工程师的相关信息。

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

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