Skip to content

Commit 5096792

Browse files
committed
Docker configuration
1 parent 65b00fe commit 5096792

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

service/.dockerignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ data/
44
Dockerfile
55
docker-compose.yml
66
.dockerignore
7-
.gitignore
8-
.env
7+
.gitignore

service/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ ENV DOCKER_HOST=unix:///var/run/docker.sock
1818

1919
WORKDIR /var/www/html
2020

21+
COPY . /var/www/html
22+
2123
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
2224

2325
COPY docker/nginx.conf /etc/nginx/sites-available/default
2426

25-
RUN mkdir -p var/log && chmod -R 777 var/log
27+
RUN mkdir -p var/log var/cache public/submissions && chmod -R 777 var/log var/cache public/submissions
2628

2729
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
2830

service/docker-compose.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@ services:
44
php:
55
build: .
66
volumes:
7-
- ./:/var/www/html:rw
8-
- ./var/log:/var/www/html/var/log:rw
97
- /var/run/docker.sock:/var/run/docker.sock:rw
108
ports:
119
- "8055:80"
1210
depends_on:
1311
- database
1412
environment:
1513
DATABASE_URL: "postgresql://${POSTGRES_USER:-app}:${POSTGRES_PASSWORD:-app}@database:5432/${POSTGRES_DB:-app}?serverVersion=${POSTGRES_VERSION:-16}"
16-
group_add:
17-
- 944
14+
restart: unless-stopped
1815
mem_limit: 1g
1916
cpus: 1
2017

service/src/Command/CodeExecutor.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class CodeExecutor
1010
{
1111
public function executeUserCode(string $code, Problem $problem, mixed $userId): array
1212
{
13+
$maxRuntime = min($problem->getMaxRuntime(), 1);
1314
$results = [];
1415
$submissionsRoot = getcwd() . '/submissions';
1516
$userProblemDir = "$submissionsRoot/$userId/{$problem->getId()}";
@@ -18,7 +19,6 @@ public function executeUserCode(string $code, Problem $problem, mixed $userId):
1819
mkdir($userProblemDir, 0777, true);
1920
}
2021

21-
// Сохраняем решение
2222
file_put_contents("$userProblemDir/solution.py", $code);
2323

2424
foreach ($problem->getTestCases() as $i => $input) {
@@ -32,11 +32,11 @@ public function executeUserCode(string $code, Problem $problem, mixed $userId):
3232
'docker', 'create',
3333
'--network', 'none',
3434
'--cpus', '0.5',
35-
'--memory', '256m',
35+
'--memory', '64m',
3636
'--name', $containerName,
3737
'python:3.10-slim',
3838
'bash', '-c',
39-
"timeout 2s python submissions/$userId/{$problem->getId()}/solution.py < submissions/$userId/{$problem->getId()}/input.txt"
39+
"timeout {$maxRuntime}s python submissions/$userId/{$problem->getId()}/solution.py < submissions/$userId/{$problem->getId()}/input.txt"
4040
]);
4141
$create->mustRun();
4242

@@ -50,7 +50,7 @@ public function executeUserCode(string $code, Problem $problem, mixed $userId):
5050
$start = new Process([
5151
'docker', 'start', '-a', $containerName
5252
]);
53-
$start->setTimeout(4);
53+
$start->setTimeout($maxRuntime + 2);
5454
$start->run();
5555

5656
$stdout = trim($start->getOutput());
@@ -85,7 +85,7 @@ public function executeUserCode(string $code, Problem $problem, mixed $userId):
8585
$results[] = [
8686
'input' => $input,
8787
'expected' => $problem->getExpectedOutputs()[$i],
88-
'output' => null,
88+
'output' => "Time limit exceeded",
8989
'passed' => false,
9090
'error' => 'Time limit exceeded',
9191
];

0 commit comments

Comments
 (0)