fix local testing & isolate & C# processing
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 48s
Build and Push Docker Images / build (src/LiquidCode.Tester.Worker/Dockerfile, git.nullptr.top/liquidcode/liquidcode-tester-worker-roman, worker) (push) Successful in 57s
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 48s
Build and Push Docker Images / build (src/LiquidCode.Tester.Worker/Dockerfile, git.nullptr.top/liquidcode/liquidcode-tester-worker-roman, worker) (push) Successful in 57s
This commit is contained in:
@@ -35,7 +35,7 @@ public class WorkerClientService : IWorkerClientService
|
|||||||
form.Add(new StringContent(submit.MissionId.ToString()), "MissionId");
|
form.Add(new StringContent(submit.MissionId.ToString()), "MissionId");
|
||||||
form.Add(new StringContent(submit.Language), "Language");
|
form.Add(new StringContent(submit.Language), "Language");
|
||||||
form.Add(new StringContent(submit.LanguageVersion), "LanguageVersion");
|
form.Add(new StringContent(submit.LanguageVersion), "LanguageVersion");
|
||||||
form.Add(new StringContent(submit.SourceCode), "SourceCode");
|
form.Add(new StringContent(submit.SourceCode, System.Text.Encoding.UTF8, "text/plain"), "SourceCode");
|
||||||
form.Add(new StringContent(submit.CallbackUrl), "CallbackUrl");
|
form.Add(new StringContent(submit.CallbackUrl), "CallbackUrl");
|
||||||
|
|
||||||
// Add package file
|
// Add package file
|
||||||
|
|||||||
@@ -103,7 +103,10 @@ public class CSharpCompilationServiceIsolate : ICompilationService
|
|||||||
DirectoryBindings = new List<DirectoryBinding>
|
DirectoryBindings = new List<DirectoryBinding>
|
||||||
{
|
{
|
||||||
new DirectoryBinding { HostPath = "/usr/lib", SandboxPath = "/usr/lib", ReadOnly = true },
|
new DirectoryBinding { HostPath = "/usr/lib", SandboxPath = "/usr/lib", ReadOnly = true },
|
||||||
new DirectoryBinding { HostPath = "/lib", SandboxPath = "/lib", ReadOnly = true }
|
new DirectoryBinding { HostPath = "/lib", SandboxPath = "/lib", ReadOnly = true },
|
||||||
|
new DirectoryBinding { HostPath = "/usr/bin", SandboxPath = "/usr/bin", ReadOnly = true },
|
||||||
|
new DirectoryBinding { HostPath = "/usr/share", SandboxPath = "/usr/share", ReadOnly = true },
|
||||||
|
new DirectoryBinding { HostPath = "/etc/mono", SandboxPath = "/etc/mono", ReadOnly = true }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using LiquidCode.Tester.Worker.Services.Isolate;
|
using LiquidCode.Tester.Worker.Services.Isolate;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace LiquidCode.Tester.Worker.Services;
|
namespace LiquidCode.Tester.Worker.Services;
|
||||||
|
|
||||||
@@ -63,6 +64,7 @@ public class CSharpExecutionServiceIsolate : IExecutionService
|
|||||||
|
|
||||||
// Prepare input/output files inside the sandbox
|
// Prepare input/output files inside the sandbox
|
||||||
var outputFilePath = Path.Combine(boxDir, "output.txt");
|
var outputFilePath = Path.Combine(boxDir, "output.txt");
|
||||||
|
var stderrFilePath = Path.Combine(boxDir, "stderr.txt");
|
||||||
string? sandboxInputPath = null;
|
string? sandboxInputPath = null;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(inputFilePath) && File.Exists(inputFilePath))
|
if (!string.IsNullOrEmpty(inputFilePath) && File.Exists(inputFilePath))
|
||||||
@@ -71,20 +73,30 @@ public class CSharpExecutionServiceIsolate : IExecutionService
|
|||||||
File.Copy(inputFilePath, sandboxInputPath, overwrite: true);
|
File.Copy(inputFilePath, sandboxInputPath, overwrite: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run in Isolate
|
// Run in Isolate using mono runtime
|
||||||
var isolateResult = await _isolateService.RunAsync(new IsolateRunOptions
|
var isolateResult = await _isolateService.RunAsync(new IsolateRunOptions
|
||||||
{
|
{
|
||||||
BoxId = boxId,
|
BoxId = boxId,
|
||||||
Executable = $"/box/{executableName}",
|
Executable = "/usr/bin/mono",
|
||||||
|
Arguments = new[] { $"/box/{executableName}" },
|
||||||
TimeLimitSeconds = timeLimitMs / 1000.0,
|
TimeLimitSeconds = timeLimitMs / 1000.0,
|
||||||
WallTimeLimitSeconds = (timeLimitMs / 1000.0) * 2,
|
WallTimeLimitSeconds = (timeLimitMs / 1000.0) * 2,
|
||||||
MemoryLimitKb = memoryLimitMb * 1024,
|
MemoryLimitKb = memoryLimitMb * 1024,
|
||||||
StackLimitKb = 256 * 1024,
|
StackLimitKb = 256 * 1024,
|
||||||
ProcessLimit = 1, // Single process for C#
|
ProcessLimit = 64, // Mono may create multiple threads/processes
|
||||||
EnableNetwork = false,
|
EnableNetwork = false,
|
||||||
StdinFile = sandboxInputPath,
|
StdinFile = sandboxInputPath,
|
||||||
StdoutFile = outputFilePath,
|
StdoutFile = outputFilePath,
|
||||||
WorkingDirectory = "/box"
|
StderrFile = stderrFilePath,
|
||||||
|
WorkingDirectory = "/box",
|
||||||
|
DirectoryBindings = new List<DirectoryBinding>
|
||||||
|
{
|
||||||
|
new DirectoryBinding { HostPath = "/usr/lib", SandboxPath = "/usr/lib", ReadOnly = true },
|
||||||
|
new DirectoryBinding { HostPath = "/lib", SandboxPath = "/lib", ReadOnly = true },
|
||||||
|
new DirectoryBinding { HostPath = "/usr/share", SandboxPath = "/usr/share", ReadOnly = true },
|
||||||
|
new DirectoryBinding { HostPath = "/etc/mono", SandboxPath = "/etc/mono", ReadOnly = true },
|
||||||
|
new DirectoryBinding { HostPath = "/usr/bin", SandboxPath = "/usr/bin", ReadOnly = true }
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
@@ -95,10 +107,19 @@ public class CSharpExecutionServiceIsolate : IExecutionService
|
|||||||
result.Output = await File.ReadAllTextAsync(outputFilePath);
|
result.Output = await File.ReadAllTextAsync(outputFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read stderr
|
||||||
|
var stderrContent = string.Empty;
|
||||||
|
if (File.Exists(stderrFilePath))
|
||||||
|
{
|
||||||
|
stderrContent = await File.ReadAllTextAsync(stderrFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
// Map Isolate result to ExecutionResult
|
// Map Isolate result to ExecutionResult
|
||||||
result.ExecutionTimeMs = (long)(isolateResult.CpuTimeSeconds * 1000);
|
result.ExecutionTimeMs = (long)(isolateResult.CpuTimeSeconds * 1000);
|
||||||
result.MemoryUsedMb = isolateResult.MemoryUsedKb / 1024;
|
result.MemoryUsedMb = isolateResult.MemoryUsedKb / 1024;
|
||||||
result.ErrorOutput = isolateResult.ErrorOutput;
|
result.ErrorOutput = string.IsNullOrEmpty(stderrContent)
|
||||||
|
? isolateResult.ErrorOutput
|
||||||
|
: $"{stderrContent}\n{isolateResult.ErrorOutput}".Trim();
|
||||||
result.ExitCode = isolateResult.ExitCode;
|
result.ExitCode = isolateResult.ExitCode;
|
||||||
|
|
||||||
if (isolateResult.TimeLimitExceeded)
|
if (isolateResult.TimeLimitExceeded)
|
||||||
|
|||||||
Reference in New Issue
Block a user