title: How to rebuild docker image when remote repository changes
body: <p>I build a docker image containing the Foo package, which is built from its master version pulled from its git repo:</p>
  <pre><code>RUN git clone git://my.git.server/Foo.git
  RUN (configure, build and install Foo)
  </code></pre>
  <p>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.</p>
  <p>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.</p>
  <p>Edit: as suggested in the linked question the desired behavior can be achieved with a trick: modifying the Dockerfile as</p>
  <pre><code>ARG FOO_MASTER_COMMIT
  RUN git clone git://my.git.server/Foo.git
  RUN (configure, build and install Foo)
  </code></pre>
  <p>and then launching the build as:</p>
  <pre><code>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 .
  </code></pre>
  <p>does the job.</p>