Skip to content

Instantly share code, notes, and snippets.

@lagergren
Created February 7, 2024 10:32
Show Gist options
  • Save lagergren/094bd5b62f55c530208ee2fa7718eb0b to your computer and use it in GitHub Desktop.
Save lagergren/094bd5b62f55c530208ee2fa7718eb0b to your computer and use it in GitHub Desktop.
Docker container build time cloning and caching a particular source code version
This is normally not the Docker approach.
Volumes only exist during runtime, and any changing external source is usually retrieved on volume level and during startup
There may be use cases when you want to clone something from git during the Dockerfile during build, but they are not very common.
To clone a particular repo as part of the container build do:
ADD https://api.github.com/repos/org/reponame/git/refs/heads/$GITHUB_BRANCH version.json
RUN git clone --branch $GITHUB_BRANCH --depth=1 https://github.com/org/reponame repo
The verison.json will ADD will create a layer that is invalidated iff $GITHUB_BRANCH is updated, and then, rebuilding the container will
realize that this layer will be regenerated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment