#Gradle Testcontainers

1 messages · Page 1 of 1 (latest)

strong scroll
#

Convert to thread

white lichen
#

Oh thats a neat use case. beyond my understanding perhaps though. I only use the golang sdk but I had a similar issue the other day where I was standing up a service and the a dependant service wasn't accessible. In my case it was because I didn't store a reference to it and it was killed after it started.

i.Db = i.postgresDB()
migration := dag.Container().
From("golang:latest").
WithServiceBinding("db", i.Db)

strong scroll
#

What I am failing to understand is, does Dagger Engine enable us to run full blown docker inside? Alternative solutiom for me would be to bind the docker socket into my Dagger function, but that does not work in Windows and is extremely slow in WSL

lunar linden
#

@strong scroll so, the fastest way to start retrofitting Dagger into your current setup with TestContainers is to start the Docker engine as a Dagger service and bind it to your app build/test Dagger step

strong scroll
#

I will send the code in 10mins, that is currently failing

lunar linden
#

There's more info about this in the #testcontainers channel. If you're still having issues, please share how yourw doing it here and I'll try to help you out

strong scroll
#

So this is the code which was failing for me :

    @function
    async def java(self, context: dagger.Directory) -> dagger.Container:
        """Builds a Java testcontainerd image"""

        docker = dag.docker().engine()
        build = (dag.container()
                 .from_("eclipse-temurin:21-jdk-alpine")
                 .with_service_binding("docker", docker)
                 .with_env_variable("DOCKER_HOST", "tcp://docker:2375")
                 .with_env_variable("TESTCONTAINERS_HOST_OVERRIDE", "docker")
                 .with_directory("/src", context)
                 .with_workdir("/src")
                 .with_mounted_cache("/src/.gradle", dag.cache_volume("gradle-8.10.2"))
                 .with_mounted_cache("~/.gradle", dag.cache_volume("gradle-home"))
                 .with_exec("./gradlew build --no-daemon".split()))

        return build
#

I am waiting for it to run now, so that I can send you the output error. Basically the testcontainers framework was unable to start the containers

#

OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended

Task :app:test

OrderPersistencePortTest > WhenCreatingAnOrder > testThenOrderIsPersistedCorrectly() FAILED
java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:180
Caused by: org.springframework.beans.factory.BeanCreationException at AbstractBeanFactory.java:326
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at ConstructorResolver.java:795
Caused by: org.springframework.beans.factory.BeanCreationException at AbstractAutowireCapableBeanFactory.java:1806
Caused by: org.springframework.beans.factory.BeanCreationException at AbstractAutowireCapableBeanFactory.java:607
Caused by: org.testcontainers.containers.ContainerLaunchException at GenericContainer.java:359
Caused by: org.rnorth.ducttape.RetryCountExceededException at Unreliables.java:88
Caused by: org.testcontainers.containers.ContainerLaunchException at GenericContainer.java:563
Caused by: com.github.dockerjava.api.exception.InternalServerErrorException at DefaultInvocationBuilder.java:247

This is basically a failure to start containers

#

Here I am using the module from shykes.

strong scroll
#

But following code with module testcontainers published by vito seems to be working:


    @function
    async def java(self, context: dagger.Directory) -> dagger.Container:
        """Builds a Java testcontainerd image"""
        build = (dag.container()
                 .from_("eclipse-temurin:21-jdk-alpine")
                 .with_(dag.testcontainers().setup)
                 .with_directory("/src", context)
                 .with_workdir("/src")
                 .with_exec(["ls"])
                 .with_mounted_cache("/src/.gradle", dag.cache_volume("gradle-8.10.2"))
                 .with_mounted_cache("~/.gradle", dag.cache_volume("gradle-home"))
                 .with_env_variable("CACHEBUSTER", "1")
                 .with_exec("./gradlew build --no-daemon".split()))
        return build
lunar linden
lunar linden