Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#429] add docker cache to build workflow #440

Merged
merged 1 commit into from
Oct 25, 2024
Merged

Conversation

ewilkins-csi
Copy link
Contributor

Saves the docker cache configured in the cacheTo and cacheFrom options of the Fabric8 docker-maven-plugin to GH caches to speed image rebuilds. Also uses the install-dependencies custom action to de-duplicate the required build tool installation logic.

@ewilkins-csi ewilkins-csi force-pushed the 429-save-docker-cache branch from 30b7622 to ee12ab3 Compare October 25, 2024 19:38
- name: Load m2 repository cache # Manually caching .m2 repo as the setup-java caching isn't falling back to older caches
id: cached-m2-repo
uses: actions/cache@v4
uses: actions/cache/restore@v4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I: By using the restore granular action, we prevent the automated cache-save logic that doesn't meet our needs of saving even when the build fails. (Prior to this change we were basically always saving these caches twice.)

@@ -123,19 +103,24 @@ jobs:
- name: Run Archetype Tests
run: |
./mvnw -B clean install -Parchetype-test -pl :foundation-archetype
#NB: The following two explicit cache saves are necessary to ensure caches are saved on build failure,
# until https://github.com/actions/cache/issues/1315 is resolved
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I: This issue is unlikely to be resolved any time soon as there are underlying restrictions that prevent it. Instead, we follow the guidance of the action maintainers.

Saves the docker cache configured in the `cacheTo` and `cacheFrom`
options of the Fabric8 `docker-maven-plugin` to GH caches to speed image
rebuilds.  Also uses the `install-dependencies` custom action to
de-duplicate the required build tool installation logic.
@ewilkins-csi ewilkins-csi force-pushed the 429-save-docker-cache branch from ee12ab3 to 2b2eb73 Compare October 25, 2024 19:42
- name: Poetry cache
id: cached-poetry
uses: actions/cache@v4
with:
path: ~/.cache/pypoetry
key: poetry-cache-${{ hashFiles('**/pom.xml') }}
key: poetry-cache-${{ hashFiles('**/pyproject.toml') }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I: Use pyproject.toml so the cache is updated when the python dependencies change, even if the POMs have not changed.

uses: actions/cache/restore@v4
with:
path: ~/.docker/cache
key: docker-cache-${{ hashFiles('**/Dockerfile') }}
Copy link
Contributor Author

@ewilkins-csi ewilkins-csi Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I: This has some limitations, as it doesn't also include the files that are copied into the docker images (e.g. our python modules) but this should be close enough to the ideal case without a ton of complexity. Alternatively, since our caches are cumulative anyway, we could just use a timestamp everywhere instead of file hashes.

@ewilkins-csi ewilkins-csi merged commit 9def258 into dev Oct 25, 2024
@ewilkins-csi ewilkins-csi deleted the 429-save-docker-cache branch October 25, 2024 20:02
@ewilkins-csi ewilkins-csi linked an issue Oct 25, 2024 that may be closed by this pull request
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Build action should re-use the docker build cache
2 participants