I'm developing some test cases using Tescontainers with Spring-Boot in order to get up a MS-SQL dockerized db. It's a huge db that takes about 40 minutes to be restored on the docker run proccess.
The steps I do to work with this image are:
- Build Dockerfile with schema and data scripts tagging it as "db".
- Run the container and wait about 40 minutes for database restoring.
- Commit the container with "db-ready" tag.
The behavior I expect is than the test case try to run a cointainer from "db-ready" image and, if it fails, build then the image directly from Dockerfile. The code I tried looks like:
public static CustomMSSqlContainer getInstance() {
if (container == null) {
try {
container = new CustomMSSqlContainer("myproject:db-ready");
}catch(Exception ex) {
container = new CustomMSSqlContainer(new ImageFromDockerfile().withFileFromClasspath("Dockerfile", "docker/Dockerfile")
.withFileFromClasspath("schema.sql", "docker/schema.sql")
.withFileFromClasspath("entrypoint.sh", "docker/entrypoint.sh")
.withFileFromClasspath("data.sql", "docker/data.sql")
.withFileFromClasspath("data-init.sql", "docker/data-init.sql")
.withFileFromClasspath("start.sh", "docker/start.sh"));
}
container.waitingFor(Wait.forLogMessage("Database ready\\n", 1)
.withStartupTimeout(Duration.ofHours(1)))
.withExposedPorts(1433);
}
return (CustomMSSqlContainer)container;
}
Of course, this code doesn't works like I expect.
Any suggestions?