docker
This commit is contained in:
parent
c1ae83f27a
commit
f040151b68
@ -18,3 +18,8 @@ def solved(user, task):
|
||||
@register.filter('settask')
|
||||
def settask(set, task):
|
||||
return SetTask.objects.get(set=set, task=task)
|
||||
|
||||
|
||||
@register.filter('startswith')
|
||||
def startswith(s, prefix):
|
||||
return s.startswith(prefix)
|
||||
|
@ -19,6 +19,7 @@ class SendCodeView(BaseView):
|
||||
"message": "Пользователя с таким именем не существует",
|
||||
}
|
||||
code = randrange(10000, 100000)
|
||||
print(code)
|
||||
user.userinfo.code = code
|
||||
user.userinfo.save()
|
||||
notify(user, "any", "Код для входа в сервис: " + str(code))
|
||||
|
@ -67,6 +67,9 @@ class BaseTester:
|
||||
def build_command(self):
|
||||
return ""
|
||||
|
||||
def call(self, command):
|
||||
return call(f'cd {self.path} && {command}', shell=True)
|
||||
|
||||
@property
|
||||
def path(self):
|
||||
return join("solutions", str(self.solution.id))
|
||||
@ -94,9 +97,16 @@ class BaseTester:
|
||||
join(self.path, file.path), "wb"
|
||||
) as fs:
|
||||
fs.write(get_bytes(file.fs_id).replace(b"\r\n", b"\n"))
|
||||
dockerfiles = sorted(list(ExtraFile.objects.filter(filename__startswith="Dockerfile", readable=True, task=self.solution.task)), key=lambda x: x.filename)
|
||||
self.call(f"docker network create solution_network_{self.solution.id}")
|
||||
for file in dockerfiles:
|
||||
with open(join(self.path, 'Dockerfile'), 'w') as fs:
|
||||
fs.write(file.text)
|
||||
self.call(f"docker build -t solution_image_{self.solution.id}_{file.filename} .".lower())
|
||||
self.call(f"docker run --network solution_network_{self.solution.id} --name solution_container_{self.solution.id}_{file.filename} -t -d solution_image_{self.solution.id}_{file.filename}".lower())
|
||||
self.solution.result = CONSTS["testing_status"]
|
||||
self.solution.save()
|
||||
docker_command = f"docker run --name solution_{self.solution.id} --volume=/sprint-data/solutions/{self.solution.id}:/{self.working_directory} -t -d {self.solution.language.image}"
|
||||
docker_command = f"docker run --network solution_network_{self.solution.id} --name solution_{self.solution.id} --volume=/sprint-data/solutions/{self.solution.id}:/{self.working_directory} -t -d {self.solution.language.image}"
|
||||
print(docker_command)
|
||||
call(docker_command, shell=True)
|
||||
checker = ExtraFile.objects.filter(task=self.solution.task, filename='checker.py').first()
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
{% block title %}{{ task.name }}{% endblock %}
|
||||
|
||||
{% load filters %}
|
||||
|
||||
{% block scripts %}
|
||||
function deleteFile(file_id) {
|
||||
$.ajax({
|
||||
@ -255,7 +257,7 @@
|
||||
<td valign="top">
|
||||
{% for test in task.files %}
|
||||
<div id="file_{{ test.id }}">
|
||||
<i class="fa {% if test.filename == "checker.py" %}fa-cogs{% else %}fa-file{% endif %}"></i> <button class="btn btn-link" {% if not test.readable %}style="color: red;" {% else %}data-toggle="modal" data-target="#filesModalLong{{ test.id }}"{% endif %}>{{ test.filename }}</button><button class="btn btn-link" style="color: black;" onclick="deleteFile({{ test.id }});"><i class="fa fa-times"></i> </button><br>
|
||||
<i class="fa {% if test.filename == "checker.py" or test.filename|startswith:'Dockerfile' %}fa-cogs{% else %}fa-file{% endif %}"></i> <button class="btn btn-link" {% if not test.readable %}style="color: red;" {% else %}data-toggle="modal" data-target="#filesModalLong{{ test.id }}"{% endif %}>{{ test.filename }}</button><button class="btn btn-link" style="color: black;" onclick="deleteFile({{ test.id }});"><i class="fa fa-times"></i> </button><br>
|
||||
{% if test.readable %}
|
||||
<form method="POST">{% csrf_token %}
|
||||
<!-- Modal -->
|
||||
|
Loading…
Reference in New Issue
Block a user