Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache CI Docker images in ghcr registry #119290

Merged
merged 2 commits into from
Jan 29, 2024

Conversation

Kobzol
Copy link
Contributor

@Kobzol Kobzol commented Dec 25, 2023

This PR changes the way rust-lang caches Docker images used in CI workflows. Before, the intermediate Docker layers were manually exported from docker history and backed up in S3. However, this approach doesn't work any more with the Docker version used by GitHub Actions since August 2023. We had to revert to disabling Docker BuildKit to make the old caching work, but this workaround will stop working eventually, after GitHub updates Docker again and the old build backend will be removed.

This PR changes the caching to use Docker caching instead. There are several backends for the cache, for our use-case S3 and Docker registry makes sense. This PR uses the Docker registry backend and uses the ghcr.io registry.

The caching creates a Docker image labeled rust-ci, which is currently stored to the ghcr.io/rust-lang-ci package registry. This image appears here. The image is stored in rust-lang-ci and not rust-lang, because try and auto builds run in the context of that repository, so the used GITHUB_TOKEN has permissions for it (unlike for rust-lang).

For pull request CI runs, the provided GITHUB_TOKEN reduces its permissions automatically to packages: read, which means that we won't be able to write the Docker image. If we're not able to write, we won't have anything to read. So I disabled the caching entirely for PR runs (it makes it slightly faster to build the Docker image if we don't have to deal with exporting and using a separate build driver). Note that before this PR, we also weren't able to read or write the cache on PR runs.

Rustup part of this change is here.

Related issue: rust-lang/infra-team#81

r? @Mark-Simulacrum

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Dec 25, 2023
@rust-log-analyzer

This comment has been minimized.

@Mark-Simulacrum
Copy link
Member

@bors try

This broadly looks fine to me -- is there a reason I don't see try builds etc. on this PR? I think we should test out that it works on try + local builds (src/ci/docker/run.sh from your laptop or w/e), and perhaps get rustup CI working, and then we can merge.

@bors
Copy link
Contributor

bors commented Dec 29, 2023

⌛ Trying commit 6f90144 with merge a4cbdba...

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 29, 2023
…try>

Cache CI Docker images in ghcr registry

This PR changes the way `rust-lang` caches Docker images used in CI workflows. Before, the intermediate Docker layers were manually exported from `docker history` and backed up in S3. However, this approach doesn't work any more with the Docker version used by GitHub Actions since August 2023. We had to revert to disabling Docker BuildKit to make the old caching work, but this workaround will stop working eventually, after GitHub updates Docker again and the old build backend will be removed.

This PR changes the caching to use [Docker caching](https://docs.docker.com/build/cache/) instead. There are several backends for the cache, for our use-case S3 and Docker registry makes sense. This PR uses the Docker registry backend and uses the ghcr.io registry.

The caching creates a Docker image labeled `rust-ci`, which is currently stored to the `ghcr.io/rust-lang-ci` package registry. This image appears [here](https://ghcr.io/rust-lang-ci/rust-ci). The image is stored in `rust-lang-ci` and not `rust-lang`, because `try` and `auto` builds run in the context of that repository, so the used `GITHUB_TOKEN` has permissions for it (unlike for `rust-lang`).

For pull request CI runs, the provided `GITHUB_TOKEN` reduces its permissions automatically to `packages: read`, which means that we won't be able to write the Docker image. If we're not able to write, we won't have anything to read. So I disabled the caching entirely for PR runs (it makes it slightly faster to build the Docker image if we don't have to deal with exporting and using a separate build driver). Note that before this PR, we also weren't able to read or write the cache on PR runs.

Related issue: rust-lang/infra-team#81

r? `@Mark-Simulacrum`
@Kobzol
Copy link
Contributor Author

Kobzol commented Dec 29, 2023

is there a reason I don't see try builds etc. on this PR

I tested a try build on a different PR, but we should of course also try it here.

What I'm struggling with currently is how to use the cache as a docker pull-able image from rustup. It doesn't seem to be possible to pull the cached images from the repository.

@bors
Copy link
Contributor

bors commented Dec 29, 2023

☀️ Try build successful - checks-actions
Build commit: a4cbdba (a4cbdbac0b250cb863eca2c0f95c92800fc3ed6c)

@Kobzol
Copy link
Contributor Author

Kobzol commented Dec 29, 2023

@bors try

@bors
Copy link
Contributor

bors commented Dec 29, 2023

⌛ Trying commit 6f90144 with merge 180eb9e...

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 29, 2023
…try>

Cache CI Docker images in ghcr registry

This PR changes the way `rust-lang` caches Docker images used in CI workflows. Before, the intermediate Docker layers were manually exported from `docker history` and backed up in S3. However, this approach doesn't work any more with the Docker version used by GitHub Actions since August 2023. We had to revert to disabling Docker BuildKit to make the old caching work, but this workaround will stop working eventually, after GitHub updates Docker again and the old build backend will be removed.

This PR changes the caching to use [Docker caching](https://docs.docker.com/build/cache/) instead. There are several backends for the cache, for our use-case S3 and Docker registry makes sense. This PR uses the Docker registry backend and uses the ghcr.io registry.

The caching creates a Docker image labeled `rust-ci`, which is currently stored to the `ghcr.io/rust-lang-ci` package registry. This image appears [here](https://ghcr.io/rust-lang-ci/rust-ci). The image is stored in `rust-lang-ci` and not `rust-lang`, because `try` and `auto` builds run in the context of that repository, so the used `GITHUB_TOKEN` has permissions for it (unlike for `rust-lang`).

For pull request CI runs, the provided `GITHUB_TOKEN` reduces its permissions automatically to `packages: read`, which means that we won't be able to write the Docker image. If we're not able to write, we won't have anything to read. So I disabled the caching entirely for PR runs (it makes it slightly faster to build the Docker image if we don't have to deal with exporting and using a separate build driver). Note that before this PR, we also weren't able to read or write the cache on PR runs.

Related issue: rust-lang/infra-team#81

r? `@Mark-Simulacrum`
@bors
Copy link
Contributor

bors commented Dec 29, 2023

☀️ Try build successful - checks-actions
Build commit: 180eb9e (180eb9e1b26bc11a3ca55fbebfda4b32af2541f4)

@Mark-Simulacrum
Copy link
Member

@rustbot author

Let me know if I can/should try to help here, otherwise will put this in waiting on author for now.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 31, 2023
@Kobzol Kobzol force-pushed the ci-docker-registry-cache branch 2 times, most recently from 7dae399 to 41ef4a5 Compare January 21, 2024 13:29
@Kobzol
Copy link
Contributor Author

Kobzol commented Jan 21, 2024

@bors try

@bors
Copy link
Contributor

bors commented Jan 21, 2024

⌛ Testing commit 8bb6a1b with merge 0872387...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 21, 2024
Cache CI Docker images in ghcr registry

This PR changes the way `rust-lang` caches Docker images used in CI workflows. Before, the intermediate Docker layers were manually exported from `docker history` and backed up in S3. However, this approach doesn't work any more with the Docker version used by GitHub Actions since August 2023. We had to revert to disabling Docker BuildKit to make the old caching work, but this workaround will stop working eventually, after GitHub updates Docker again and the old build backend will be removed.

This PR changes the caching to use [Docker caching](https://docs.docker.com/build/cache/) instead. There are several backends for the cache, for our use-case S3 and Docker registry makes sense. This PR uses the Docker registry backend and uses the ghcr.io registry.

The caching creates a Docker image labeled `rust-ci`, which is currently stored to the `ghcr.io/rust-lang-ci` package registry. This image appears [here](https://ghcr.io/rust-lang-ci/rust-ci). The image is stored in `rust-lang-ci` and not `rust-lang`, because `try` and `auto` builds run in the context of that repository, so the used `GITHUB_TOKEN` has permissions for it (unlike for `rust-lang`).

For pull request CI runs, the provided `GITHUB_TOKEN` reduces its permissions automatically to `packages: read`, which means that we won't be able to write the Docker image. If we're not able to write, we won't have anything to read. So I disabled the caching entirely for PR runs (it makes it slightly faster to build the Docker image if we don't have to deal with exporting and using a separate build driver). Note that before this PR, we also weren't able to read or write the cache on PR runs.

Related issue: rust-lang/infra-team#81

r? `@Mark-Simulacrum`
@Kobzol
Copy link
Contributor Author

Kobzol commented Jan 21, 2024

@bors try

@Kobzol
Copy link
Contributor Author

Kobzol commented Jan 21, 2024

The Rustup part of this change is at: rust-lang/rustup#3648. Local build seems to work.

@rust-log-analyzer

This comment has been minimized.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 27, 2024
@bors
Copy link
Contributor

bors commented Jan 27, 2024

⌛ Testing commit da5ab5e with merge ea585a9...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 27, 2024
…ark-Simulacrum

Cache CI Docker images in ghcr registry

This PR changes the way `rust-lang` caches Docker images used in CI workflows. Before, the intermediate Docker layers were manually exported from `docker history` and backed up in S3. However, this approach doesn't work any more with the Docker version used by GitHub Actions since August 2023. We had to revert to disabling Docker BuildKit to make the old caching work, but this workaround will stop working eventually, after GitHub updates Docker again and the old build backend will be removed.

This PR changes the caching to use [Docker caching](https://docs.docker.com/build/cache/) instead. There are several backends for the cache, for our use-case S3 and Docker registry makes sense. This PR uses the Docker registry backend and uses the ghcr.io registry.

The caching creates a Docker image labeled `rust-ci`, which is currently stored to the `ghcr.io/rust-lang-ci` package registry. This image appears [here](https://ghcr.io/rust-lang-ci/rust-ci). The image is stored in `rust-lang-ci` and not `rust-lang`, because `try` and `auto` builds run in the context of that repository, so the used `GITHUB_TOKEN` has permissions for it (unlike for `rust-lang`).

For pull request CI runs, the provided `GITHUB_TOKEN` reduces its permissions automatically to `packages: read`, which means that we won't be able to write the Docker image. If we're not able to write, we won't have anything to read. So I disabled the caching entirely for PR runs (it makes it slightly faster to build the Docker image if we don't have to deal with exporting and using a separate build driver). Note that before this PR, we also weren't able to read or write the cache on PR runs.

Rustup part of this change is [here](rust-lang/rustup#3648).

Related issue: rust-lang/infra-team#81

r? `@Mark-Simulacrum`
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jan 27, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 27, 2024
@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 28, 2024
@Kobzol
Copy link
Contributor Author

Kobzol commented Jan 28, 2024

@bors r=Mark-simulacrum

(This run will fail, but I added additional logging to help me debug the used Docker version on our self-hosted runners).

@bors
Copy link
Contributor

bors commented Jan 28, 2024

📌 Commit 09e0d4f has been approved by Mark-simulacrum

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 28, 2024
@bors
Copy link
Contributor

bors commented Jan 29, 2024

⌛ Testing commit 09e0d4f with merge 7e43442...

@bors
Copy link
Contributor

bors commented Jan 29, 2024

☀️ Test successful - checks-actions
Approved by: Mark-simulacrum
Pushing 7e43442 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 29, 2024
@bors bors merged commit 7e43442 into rust-lang:master Jan 29, 2024
12 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 29, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (7e43442): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.9% [2.9%, 2.9%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.2% [-3.4%, -3.0%] 2
All ❌✅ (primary) 2.9% [2.9%, 2.9%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 660.85s -> 661.466s (0.09%)
Artifact size: 308.02 MiB -> 308.03 MiB (0.00%)

@Kobzol Kobzol deleted the ci-docker-registry-cache branch January 29, 2024 07:40
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 15, 2024
…acrum

CI: cache PR CI Docker builds

An attempt to restore Docker caching for PR CI workflows that share the Docker image with an auto/try workflow.

This was broken by my previous [PR](rust-lang#119290) that changed how we cache the Docker builds.

[Before](rust-lang#122545):
![image](https://github.com/rust-lang/rust/assets/4539057/05e0d347-af64-4e85-bc99-0e4ac07192ec)

After:
![image](https://github.com/rust-lang/rust/assets/4539057/2f657d60-b242-45eb-ac61-d8f71787edda)

r? `@ghost`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 15, 2024
…acrum

CI: cache PR CI Docker builds

An attempt to restore Docker caching for PR CI workflows that share the Docker image with an auto/try workflow.

This was broken by my previous [PR](rust-lang#119290) that changed how we cache the Docker builds.

[Before](rust-lang#122545):
![image](https://github.com/rust-lang/rust/assets/4539057/05e0d347-af64-4e85-bc99-0e4ac07192ec)

After:
![image](https://github.com/rust-lang/rust/assets/4539057/2f657d60-b242-45eb-ac61-d8f71787edda)

r? ``@ghost``
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 15, 2024
Rollup merge of rust-lang#122563 - Kobzol:ci-pr-caching, r=Mark-Simulacrum

CI: cache PR CI Docker builds

An attempt to restore Docker caching for PR CI workflows that share the Docker image with an auto/try workflow.

This was broken by my previous [PR](rust-lang#119290) that changed how we cache the Docker builds.

[Before](rust-lang#122545):
![image](https://github.com/rust-lang/rust/assets/4539057/05e0d347-af64-4e85-bc99-0e4ac07192ec)

After:
![image](https://github.com/rust-lang/rust/assets/4539057/2f657d60-b242-45eb-ac61-d8f71787edda)

r? ``@ghost``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants