Skip to content

Commit

Permalink
Correcting check and adding an explicit explaination of what happens …
Browse files Browse the repository at this point in the history
…with caching
  • Loading branch information
gvegayon committed Jan 15, 2025
1 parent de723ad commit eb8b7fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/test-twostep-container-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
- name: Check the output
run: |
if [ "${{ steps.twostep-2.outputs.summary }}" == "re-built" ]; then
if [ "${{ steps.twostep-2.outputs.summary }}" == "rebuilt" ]; then
echo "Using a re-built version (OK)"
else
echo "This was supposed to use the cache version"
Expand Down
15 changes: 15 additions & 0 deletions twostep-container-build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ flowchart LR
Containerfile2-->|Generates|Image2
```

The bulk of the action is dealing with whether the first image is available or not. If available, the action will check if the cache key matches the hash of the container file. If it does, the action will skip the first step and use the cached image. If the cache key does not match, the action will build the image and push it to the registry (if `push-image-1` is set to `true`):

```mermaid
flowchart TB
subgraph "Caching"
start((Start)) --> tag_exists
tag_exists{Tag exists}-->|Yes|pull_image
pull_image[Pull image<br>& inspect<br>labels]-->check_label
check_label{Label<br>matches<br>hash}-->|Yes|done((Done))
check_label-->|No|build_image["Build image<br>& push (optional)"]
tag_exists-->|No|build_image
build_image-->done
end
```

Caching is done by storing the cache-key as a label in the image (`TWO_STEP_BUILD_CACHE_KEY`); and the build and push process is done using the [docker/build-push-action@v6](https://github.com/docker/build-push-action/tree/v6) action. Users have to explicitly provide the cache key for the first step. For example, if you are dealing with an R package, you can cache the dependencies by passing the key `${{ hashFiles('DESCRIPTION') }}` to the `first-step-cache-key` input. That way, the first step will only be executed if the dependencies change.

## Inputs and Outputs
Expand Down

0 comments on commit eb8b7fe

Please sign in to comment.