diff --git a/.gitignore b/.gitignore index 8cea9c3a..8017012b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ build !.yarn/releases !.yarn/sdks !.yarn/versions + +node_modules/ diff --git a/README.md b/README.md index 4b5917d6..31a41e2a 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,12 @@ Cache Docker Images Whether Built or Pulled - [Usage](#usage) - [Inputs](#inputs) - [Required](#required) + - [`key`](#key) - [Optional](#optional) + - [`read-only`](#read-only) - [Outputs](#outputs) - [`cache-hit`](#cache-hit) + - [Anonymous image names](#anonymous-image-names) - [Supported Runners](#supported-runners) - [Permissions](#permissions) - [Changelog](#changelog) @@ -94,6 +97,30 @@ True on cache hit (even if the subsequent failed) and false on cache miss. See also [skipping steps based on cache-hit](https://github.com/marketplace/actions/cache#Skipping-steps-based-on-cache-hit). +## Anonymous image names + +Anonymous images (eg. `:`) will be skipped during caching +via `docker save`, as we use the `{{ .Repository }}:{{ .Tag }}` format +to reference which images to save. + +`docker save {{ .ID }}` would allow us to cache/load such anonymous images. +However, the docker client loses reference to the original +`{{ .Repository }}:{{ .Tag }}` value upon `docker load` for previously +named images, resulting in: + +```sh +my-image:tag +``` + +to become + +```sh +: +``` + +Be sure to name + tag those images you wish to be handled by the caching +and loading operations in this action. + ## Supported Runners - Tested on `ubuntu-22.04` and `windows-2022` diff --git a/src/docker.test.ts b/src/docker.test.ts index 8d309b50..e9a2b3e2 100644 --- a/src/docker.test.ts +++ b/src/docker.test.ts @@ -256,7 +256,10 @@ describe("Docker images", (): void => { assertSaveCacheHit(key); } else if (readOnly) { assertSaveReadOnly(key); - } else if (newImages.length === 0) { + } else if ( + newImages.length === 0 || + newImages.every((img) => img == ":") + ) { assertNoNewImagesToSave(); } else { assertSaveCacheMiss(key, newImages); @@ -268,6 +271,7 @@ describe("Docker images", (): void => { ["my-key", false, false, [["preexisting-image"], []]], ["my-key", false, true, [["preexisting-image"], ["new-image"]]], ["my-key", true, false, [["preexisting-image"], ["new-image"]]], + ["my-key", false, false, [["preexisting-image"], [":"]]], ], }, ); diff --git a/src/docker.ts b/src/docker.ts index 92a5b024..e7019efd 100644 --- a/src/docker.ts +++ b/src/docker.ts @@ -42,7 +42,8 @@ const saveDockerImages = async (): Promise => { const images = await execBashCommand(LIST_COMMAND); const imagesList = images.split("\n"); const newImages = imagesList.filter( - (image: string): boolean => !preexistingImages.includes(image), + (image: string): boolean => + !preexistingImages.includes(image) && image !== ":", ); if (newImages.length === 0) { info("No Docker images to save");