snowdrop / java-buildpack-client

A simple buildpack (https://buildpacks.io/) platform implementation as a library for java..
Apache License 2.0
14 stars 7 forks source link

Question: Can we mount a local maven repository ? #82

Closed cmoulliard closed 3 weeks ago

cmoulliard commented 1 month ago

Question

Can we mount a local maven repository as we can do with Pack CLI ?

REGISTRY_HOST="kind-registry.local:5000"
docker rmi ${REGISTRY_HOST}/quarkus-hello:1.0
pack build ${REGISTRY_HOST}/quarkus-hello:1.0 \
     --builder paketocommunity/builder-ubi-base:0.0.92 \
     --volume $HOME/.m2:/home/cnb/.m2:rw

@BarDweller

cmoulliard commented 1 month ago

The fluent DSL allows to declare such a volume at the condition that a podman's volume has been created but how can we tell to podman or the buildpack client = lifecycle which uses java docker lib to bind $HOME/.m2 with the volume ?

        int exitCode = BuildConfig.builder()
            .withNewBuildCacheConfig()
              .withCacheVolumeName("~/.m2")
            .endBuildCacheConfig()
BarDweller commented 3 weeks ago

The build cache is a buildpacks artifact, controlled by the buildpacks spec. It's not a generic cache volume you can mount arbitrary content via. The cache volume name is not a system path, but the volume name used with docker, you do not get to pick paths for the cache volume, it is supplied to the lifecycle, to be used to store buildpack layers marked for caching. Supplying the same cache volume for a subsequent build of the same project will then allow those layers to be reinflated and reused.. (if the buildpacks that created them understand how to do that).

The snowdrop buildpack library does not expose any way to perform bind mounts from the local filesystem into a buildpack build. This would be required to mount a maven cache, however, previous investigations from other containerised build tooling such as odo and appsody discoverd that the m2 cache directory is in no way safe to use concurrently, and that bind mounting it for containerised builds risks corrupting the cache if concurrent writes are made for the same dependencies.

Adding the functionality would not be difficult, it would require new configuration to allow src:dest paths to be specified, and then extra code to mount the specified volume(s) for each phase.