Skip to content

Commit

Permalink
Merge pull request #28 from aminya/support-cache-props
Browse files Browse the repository at this point in the history
feat: support arbitrary mount options for each cache
  • Loading branch information
AkihiroSuda committed Apr 8, 2024
2 parents 8da9ff0 + 2a1e987 commit 5de31fc
Show file tree
Hide file tree
Showing 14 changed files with 1,128 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
name: Test
name: Actions Test
on:
push:
pull_request:
jobs:
test:
actions_test:
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
Expand All @@ -30,7 +30,10 @@ jobs:
skip-extraction: false
cache-map: |
{
"var-cache-apt": "/var/cache/apt",
"var-cache-apt": {
"target": "/var/cache/apt",
"id": "1"
},
"var-lib-apt": "/var/lib/apt"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check Dist
name: Tests

on:
pull_request:
Expand All @@ -8,8 +8,7 @@ permissions:
contents: read

jobs:
check-dist:
name: Check dist/
tests:
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -44,3 +43,6 @@ jobs:
name: dist
path: dist/
retention-days: 10

- name: Run Tests
run: pnpm run test
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
key: cache-${{ hashFiles('.github/workflows/test/Dockerfile') }}

- name: inject cache into docker
uses: reproducible-containers/buildkit-cache-dance@v3.0.0
uses: reproducible-containers/buildkit-cache-dance@v3.1.0
with:
cache-map: |
{
Expand All @@ -85,24 +85,43 @@ Real-world examples:
- <https://github.com/rootless-containers/slirp4netns/blob/v1.2.2/.github/workflows/release.yaml#L18-L36>
- <https://github.com/containers/fuse-overlayfs/blob/40e0f3c/.github/workflows/release.yaml#L17-L36>

## CacheMap Options

Optionally, instead of a single string for the `target`, you can provide an object with additional options that should be passed to `--mount=type=cache` in the values `cache-map` JSON. The `target` path must be present in the object as a property.

```yaml
- name: inject cache into docker
uses: reproducible-containers/buildkit-cache-dance@v3.1.0
with:
cache-map: |
{
"var-cache-apt": {
"target": "/var/cache/apt",
"id": "1"
},
"var-lib-apt": "/var/lib/apt"
}
skip-extraction: ${{ steps.cache.outputs.cache-hit }}
```

## CLI Usage

In other CI systems, you can run the script directly via `node`:

```shell
curl -LJO https://github.com/reproducible-containers/buildkit-cache-dance/archive/refs/tags/v3.0.0.tar.gz
tar xvf buildkit-cache-dance-3.0.0.tar.gz
curl -LJO https://github.com/reproducible-containers/buildkit-cache-dance/archive/refs/tags/v3.1.0.tar.gz
tar xvf buildkit-cache-dance-3.1.0.tar.gz
```
During injection:

```shell
node ./buildkit-cache-dance-3.0.0/dist/index.js --cache-map '{"var-cache-apt": "/var/cache/apt", "var-lib-apt": "/var/lib/apt"}'
node ./buildkit-cache-dance-3.1.0/dist/index.js --cache-map '{"var-cache-apt": "/var/cache/apt", "var-lib-apt": "/var/lib/apt"}'
```

After build during extraction:

```shell
node ./buildkit-cache-dance-3.0.0/dist/index.js --extract --cache-map '{"var-cache-apt": "/var/cache/apt", "var-lib-apt": "/var/lib/apt"}'
node ./buildkit-cache-dance-3.1.0/dist/index.js --extract --cache-map '{"var-cache-apt": "/var/cache/apt", "var-lib-apt": "/var/lib/apt"}'
```

Here are the available options:
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: "Injects the cached data into the docker build(x|kit) process"
inputs:
cache-map:
required: true
description: "The map of actions source to container destination paths for the cache paths"
description: "The map of actions source paths to container destination paths or mount arguments"
cache-source:
deprecationMessage: "Use `cache-map` instead"
description: "Where the cache is stored in the calling workspace. Default: `cache`"
Expand Down
53 changes: 38 additions & 15 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "buildkit-cache-dance",
"version": "3.0.0",
"description": "",
"version": "3.1.0",
"description": "Save `RUN --mount=type=cache` caches on GitHub Actions or other CI platforms",
"main": "dist/index.js",
"source": "src/index.ts",
"type": "module",
"scripts": {
"build": "parcel build",
"prepare": "npm run build"
"prepare": "npm run build",
"test": "vitest"
},
"keywords": [
"buildkit",
Expand All @@ -25,7 +26,8 @@
"devDependencies": {
"@types/node": "^20.11.30",
"parcel": "^2.12.0",
"typescript": "^5.4.3"
"typescript": "^5.4.3",
"vitest": "^1.4.0"
},
"dependencies": {
"@actions/core": "~1.5.0",
Expand Down
Loading

0 comments on commit 5de31fc

Please sign in to comment.