Skip to content

Run the sandbox on a remote Docker host #336

Closed

Description

@AydinHassan

Goal

Run student code on a separate Docker host (a Fly.io machine over WireGuard) instead of the web server. Changing provider later means changing DOCKER_HOST and the ports host, nothing else.

Tasks

Design now (php-workshop src/Process)

  • Sandbox\SandboxFactory: one for the app, HostSandboxFactory or DockerSandboxFactory. Holds the setup (docker binary, image, network, ports host, port picker). create($directory, $scenario) gives a Sandbox.
  • Sandbox\Sandbox: one per solution, reference and student. Holds the directory and the port. execute(ProcessInput) gives a SandboxExecution, getPort() the port.
  • Sandbox\SandboxExecution: one run, a single class. start, wait, output, getAddress().
  • Sandbox\ProcessInput: just the command, executable, args, env, stdin.
  • Port\PortPicker: FreePortPicker locally, LockPortPicker (Redis lock, 60s, 5 tries) on the website.

The exercise says ->exposePort(). The factory picks one port per solution and Docker publishes it the same inside and out, -p host:N:N. The exercise puts it in its args on the pre events with $event->getSandbox()->getPort() and connects on the executing events with $event->getExecution()->getAddress().

Next: one container per solution

  • DockerSandboxFactory::create() starts a container for the solution with the port published, and copies the files in once: find . ! -type d | tar -c -T - | docker exec -i c tar -x -C /solution (files only, tar can't chmod image-owned dirs), -v /solution anonymous volume.
  • DockerSandbox::execute() is a docker exec with timeout -s KILL 30.
  • When the sandbox is done the container is removed (rm -f -v) and the port lock released, so the lock no longer needs a fixed 60s.
  • The old prototype (local branch exec-per-folder) cut verify from ~6s to ~2.5s. Rewrite it on the new classes rather than rebasing.

Notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions