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 { ...@@ -33,14 +33,14 @@ public class TaskUpload {
private static final Logger LOG = LogManager.getLogger(TaskUpload.class); private static final Logger LOG = LogManager.getLogger(TaskUpload.class);
private final RepoUtil repoUtil; private final RepoUtil repoUtil;
private final Path testTmpPath; private final Path assignmentSubmissionsPath;
private final ExecuteTestUtil executeTestUtil; private final ExecuteTestUtil executeTestUtil;
private final Tika tika; private final Tika tika;
public TaskUpload(Environment env, RepoUtil repoUtil, ExecuteTestUtil executeTestUtil) { public TaskUpload(Environment env, RepoUtil repoUtil, ExecuteTestUtil executeTestUtil) {
this.repoUtil = repoUtil; this.repoUtil = repoUtil;
this.executeTestUtil = executeTestUtil; 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(); this.tika = new Tika();
} }
...@@ -68,7 +68,7 @@ public class TaskUpload { ...@@ -68,7 +68,7 @@ public class TaskUpload {
private Path createWorkDirectory() throws IOException { private Path createWorkDirectory() throws IOException {
LOG.debug("Creating new temporary directory"); 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()); LOG.debug("Working directory for test: {}", workDirectory.toAbsolutePath());
return workDirectory; return workDirectory;
} }
......
...@@ -59,27 +59,56 @@ public class DockerUtil { ...@@ -59,27 +59,56 @@ public class DockerUtil {
image, image,
e.getMessage())); e.getMessage()));
} }
LOG.debug("creating container"); LOG.debug("creating container");
CreateContainerResponse containerResponse; CreateContainerResponse containerResponse;
try { 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") containerResponse = dockerClient.createContainerCmd("testcontainer")
.withImage(image) .withImage(image)
.withHostConfig( .withHostConfig(
HostConfig.newHostConfig() 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(); .exec();
} catch (DockerException e) { } catch (DockerException e) {
LOG.error(String.format( LOG.error(String.format(
"Creating Docker Testrunner container failed with %s", e.getMessage())); "Creating Docker Testrunner container failed with %s", e.getMessage()));
throw e; throw e;
} }
LOG.debug(String.format("container created: %s", containerResponse.getId())); LOG.debug(String.format("container created: %s", containerResponse.getId()));
LOG.debug(String.format("starting container %s", containerResponse.getId())); LOG.debug(String.format("starting container %s", containerResponse.getId()));
dockerClient.startContainerCmd(containerResponse.getId()).exec(); dockerClient.startContainerCmd(containerResponse.getId()).exec();
LOG.debug(String.format("retrieving logs for container %s", containerResponse.getId())); LOG.debug(String.format("retrieving logs for container %s", containerResponse.getId()));
dockerClient.logContainerCmd(containerResponse.getId()) dockerClient.logContainerCmd(containerResponse.getId())
.withStdOut(true) .withStdOut(true)
...@@ -92,7 +121,7 @@ public class DockerUtil { ...@@ -92,7 +121,7 @@ public class DockerUtil {
LOG.debug(String.format("LOG: %s", new String(frame.getPayload(), StandardCharsets.UTF_8))); 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())); LOG.debug(String.format("waiting for completion of container %s", containerResponse.getId()));
int ret = dockerClient int ret = dockerClient
.waitContainerCmd(containerResponse.getId()) .waitContainerCmd(containerResponse.getId())
...@@ -100,12 +129,12 @@ public class DockerUtil { ...@@ -100,12 +129,12 @@ public class DockerUtil {
.awaitCompletion() .awaitCompletion()
.awaitStatusCode(); .awaitStatusCode();
LOG.debug(String.format("container completed with status %d", ret)); LOG.debug(String.format("container completed with status %d", ret));
LOG.debug(String.format("deleting container %s", containerResponse.getId())); LOG.debug(String.format("deleting container %s", containerResponse.getId()));
dockerClient.removeContainerCmd(containerResponse.getId()) dockerClient.removeContainerCmd(containerResponse.getId())
.withRemoveVolumes(true) .withRemoveVolumes(true)
.exec(); .exec();
return ret; return ret;
} }
} }
...@@ -104,9 +104,9 @@ public class ExecuteTestUtil { ...@@ -104,9 +104,9 @@ public class ExecuteTestUtil {
// Start the test-container with professor-given image and submission-specific volume mounts // Start the test-container with professor-given image and submission-specific volume mounts
dockerUtil.runContainer( dockerUtil.runContainer(
image, image,
new Bind(testPath.toString(), new Volume("/data/test")), new Bind(testPath.toString(), new Volume("test")),
new Bind(srcPath.toString(), new Volume("/data/src")), new Bind(srcPath.toString(), new Volume("src")),
new Bind(resultPath.toString(), new Volume("/data/result")) new Bind(resultPath.toString(), new Volume("result"))
); );
return generateResult(assignmentId, resultPath, testPath); 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