Skip to content

Commit

Permalink
feat: Add support for npm cache (#95)
Browse files Browse the repository at this point in the history
Co-authored-by: Anders K. Pettersen <staticaland@users.noreply.github.com>
  • Loading branch information
staticaland and staticaland authored Jul 1, 2024
1 parent 494e78b commit 20bede7
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/reusable-docker-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ on:
type: string
default: '**/requirements.txt'

npm_cache:
description: |
Enable or disable the use of a persistent npm directory cache.
Mount the cache into the container using the `--mount` flag with the `RUN` instruction in the Dockerfile. The cache must be in the default location (`/root/.npm`) and have an ID of `npm-cache`.
default: false
type: boolean

npm_package_file_pattern:
description: >
Glob pattern to match the npm package file.
type: string
default: '**/package.json'

outputs:

image_version:
Expand Down Expand Up @@ -368,6 +382,33 @@ jobs:
skip-extraction: ${{ steps.cache-pip.outputs.cache-hit }}


- if: ${{ inputs.npm_cache }}
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
name: Handle cache for npm ⚙
id: cache-npm
with:
key: cache-npm-${{ hashFiles(inputs.npm_package_file_pattern) }}
path: |
root-npm
restore-keys: |
cache-npm-
- if: ${{ inputs.npm_cache }}
name: Inject npm cache into Docker ⚙
uses: reproducible-containers/buildkit-cache-dance@87e6a3bbd976a1476e29b60fe743ab0977034ff5 # v3.1.1
with:
cache-map: |
{
"root-npm": {
"target": "/root/.npm",
"id": "npm-cache"
}
}
save-always: "false"
skip-extraction: ${{ steps.cache-npm.outputs.cache-hit }},


- name: Build and push (if enabled) Docker image to one or more registries 🚀
id: build-push
uses: docker/build-push-action@15560696de535e4014efeff63c48f16952e52dd1 # v6.2.0
Expand Down

0 comments on commit 20bede7

Please sign in to comment.