diff --git a/Main/models/solution.py b/Main/models/solution.py index 5032cd9..3629208 100644 --- a/Main/models/solution.py +++ b/Main/models/solution.py @@ -65,7 +65,7 @@ class Solution(models.Model): @property def volume_directory(self): - return "solution" + return "/sprint-data/worker/" + str(self.id) def exec_command(self, command, working_directory='app', timeout=None): return call(f'docker exec -i solution_{self.id} sh -c "cd {working_directory} && {command}"', shell=True, timeout=timeout) diff --git a/SprintLib/testers/BaseTester.py b/SprintLib/testers/BaseTester.py index 646e52f..405159a 100644 --- a/SprintLib/testers/BaseTester.py +++ b/SprintLib/testers/BaseTester.py @@ -60,19 +60,19 @@ class BaseTester: for file in SolutionFile.objects.filter(solution=self.solution): dirs = file.path.split('/') for i in range(len(dirs) - 1): - name = join("solution", '/'.join(dirs[:i + 1])) + name = join(str(self.solution.id), '/'.join(dirs[:i + 1])) if not exists(name): mkdir(name) - with open(join("solution", file.path), 'wb') as fs: + with open(join(str(self.solution.id), file.path), 'wb') as fs: fs.write(get_bytes(file.fs_id)) self.solution.result = CONSTS["testing_status"] self.solution.save() - docker_command = f"docker run --name solution_{self.solution.id} --volume=/usr/src/app/solution:/{self.working_directory} -t -d {self.solution.language.image}" + docker_command = f"docker run --name solution_{self.solution.id} --volume={self.solution.volume_directory}:/{self.working_directory} -t -d {self.solution.language.image}" print(docker_command) call(docker_command, shell=True) print("Container created") for file in ExtraFile.objects.filter(task=self.solution.task): - with open(join("solution", file.filename), 'wb') as fs: + with open(join(str(self.solution.id), file.filename), 'wb') as fs: fs.write(get_bytes(file.fs_id)) print("Files copied") try: @@ -102,7 +102,7 @@ class BaseTester: self.solution.result = "TE" print(str(e)) self.solution.save() - # call(f"docker rm --force solution_{self.solution.id}", shell=True) + call(f"docker rm --force solution_{self.solution.id}", shell=True) self.solution.user.userinfo.refresh_from_db() if self.solution.user.userinfo.notification_solution_result: bot.send_message( diff --git a/docker-compose.yaml b/docker-compose.yaml index 12cc781..0267d38 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -76,4 +76,5 @@ services: - postgres - storage volumes: + - /sprint-data/worker:/usr/src/app - /var/run/docker.sock:/var/run/docker.sock \ No newline at end of file