path
This commit is contained in:
parent
a31d940429
commit
cc95eb34ec
@ -65,7 +65,7 @@ class Solution(models.Model):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def volume_directory(self):
|
def volume_directory(self):
|
||||||
return "solution"
|
return "/sprint-data/worker/" + str(self.id)
|
||||||
|
|
||||||
def exec_command(self, command, working_directory='app', timeout=None):
|
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)
|
return call(f'docker exec -i solution_{self.id} sh -c "cd {working_directory} && {command}"', shell=True, timeout=timeout)
|
||||||
|
@ -60,19 +60,19 @@ class BaseTester:
|
|||||||
for file in SolutionFile.objects.filter(solution=self.solution):
|
for file in SolutionFile.objects.filter(solution=self.solution):
|
||||||
dirs = file.path.split('/')
|
dirs = file.path.split('/')
|
||||||
for i in range(len(dirs) - 1):
|
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):
|
if not exists(name):
|
||||||
mkdir(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))
|
fs.write(get_bytes(file.fs_id))
|
||||||
self.solution.result = CONSTS["testing_status"]
|
self.solution.result = CONSTS["testing_status"]
|
||||||
self.solution.save()
|
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)
|
print(docker_command)
|
||||||
call(docker_command, shell=True)
|
call(docker_command, shell=True)
|
||||||
print("Container created")
|
print("Container created")
|
||||||
for file in ExtraFile.objects.filter(task=self.solution.task):
|
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))
|
fs.write(get_bytes(file.fs_id))
|
||||||
print("Files copied")
|
print("Files copied")
|
||||||
try:
|
try:
|
||||||
@ -102,7 +102,7 @@ class BaseTester:
|
|||||||
self.solution.result = "TE"
|
self.solution.result = "TE"
|
||||||
print(str(e))
|
print(str(e))
|
||||||
self.solution.save()
|
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()
|
self.solution.user.userinfo.refresh_from_db()
|
||||||
if self.solution.user.userinfo.notification_solution_result:
|
if self.solution.user.userinfo.notification_solution_result:
|
||||||
bot.send_message(
|
bot.send_message(
|
||||||
|
@ -76,4 +76,5 @@ services:
|
|||||||
- postgres
|
- postgres
|
||||||
- storage
|
- storage
|
||||||
volumes:
|
volumes:
|
||||||
|
- /sprint-data/worker:/usr/src/app
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
Loading…
Reference in New Issue
Block a user