Enables cgroup support for isolate
All checks were successful
Build and Push Docker Images / build (src/LiquidCode.Tester.Gateway/Dockerfile, git.nullptr.top/liquidcode/liquidcode-tester-gateway-roman, gateway) (push) Successful in 56s
Build and Push Docker Images / build (src/LiquidCode.Tester.Worker/Dockerfile, git.nullptr.top/liquidcode/liquidcode-tester-worker-roman, worker) (push) Successful in 1m7s

Configures isolate to use cgroups for improved resource management.

Adds the `--cg` flag to the isolate init and cleanup commands,
leveraging cgroups for better resource isolation during code execution testing.

Makes isolate configuration file explicit.
This commit is contained in:
2025-11-05 22:01:57 +03:00
parent 24943a7c86
commit a8c0ec9ed3
2 changed files with 6 additions and 5 deletions

View File

@@ -87,9 +87,10 @@ RUN useradd -m -u 1001 -s /bin/bash workeruser && \
chmod 755 /var/local/lib/isolate && \ chmod 755 /var/local/lib/isolate && \
chown -R workeruser:workeruser /var/local/lib/isolate chown -R workeruser:workeruser /var/local/lib/isolate
# Configure isolate directories (defaults in isolate binary already match these paths) # Configure isolate directories and control-group root
# The binary falls back to /var/local/lib/isolate for boxes and /sys/fs/cgroup for cgroups, RUN printf "box_root = /var/local/lib/isolate\nlock_root = /run/isolate/locks\ncg_root = /sys/fs/cgroup\nfirst_uid = 60000\nfirst_gid = 60000\nnum_boxes = 1000\n" > /usr/local/etc/isolate.conf && \
# so no explicit config file is required here. ln -sf /usr/local/etc/isolate.conf /usr/local/etc/isolate && \
mkdir -p /run/isolate/locks
# Copy published app # Copy published app
COPY --from=publish /app/publish . COPY --from=publish /app/publish .

View File

@@ -24,7 +24,7 @@ public class IsolateService
{ {
_logger.LogDebug("Initializing isolate box {BoxId}", boxId); _logger.LogDebug("Initializing isolate box {BoxId}", boxId);
var result = await RunIsolateCommandAsync($"--box-id={boxId} --init"); var result = await RunIsolateCommandAsync($"--box-id={boxId} --cg --init");
if (result.ExitCode != 0) if (result.ExitCode != 0)
{ {
@@ -90,7 +90,7 @@ public class IsolateService
{ {
_logger.LogDebug("Cleaning up isolate box {BoxId}", boxId); _logger.LogDebug("Cleaning up isolate box {BoxId}", boxId);
var result = await RunIsolateCommandAsync($"--box-id={boxId} --cleanup"); var result = await RunIsolateCommandAsync($"--box-id={boxId} --cg --cleanup");
if (result.ExitCode != 0) if (result.ExitCode != 0)
{ {