https://pulumi.com logo
Title
m

mysterious-family-43099

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
cacheFrom
option is the solve: https://www.pulumi.com/blog/build-images-50x-faster-docker-v4/ What I don't fully understand is the behavior. If I just set
cacheFrom
to
true
is this sufficient if all my images are tagged with
latest
? 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
true
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: <https://github.com/pulumi/pulumi-docker/issues/132>
  // 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: {
      DOCKER_BUILDKIT: '1',
    },
    // 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.