Commit 841667fb authored by mamunozgil's avatar mamunozgil
Browse files

Add dynamic paths to test

No related merge requests found
Pipeline #10915 passed with stage
in 18 seconds
Showing with 44 additions and 15 deletions
+44 -15
......@@ -33,14 +33,14 @@ public class TaskUpload {
private static final Logger LOG = LogManager.getLogger(TaskUpload.class);
private final RepoUtil repoUtil;
private final Path testTmpPath;
private final Path assignmentSubmissionsPath;
private final ExecuteTestUtil executeTestUtil;
private final Tika tika;
public TaskUpload(Environment env, RepoUtil repoUtil, ExecuteTestUtil executeTestUtil) {
this.repoUtil = repoUtil;
this.executeTestUtil = executeTestUtil;
this.testTmpPath = Paths.get(env.getProperty("tests.tmp.dir"));
this.assignmentSubmissionsPath = Paths.get(env.getProperty("tests.tmp.dir"));
this.tika = new Tika();
}
......@@ -68,7 +68,7 @@ public class TaskUpload {
private Path createWorkDirectory() throws IOException {
LOG.debug("Creating new temporary directory");
Path workDirectory = Files.createTempDirectory(testTmpPath, "dta-submission");
Path workDirectory = Files.createTempDirectory(assignmentSubmissionsPath, "dta-submission");
LOG.debug("Working directory for test: {}", workDirectory.toAbsolutePath());
return workDirectory;
}
......
......@@ -59,27 +59,56 @@ public class DockerUtil {
image,
e.getMessage()));
}
LOG.debug("creating container");
CreateContainerResponse containerResponse;
try {
// Extract paths from binds
String testPath = null;
String srcPath = null;
String resultPath = null;
for (Bind bind : binds) {
Volume volume = bind.getVolume();
if (volume.getPath().contains("test")) {
testPath = bind.getPath();
} else if (volume.getPath().contains("src")) {
srcPath = bind.getPath();
} else if (volume.getPath().contains("result")) {
resultPath = bind.getPath();
}
}
if (testPath == null || srcPath == null || resultPath == null) {
throw new IllegalArgumentException("All required paths (testPath, srcPath, resultPath) must be provided.");
}
containerResponse = dockerClient.createContainerCmd("testcontainer")
.withImage(image)
.withHostConfig(
HostConfig.newHostConfig()
.withBinds(binds))
.withBinds(binds)
)
.withCmd(
"java",
"-Djava.security.egd=file:/dev/./urandom",
"-jar",
"/data/app.jar",
String.format("%s:%s", srcPath, testPath),
"/data/libs/*:/data/test/libs/*",
resultPath
)
.exec();
} catch (DockerException e) {
LOG.error(String.format(
"Creating Docker Testrunner container failed with %s", e.getMessage()));
throw e;
}
LOG.debug(String.format("container created: %s", containerResponse.getId()));
LOG.debug(String.format("starting container %s", containerResponse.getId()));
dockerClient.startContainerCmd(containerResponse.getId()).exec();
LOG.debug(String.format("retrieving logs for container %s", containerResponse.getId()));
dockerClient.logContainerCmd(containerResponse.getId())
.withStdOut(true)
......@@ -92,7 +121,7 @@ public class DockerUtil {
LOG.debug(String.format("LOG: %s", new String(frame.getPayload(), StandardCharsets.UTF_8)));
}
});
LOG.debug(String.format("waiting for completion of container %s", containerResponse.getId()));
int ret = dockerClient
.waitContainerCmd(containerResponse.getId())
......@@ -100,12 +129,12 @@ public class DockerUtil {
.awaitCompletion()
.awaitStatusCode();
LOG.debug(String.format("container completed with status %d", ret));
LOG.debug(String.format("deleting container %s", containerResponse.getId()));
dockerClient.removeContainerCmd(containerResponse.getId())
.withRemoveVolumes(true)
.exec();
return ret;
}
}
}
......@@ -104,9 +104,9 @@ public class ExecuteTestUtil {
// Start the test-container with professor-given image and submission-specific volume mounts
dockerUtil.runContainer(
image,
new Bind(testPath.toString(), new Volume("/data/test")),
new Bind(srcPath.toString(), new Volume("/data/src")),
new Bind(resultPath.toString(), new Volume("/data/result"))
new Bind(testPath.toString(), new Volume("test")),
new Bind(srcPath.toString(), new Volume("src")),
new Bind(resultPath.toString(), new Volume("result"))
);
return generateResult(assignmentId, resultPath, testPath);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment