1

I've got a github repo which has a library which builds a go binary which is the entrypoint of a container.

My question is whether it is possible to add a depenedency in the dockerfile to that repo (this is to invalidate the cached go binary).

The simplest solution is to have the repo in the source tree and then copy it before building the binary, however that file doesn't have to exist in the up to date image, and would be cleaner if it didn't...

Any help would be appreciated!!

Cjen1
  • 1,826
  • 3
  • 17
  • 47

1 Answers1

0

As detailed in "How to prevent Dockerfile caching git clone", or as I proposed in "force a docker build to 'rebuild' a single step", you can pass an argument to docker build in order to invalidate the cache.

docker build --build-arg \
SHA=$(curl -s 'https://api.github.com/repos/<you>/<GoProject>/commits' | jq -r '.[0].sha') \
-t imageName .

Meaning, if your Go project repository has any new commit, you would want to rebuild your binary.

You would put the ARG command right before the RUN for which you want the cache invalidated

FROM xxx
...
...
ARG SHA=LATEST
RUN SHA=${SHA} \
    git clone https://github.com/Tencent/mars.git
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250