From b045ea1d9e56f9ce50c87ef4a277f8738f8914a2 Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Sat, 2 Dec 2023 00:28:50 +0100 Subject: [PATCH] Add Docker example --- README.md | 1 + examples.md | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/README.md b/README.md index 7f27d6c..e44cf8c 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,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) diff --git a/examples.md b/examples.md index 1bcde91..0fa98e7 100644 --- a/examples.md +++ b/examples.md @@ -9,6 +9,7 @@ - [Linux](#linux) - [macOS](#macos) - [Windows](#windows-1) +- [Docker](#docker) - [Elixir - Mix](#elixir---mix) - [Erlang - Rebar3](#erlang--rebar3) - [Go - Modules](#go---modules) @@ -155,6 +156,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