Compare commits

...

3 Commits

Author SHA1 Message Date
Jose Quintana
b433ca0604
Merge b045ea1d9e56f9ce50c87ef4a277f8738f8914a2 into 36f1e144e1c8edb0a652766b484448563d8baf46 2025-01-14 20:30:34 +05:00
Tobbe Lundberg
36f1e144e1
docs: Make the "always save prime numbers" example more clear (#1525)
Some checks failed
Code scanning - action / CodeQL-Build (push) Has been cancelled
Licensed / Licensed (push) Has been cancelled
Tests / build (macOS-latest) (push) Has been cancelled
Tests / build (ubuntu-latest) (push) Has been cancelled
Tests / build (windows-latest) (push) Has been cancelled
Tests / test-save (macOS-latest) (push) Has been cancelled
Tests / test-save (ubuntu-latest) (push) Has been cancelled
Tests / test-save (windows-latest) (push) Has been cancelled
Tests / test-proxy-save (push) Has been cancelled
Tests / test-restore (macOS-latest) (push) Has been cancelled
Tests / test-restore (ubuntu-latest) (push) Has been cancelled
Tests / test-restore (windows-latest) (push) Has been cancelled
Tests / test-proxy-restore (push) Has been cancelled
2025-01-09 23:36:56 +00:00
Jose Quintana
b045ea1d9e
Add Docker example 2023-12-02 00:28:50 +01:00
3 changed files with 46 additions and 8 deletions

View File

@ -181,6 +181,7 @@ See [Examples](examples.md) for a list of `actions/cache` implementations for us
* [Clojure - Lein Deps](./examples.md#clojure---lein-deps)
* [D - DUB](./examples.md#d---dub)
* [Deno](./examples.md#deno)
* [Docker](./examples.md#docker)
* [Elixir - Mix](./examples.md#elixir---mix)
* [Go - Modules](./examples.md#go---modules)
* [Haskell - Cabal](./examples.md#haskell---cabal)

View File

@ -10,6 +10,7 @@
- [Linux](#linux)
- [macOS](#macos)
- [Windows](#windows-1)
- [Docker](#docker)
- [Elixir - Mix](#elixir---mix)
- [Erlang - Rebar3](#erlang--rebar3)
- [Go - Modules](#go---modules)
@ -176,6 +177,40 @@ steps:
key: ${{ runner.os }}-deno-${{ hashFiles('**/deps.ts') }}
```
## Docker
```yaml
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: my-project-${{ matrix.arch }}-buildx-${{ hashFiles('my-directory/Dockerfile') }}
restore-keys: |
my-project-${{ matrix.arch }}-buildx-
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Test
uses: docker/build-push-action@v3
with:
push: false
context: .
platforms: ${{ matrix.arch }}
file: my-directory/Dockerfile
tags: my-username/my-image:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
-
# Temporary workaround
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
```
## Elixir - Mix
```yaml

View File

@ -79,8 +79,10 @@ To avoid saving a cache that already exists, the `cache-hit` output from a resto
The `cache-primary-key` output from the restore step should also be used to ensure
the cache key does not change during the build if it's calculated based on file contents.
Here's an example where we imagine we're calculating a lot of prime numbers and want to cache them:
```yaml
name: Always Caching Primes
name: Always Caching Prime Numbers
on: push
@ -91,23 +93,23 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Restore cached Primes
id: cache-primes-restore
- name: Restore cached Prime Numbers
id: cache-prime-numbers-restore
uses: actions/cache/restore@v4
with:
key: ${{ runner.os }}-primes
key: ${{ runner.os }}-prime-numbers
path: |
path/to/dependencies
some/other/dependencies
# Intermediate workflow steps
- name: Always Save Primes
id: cache-primes-save
if: always() && steps.cache-primes-restore.outputs.cache-hit != 'true'
- name: Always Save Prime Numbers
id: cache-prime-numbers-save
if: always() && steps.cache-prime-numbers-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
key: ${{ steps.cache-primes-restore.outputs.cache-primary-key }}
key: ${{ steps.cache-prime-numbers-restore.outputs.cache-primary-key }}
path: |
path/to/dependencies
some/other/dependencies