Skip to content

Support caching build layers to an image  #28386

@scottfrederick

Description

@scottfrederick

The spring-boot:build-image Maven goal and bootBuildImage Gradle task configure the CNB builder to cache layers created by buildpacks to make subsequent image builds run faster. Currently the cache is stored as named volume in the Docker daemon. This doesn't work well when running builds on CI/CD environments, since Docker daemons might be ephemeral or builds might run on different worker nodes.

To better support running builds on CI/CD environments, the CNB builder supports storing cached layers in an OCI image. The Boot plugins could be enhanced to support this configuration also.

For Maven, the build configuration would be:

<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
          <image>
            <buildCache>
              <image>
                <name>repo.example.com/cache-${project.artifactId}:latest</name>
              </image>
            </buildCache>
          </image>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

For Gradle, the build configuration would be:

bootBuildImage {
  buildCache {
    image {
      name = "repo.example.com/cache-${rootProject.name}:latest"
    }
  }
}

Note: the image option is not available for the launch cache, only for the build cache.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions