Repository navigation
Exercises pick their port up front, docker picks where it is published - #343
Merged
Merged
Conversation
A port free on this machine is free in a sandbox container too, so exercises pick it once with System::freePort() and docker publishes it on a free host port. Checks ask the execution where to connect, from the executing event. SandboxHost goes, so nothing asks this machine about ports on the docker host.
DockerSandbox picks the published port itself, random by default, so it knows the address without a docker port lookup. A shared docker host can pass a picker that remembers ports in use.
…domPortPicker FreePortPicker is a port free on this machine: exercises use it, and DockerSandbox by default. LockPortPicker claims a random port with a symfony/lock lock, for a docker host shared by many runs.
AydinHassan
added a commit
to php-school/phpschool.io
that referenced
this pull request
Nov 1, 2026
Uses php-workshop's `LockPortPicker` (php-school/php-workshop#343): `CloudWorkshopRepository` passes it to each workshop's `DockerSandbox`, with a `LockFactory` on our Redis, so verifies sharing the docker host never publish on the same port. The picker is required, so it can't be forgotten. Also updates php-workshop, which brings in symfony/lock. Checked against a throwaway Redis: picked ports are locked for 60s and a second claim of the same port is refused.
3 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step 2 of the simpler sandbox plan (#336): every run should go through the same container workflow, so a port must be known before the container is made.
defineTestScenario(), withFreePortPicker. It is free on this machine, and every port is free in a fresh sandbox container, so the CLI on a laptop never clashes.DockerSandboxpublishes it on a host port from aPortPicker(constructor option):-p <portsHost>:<picked>:<port>. The default isFreePortPicker, right when docker runs on this machine.LockPortPickerclaims a random port with a symfony/lock lock (new dependency) for a docker host shared by many verifies: phpschool.io passes it aLockFactoryon its Redis.SandboxExecution::getAddress(int $port)says where to connect, eg.127.0.0.1:54321on the host or10.0.0.5:47213in docker (the execution keeps the host once and a port map) (pass an IPv6portsHostin brackets, eg.[fdaa::2]).$event->getExecution()->getAddress($port).SandboxHost,Sandbox::getHost(),ExecutionContext::getSandboxHost()and the dispatcher's sandbox argument go.Time Server follows in learn-you-php. Checked with its verify (correct, no server, wrong output) and run, with
SANDBOX=dockerand on the host.