Skip to content

Refactor how we use run() docker command - #426

Open
lyrixx wants to merge 1 commit into
mainfrom
docker-run
Open

Refactor how we use run() docker command#426
lyrixx wants to merge 1 commit into
mainfrom
docker-run

Conversation

@lyrixx

@lyrixx lyrixx commented Aug 3, 2026

Copy link
Copy Markdown
Member
  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

I did that, because I needed exec() on another project, and the logic between run and exec are very close

@lyrixx lyrixx changed the title Move some code from builder() to docker_run() Refactor how we use run() docker command Aug 5, 2026
@lyrixx
lyrixx requested review from loic425 and pyrech and a lite review from Copilot August 5, 2026 13:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to list<string> token arrays.
  • Refactors builder() to delegate to the updated docker_compose_run() behavior.
  • Adds docker_compose_exec() helper for docker compose exec support.

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 forces withAllowFailure() for any non-interactive invocation. This changes behavior for callers like castor install/qa tasks that rely on a non-zero exit to fail fast; errors may be silently ignored unless every caller checks the returned Process. Only add withAllowFailure() 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 forces withAllowFailure() 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.

Comment thread .castor/docker.php
Comment thread .castor/docker.php
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

@pyrech pyrech left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants