04/28/2023, 3:40 PM
I am trying to get docker images with layer caching to work with Github actions. My understanding is that using the
option is the solve: What I don't fully understand is the behavior. If I just set
is this sufficient if all my images are tagged with
? Will this only pull the cached image if nothing has changed? Or will this know to pull the last image and start from the latest layer that invalidates the cache?
More context: after trying this with Github actions, it looks like it pulls the image from the container repository but doesn't actually use it during the build process
Tried with both
and this configuration:
if (dockerArgs) {
    // Need this for caching to work properly
    dockerArgs.BUILDKIT_INLINE_CACHE = "1";
  else {
    dockerArgs = {}

  // Build and push the image to ECR.
  // TODO: Docker images get built and pushed every time if things haven't changed.
  // This is a bug: <>
  // See if we can fix this by using git hashes.
  const image = repo.buildAndPushImage({
    context: `../../../${project}`,
    ...(dockerfileName && {
      dockerfile: `../../../${project}/${dockerfileName}`,
    ...(dockerArgs && {args: dockerArgs}),
    args: dockerArgs,
    env: {
    // We need this to build images on M1 architecture.
    extraOptions: ['--platform=linux/amd64', '--quiet'],
    extraOptions: ['--platform=linux/amd64', '--quiet', '--load'],
    // Support docker layer caching by pulling the latest image
    cacheFrom: { stages: ['pre-deps', 'deps', 'build']},
    target: 'final'
In the Github action it pulled the image from the repository, but it didn't actually use it to build the image.