I have a pipeline which installs sdkman, java and maven. I had it working and decided to implement cache for the installation of sdkman and its candidates but now the directory that I am trying to cache (/root/.sdkman) its empty after using the with_cache_mounted function. This is what my pipeline looks like:
In the following pipeline:
import sys
import anyio
import dagger
async def main():
config = dagger.Config(log_output=sys.stdout)
async with dagger.Connection(config) as client:
container = client.container().from_("ubuntu:22.04")
sdkman_cache = client.cache_volume("sdkman-cache")
# install sdkman and its dependencies
container = (
container
.with_exec("apt-get update".split())
.with_exec("apt-get install -y zip unzip wget curl".split())
.with_exec("curl -s https://get.sdkman.io -o sdkman.sh".split())
.with_exec("bash sdkman.sh".split())
.with_mounted_cache("/root/.sdkman", sdkman_cache)
)
# install required java and maven versions
container = (
container
.with_exec(["/bin/bash", "-c", "source /root/.sdkman/bin/sdkman-init.sh && sdk install java 11.0.18-zulu"])
.with_exec(["/bin/bash", "-c", "source /root/.sdkman/bin/sdkman-init.sh && sdk install maven 3.6.3"])
.with_env_variable(name="PATH", value="$PATH:/root/.sdkman/candidates/maven/current/bin", expand=True)
.with_env_variable(name="PATH", value="$PATH:/root/.sdkman/candidates/java/current/bin", expand=True)
.with_env_variable(name="JAVA_HOME", value="/root/.sdkman/candidates/java/current")
)
container = container.with_exec(["java", "--version"])
await container
anyio.run(main)