I build a docker image containing the Foo package, which is built from its master version pulled from its git repo:
RUN git clone git://my.git.server/Foo.git
RUN (configure, build and install Foo)
Every time the image is built I'd like the Docker build cache to be invalidated if a new commit has been pushed into the Foo repository, in order to always build the latest version. On the contrary, if the master version is the same as the last time the image was built then the build cache should be used to avoid an unnecessary rebuild.
In its current form, my Dockerfile never needs to be changed so the build cache is never invalidated. Given my poor skills with Docker I can't figure out a possible modification to achieve my desired behavior, so I'd need help with this. Thanks in advance.
Edit: as suggested in the linked question the desired behavior can be achieved with a trick: modifying the Dockerfile as
ARG FOO_MASTER_COMMIT
RUN git clone git://my.git.server/Foo.git
RUN (configure, build and install Foo)
and then launching the build as:
git clone git://my.git.server/Foo.git
DOCKER_BUILDKIT=1 docker build --build-arg FOO_MASTER_COMMIT=$(git -C Foo rev-parse HEAD) -t myimage:ver .
does the job.