Refactor how we use run() docker command - #426
Open
lyrixx wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors the Castor Docker helpers to pass commands as token arrays (instead of shell strings), centralizing command construction in .castor/docker.php and introducing a new docker_compose_exec() helper to align behavior between run and exec.
Changes:
- Switches many
docker_compose_run()/docker_exit_code()call sites from string commands tolist<string>token arrays. - Refactors
builder()to delegate to the updateddocker_compose_run()behavior. - Adds
docker_compose_exec()helper fordocker compose execsupport.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| castor.php | Updates install-related commands to call docker_compose_run() using token arrays. |
| .castor/qa.php | Converts QA commands to token arrays; refactors PHPStan command building to array form. |
| .castor/init.php | Converts project init commands (composer/sed) to token arrays for docker_compose_run(). |
| .castor/docker.php | Refactors docker_compose_run()/docker_exit_code(), simplifies builder(), adds docker_compose_exec(). |
Suppressed comments (2)
.castor/docker.php:473
docker_compose_run()currently forceswithAllowFailure()for any non-interactive invocation. This changes behavior for callers likecastor install/qatasks that rely on a non-zero exit to fail fast; errors may be silently ignored unless every caller checks the returnedProcess. Only addwithAllowFailure()in helpers that explicitly want to capture exit codes (e.g.docker_exit_code()/builder).
if (0 === \count($params)) {
$params = ['bash'];
$c = $c->toInteractive();
} else {
$c = $c->withTty(false)->withPty(false)->withInput(STDIN)->withAllowFailure();
$params = array_map(escapeshellarg(...), $params);
}
.castor/docker.php:503
docker_compose_exec()also forceswithAllowFailure()for non-interactive execution. For consistency with other task helpers, it should not suppress failures by default; callers that want to capture exit codes can opt into allow-failure via the passed context or a dedicated helper.
if (0 === \count($params)) {
$params = ['bash'];
$context = $context->toInteractive();
} else {
$context = $context->withTty(false)->withPty(false)->withInput(STDIN)->withAllowFailure();
$params = array_map(escapeshellarg(...), $params);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1. use array insteand of string, it's more secure, and easier to manipulate data 2. move many code from the builder to to the run() command 3. add an exec() command 4. and remove run_in_docker_or_locally_for_mac, not used anymore
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.
manipulate data