Skip to content

도커 기반 컴파일 파이프라인 구현 #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
w8385 opened this issue Mar 31, 2025 · 5 comments
Closed

도커 기반 컴파일 파이프라인 구현 #22

w8385 opened this issue Mar 31, 2025 · 5 comments
Assignees

Comments

@w8385
Copy link
Member

w8385 commented Mar 31, 2025

  1. 입력 파일, C++ 소스코드 Rust 컨테이너로 전송
  2. 컴파일 및 실행
  3. 출력 파일 반환

위 일련의 과정을 구현합니다.

@w8385 w8385 added this to Bibimbap Mar 31, 2025
@w8385 w8385 self-assigned this Mar 31, 2025
@w8385
Copy link
Member Author

w8385 commented Apr 1, 2025

domjudge

buildscript

  switch ($execlang) {
      case 'c':
          $buildscript .= "gcc -Wall -O2 -std=gnu11 $source -o run -lm\n";
          break;
      case 'cpp':
          $buildscript .= "g++ -Wall -O2 -std=gnu++20 $source -o run\n";
          break;
      case 'java':
          $buildscript .= "javac -cp . -d . $source\n";
          $buildscript .= "echo '#!/bin/sh' > run\n";
          // no main class detection here
          $buildscript .= "echo 'COMPARE_DIR=\$(dirname \"\$0\")' >> run\n";
          $mainClass = basename($unescapedSource, '.java');
          // Note: since the $@ is within single quotes, we do not need to double escape it.
          $buildscript .= "echo 'java -cp \"\$COMPARE_DIR\" $mainClass \"\$@\"' >> run\n";
          $buildscript .= "chmod +x run\n";
          break;
      case 'py':
          $buildscript .= "echo '#!/bin/sh' > run\n";
          $buildscript .= "echo 'COMPARE_DIR=\$(dirname \"\$0\")' >> run\n";
          // Note: since the $@ is within single quotes, we do not need to double escape it.
          $buildscript .= "echo 'python3 \"\$COMPARE_DIR/$source\" \"\$@\"' >> run\n";
          $buildscript .= "chmod +x run\n";
          break;
  }

https://github.com/DOMjudge/domjudge/blob/1530b1aa92558398a66069383efafaf3f1ec71df/judge/judgedaemon.main.php#L428-L452

쉘스크립트 작성하여 빌드 및 실행합니다.

@w8385
Copy link
Member Author

w8385 commented Apr 1, 2025

DMOJ

Grader: 채점 호출

def _launch_process(self, case: TestCase, input_file=None) -> None:
        self._current_proc = self.binary.launch(
            time=self.problem.time_limit,
            memory=self.problem.memory_limit,
            symlinks=case.config.symlinks,
            stdin=input_file or subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            wall_time=case.config.wall_time_factor * self.problem.time_limit,
        )

Grader에서 테스트 케이스와 인풋 데이터를 가지고 채점을 요청합니다.


Executer: 채점 준비

⭐ 여기가 이번 스프린트에서 하려는거 ⭐

BaseExecuter > CompiledExecuter > (CLikeExecuter, JavaExecuter, PythonExecuter ...)
순으로 상속받습니다.

CompiledExecuter의 메타클래스를 활용하여 모든 생성자가 실행된 이후
컴파일이 자동적으로 수행되도록 설계되어 있음.

Executable이 상속 과정에서 생성됩니다.


TracedPopen: 채점 진행

BaseExecuter에서 아래 launch 함수 호출시 채점 프로세스가 실행됩니다.
스레드를 모니터링하면서 TLE, MLE 등의 플래그를 관찰하고
결과를 반환합니다.

def launch(self, *args, **kwargs) -> TracedPopen:
      ...
      return TracedPopen(
          [utf8bytes(a) for a in self.get_cmdline(**kwargs) + list(args)],
          executable=utf8bytes(executable),
          security=self.get_security(launch_kwargs=kwargs, extra_fs=kwargs.get('extra_fs')),
          address_grace=self.get_address_grace(),
          data_grace=self.data_grace,
          personality=self.personality,
          time=kwargs.get('time', 0),
          memory=kwargs.get('memory', 0),
          wall_time=kwargs.get('wall_time'),
          stdin=kwargs.get('stdin'),
          stdout=kwargs.get('stdout'),
          stderr=kwargs.get('stderr'),
          env=child_env,
          cwd=utf8bytes(self._dir),
          nproc=self.get_nproc(),
          fsize=self.fsize,
          cpu_affinity=env.submission_cpu_affinity,
      )

@w8385
Copy link
Member Author

w8385 commented Apr 1, 2025

CMS

https://justicehui.github.io/etc/2021/05/18/cms-1/

제가 찾던 채점 시스템 분석 여기 있네요

@w8385
Copy link
Member Author

w8385 commented Apr 6, 2025

https://github.com/Bibimbap-Team/rpc-playground

  • RPC를 사용한 클라이언트-서버 통신
  • Docker 컨테이너로 작동하는 워커를 통해 소스코드 컴파일 및 실행
  • C99, C++17, C++20, Java8, Python3, PyPy 작동

@w8385 w8385 moved this to In review in Bibimbap Apr 7, 2025
@w8385
Copy link
Member Author

w8385 commented Apr 7, 2025

rpc-playground/
├── docker-compose.yml
├── shared/
│   ├── Main.cpp
│   ├── Main.c
│   ├── Main.py
│   └── ... (생성된 실행 파일들)
├── proto/
│   └── code.proto
├── server/
│   └── main.rs
├── client/
│   └── main.rs
└── worker/
    ├── Dockerfile
    └── run_worker.sh

@w8385 w8385 moved this from In review to Done in Bibimbap Apr 8, 2025
@w8385 w8385 closed this as completed by moving to Done in Bibimbap Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

1 participant