Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use intermediate stage to avoid invalidating Docker cache when copyin…
…g from build context (#3179) ## Description In WATonomous/infra-config#3176, we documented a manual procedure to fix cache invalidation issues for the provisioner container. However, there's a workaround: use a lightweight intermediate stage to serve as the courier between the context. The workaround comes from [here](devcontainers/cli#153 (comment)). This PR implements the workaround and updates the docs to reflect this. **How it works**: Docker computes hashes for the input to each layer to determine whether that layer can use the cache. Previously, the permission bits on the computer that built the cache and my personal environment were different. This resulted in the hash being different, thus invalidating the cache. `COPY --chmod` doesn't help either because the hash is computed [without taking into account the parameters](docker/buildx#1311). In this PR, we implement a workaround, where we use an extremely lightweight stage (`FROM scratch` with only `COPY` statements) to import files and set permissions from the build context. We don't care whether this stage runs or gets cached, because it's very lightweight. At build-time, if we are lucky that our system has the same permissions as the cache build environment, then this stage will be cached. If not, this stage will run. Regardless, the output of this stage will remain the same if the file is unchanged. This property allows Docker to continue subsequent steps with cache. Tested to work with the existing cache when using permission 644. This PR changes the permissions to 400 to be a bit more strict. Resolves WATonomous/infra-config#3178 ## Checklist - [x] I have read and understood the [WATcloud Guidelines](https://cloud.watonomous.ca/docs/community-docs/watcloud/guidelines) - [x] I have performed a self-review of my code
- Loading branch information