Skip to content

Determine default cache map from Dockerfile#49

Merged
AkihiroSuda merged 7 commits intoreproducible-containers:mainfrom
bennesp:automatic-cache-map-discovery
May 3, 2025
Merged

Determine default cache map from Dockerfile#49
AkihiroSuda merged 7 commits intoreproducible-containers:mainfrom
bennesp:automatic-cache-map-discovery

Conversation

@bennesp
Copy link
Copy Markdown
Contributor

@bennesp bennesp commented Apr 22, 2025

Closes #48 (thank you @omus for sharing a very useful code snippet)

This PR allows users to avoid specifying cache-map: the cache-map will be automatically created by inspecting the AST of the Dockerfile. Of course, users can continue specifying cache-map, in situations where users need more control.

Users can specify a Dockerfile of their choice with the dockerfile option.

For each cache mount, the respective generated cache-map entry is the following:

  • cache-map source: The id of the cache mount if specified, otherwise the target of the cache mount
  • cache-map target: The absolute path of the target (prefixed by the WORKDIR, if any)

Example:

FROM alpine:latest AS builder

# Target absolute path, no id
RUN --mount=type=cache,target=/tmp/cache \
    echo "Hello, World!" > /tmp/cache/hello.txt

# Target relative path with workdir, no id
WORKDIR /app
RUN --mount=type=cache,target=cache1 \
    echo "Hello, World!" > cache/hello.txt

# Multi-stage build
FROM alpine:latest

# Target absolute path with id
RUN --mount=type=cache,id=cache2,target=/tmp/cache \
    echo "Hello, World!" > /tmp/cache/hello.txt

# Target relative path with workdir and id
WORKDIR /app2
RUN --mount=type=cache,id=cache3,target=cache \
    echo "Hello, World!" > cache/hello.txt

This dockerfile will generate the following cache-map:

{
  "/tmp/cache": {
      "id": "/tmp/cache",
      "target": "/var/cache-target"
  },
  "cache1": {
      "id": "cache1",
      "target": "/var/cache-target"
  },
  "cache2": {
      "id": "cache2",
      "target": "/var/cache-target"
  },
  "cache3": {
      "id": "cache3",
      "target": "/var/cache-target"
  }
}

bennesp added 2 commits April 22, 2025 15:03
Signed-off-by: bennesp <bennesp@users.noreply.github.com>
Signed-off-by: bennesp <bennesp@users.noreply.github.com>
@bennesp bennesp force-pushed the automatic-cache-map-discovery branch from 8a21fcd to ff982a4 Compare April 22, 2025 13:03
Copy link
Copy Markdown
Contributor

@omus omus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment thread action.yml
Comment thread src/opts.ts Outdated
Comment thread src/opts.ts Outdated
bennesp added 2 commits April 22, 2025 22:09
Signed-off-by: bennesp <bennesp@users.noreply.github.com>
Signed-off-by: bennesp <bennesp@users.noreply.github.com>
@bennesp bennesp force-pushed the automatic-cache-map-discovery branch from 395734c to 9b9fed1 Compare April 22, 2025 20:12
bennesp added 3 commits April 22, 2025 22:23
Signed-off-by: bennesp <bennesp@users.noreply.github.com>
Signed-off-by: bennesp <bennesp@users.noreply.github.com>
Signed-off-by: bennesp <bennesp@users.noreply.github.com>
@bennesp bennesp force-pushed the automatic-cache-map-discovery branch from dba22cf to 429cead Compare April 22, 2025 20:23
@bennesp
Copy link
Copy Markdown
Contributor Author

bennesp commented May 2, 2025

@AkihiroSuda do you think you could kindly take a look at this PR? 🙏

Copy link
Copy Markdown
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda merged commit 653a570 into reproducible-containers:main May 3, 2025
3 checks passed
@AkihiroSuda
Copy link
Copy Markdown
Member

Next time please consider squashing commits

@bennesp
Copy link
Copy Markdown
Contributor Author

bennesp commented May 3, 2025

Thank you for the quick response, I will squash next time!
Best

github-actions Bot pushed a commit to starkayc/patchy that referenced this pull request Mar 12, 2026
…it-cache-dance action to v3.2.0 (#23)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [https://github.com/reproducible-containers/buildkit-cache-dance](https://github.com/reproducible-containers/buildkit-cache-dance) | action | minor | `v3.1.0` -> `v3.2.0` |

---

### Release Notes

<details>
<summary>reproducible-containers/buildkit-cache-dance (https://github.com/reproducible-containers/buildkit-cache-dance)</summary>

### [`v3.2.0`](https://github.com/reproducible-containers/buildkit-cache-dance/releases/tag/v3.2.0)

[Compare Source](reproducible-containers/buildkit-cache-dance@v3.1.2...v3.2.0)

#### What's Changed

-   Allow overriding container image by [@&#8203;relu](https://github.com/relu) in reproducible-containers/buildkit-cache-dance#44
-   Added support for running with different builder by [@&#8203;ty2](https://github.com/ty2) in reproducible-containers/buildkit-cache-dance#45
-   Determine default cache map from Dockerfile by [@&#8203;bennesp](https://github.com/bennesp) in reproducible-containers/buildkit-cache-dance#49

#### New Contributors

-   [@&#8203;relu](https://github.com/relu) made their first contribution in reproducible-containers/buildkit-cache-dance#44
-   [@&#8203;ty2](https://github.com/ty2) made their first contribution in reproducible-containers/buildkit-cache-dance#45
-   [@&#8203;bennesp](https://github.com/bennesp) made their first contribution in reproducible-containers/buildkit-cache-dance#49

**Full Changelog**: reproducible-containers/buildkit-cache-dance@v3.1.2...v3.2.0

### [`v3.1.2`](https://github.com/reproducible-containers/buildkit-cache-dance/releases/tag/v3.1.2)

[Compare Source](reproducible-containers/buildkit-cache-dance@v3.1.1...v3.1.2)

#### What's Changed

-   Fix not preserving uid and/or gid by [@&#8203;mabrikan](https://github.com/mabrikan) in reproducible-containers/buildkit-cache-dance#35
-   Use sudo to clear cache source during extraction by [@&#8203;rose-m](https://github.com/rose-m) in reproducible-containers/buildkit-cache-dance#37

#### New Contributors

-   [@&#8203;mabrikan](https://github.com/mabrikan) made their first contribution in reproducible-containers/buildkit-cache-dance#35
-   [@&#8203;rose-m](https://github.com/rose-m) made their first contribution in reproducible-containers/buildkit-cache-dance#37

**Full Changelog**: reproducible-containers/buildkit-cache-dance@v3.1.1...v3.1.2

### [`v3.1.1`](https://github.com/reproducible-containers/buildkit-cache-dance/releases/tag/v3.1.1)

[Compare Source](reproducible-containers/buildkit-cache-dance@v3.1.0...v3.1.1)

#### What's Changed

-   Ensure scratch directory exists when calling extractCache by [@&#8203;Chagui-](https://github.com/Chagui-) in reproducible-containers/buildkit-cache-dance#29
-   Do not extract cache on job failure by [@&#8203;borchero](https://github.com/borchero) in reproducible-containers/buildkit-cache-dance#32

#### New Contributors

-   [@&#8203;Chagui-](https://github.com/Chagui-) made their first contribution in reproducible-containers/buildkit-cache-dance#29
-   [@&#8203;borchero](https://github.com/borchero) made their first contribution in reproducible-containers/buildkit-cache-dance#32

**Full Changelog**: reproducible-containers/buildkit-cache-dance@v3.1.0...v3.1.1

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MC4yOS4xIiwidXBkYXRlZEluVmVyIjoiNDAuMjkuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Reviewed-on: https://git.nadeko.net/Fijxu/file-uploader-crystal/pulls/23
Co-authored-by: Renovate Bot <git@nadeko.net>
Co-committed-by: Renovate Bot <git@nadeko.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Determine default cache map from Dockerfile

3 participants