Skip to content

Instantly share code, notes, and snippets.

@stevehenderson
Last active January 18, 2022 15:28
Show Gist options
  • Save stevehenderson/8847c9508e6e0a49768050cb7a573d63 to your computer and use it in GitHub Desktop.
Save stevehenderson/8847c9508e6e0a49768050cb7a573d63 to your computer and use it in GitHub Desktop.
Prevent Docker from Caching Git Clone

Issue: When pulling from github inside docker, it won't update the cached docker image.

You can force it to by using the git api to pull down the latest commit meta data and saving that to the image. This works and stays in synch with every new update to your repo, which you want to pull. No commits mean no new meta data so your docker will use the cached version. If you commits, this makes a new SHA which gets pulled in the API, invalidating cached

ADD https://$GIT_PAT@api.github.com/repos/some_org/some_repo/git/refs/heads cachebust
RUN git clone https://$GIT_PAT_IN@github.com/some_org/some-repo-git.git

Ref: https://stackoverflow.com/questions/13735051/how-to-capture-curl-output-to-a-file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment