Skip to content

Separate Composer and PHP development services - #19

Merged
gachakra merged 5 commits into
mainfrom
chore/separate-composer-service
Dec 3, 2026
Merged

gachakra merged 5 commits into
mainfrom
chore/separate-composer-service

Conversation

@gachakra

@gachakra gachakra commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • Separate one-shot dependency installation from the long-running PHP CLI service.
  • Share the existing PHP image and project bind mount, including host-visible vendor/.
  • Retain Composer downloads in a named cache volume.
  • Gate PHP startup on successful Composer completion and preserve the image entrypoint with multiline shell commands.
  • Update Docker development instructions, including explicit install/update, shared-vendor concurrency, and Linux file ownership notes.

This PR is independent of the API changes in #18. No PHP source, Dockerfile, dependencies, or CI configuration changes.

Verification

The existing hosted CI checks the PHP package, not the Compose workflow. A Docker engine is unavailable in the authoring environment; an actual image build and Compose startup/failure-path smoke test remain to be performed during review.

@gachakra gachakra left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Reviewed 291a52c0e59eb38e91c5278c18576f956fccf8d0. Fresh startup works as intended. I found two issues with the shared image build and the documented failure behavior.

  • On Docker Compose v2.40.3, a clean up -d --build --remove-orphans waited for Composer to exit 0 before starting PHP. With Composer forced to exit 1, up returned 1 and left PHP in created. I also verified the manual install and Composer command override. The inline comments contain the rebuild and restart reproductions.
  • On PHP 8.4.28 and 8.5.13, PHPUnit passed with 345 tests and 1,458 assertions per version. All 25 examples passed with assertions enabled. Composer validation, platform requirements, strict PSR-4 autoloading, PHP lint, and the PHPStan 2.3.7 CI checks passed on both versions. The selection fixture reported its 13 expected existing diagnostics. The Git and Composer distribution archives each matched the expected file list.
  • Docker checks ran on Docker Desktop using isolated resource names. Native Linux bind-mount ownership remains unverified.

Comment thread docker-compose.yml Outdated
- php-enumex

composer:
<<: *php-image

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

[P3] Build the shared image from a single service

The anchor gives both services a build and the same output tag. Compose v2.40.3 exports two image IDs with different com.docker.compose.service labels, and repeated builds can leave either ID tagged as php-enumex:local. I reproduced a PHP replacement without touching the Dockerfile by running docker compose build php → docker compose up -d --no-build → docker compose build composer → docker compose up -d --no-build. The last command replaced the running PHP container, interrupting any exec sessions. Give one service ownership of the build and let the other reference the resulting image. I verified that keeping build on composer and setting pull_policy: never on the image-only php service allows a fresh up -d --build with one image ID.

Comment thread README.md Outdated
Wait until the PHP service logs show `Composer installation complete`. On the first run, dependencies may still be installing after the container starts. Press Ctrl+C to stop following the logs (the PHP container remains running), then enter the PHP container and run the example:
Both services use the same PHP 8.4 CLI image and mount the project directory. The one-shot `composer` service installs the locked development dependencies into the host project's `vendor/` directory, then exits. The `php` service starts after Composer exits successfully and remains available for development. The host IDE and both services see the same installed dependencies. The named `composer-cache` volume retains downloaded package data independently of the installed dependencies.

An exited Composer service with exit code 0 is expected. If installation fails, inspect `docker compose logs composer`; the dependent PHP service will not start successfully.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

[P3] Scope the installation failure guarantee to fresh startup

An already-running PHP container stays running if a subsequent up fails to reinstall dependencies. Also, with a broken lock file in a disposable checkout, docker compose restart returned 0 and PHP accepted exec commands even though Composer exited 1. This can make a stale vendor/ look ready after a restart. State that a fresh up waits for a successful installation, and point readers to the explicit docker compose run --rm composer command for dependency resynchronization while PHP is running.

@gachakra gachakra left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Re-reviewed 4ee1bad2bf7e71c4504dae6cb49510ce95288c99. Both prior findings are addressed. I found no additional actionable issues.

  • Docker Compose v2.40.3 built one shared image. docker compose build composer followed by docker compose up -d --no-build kept the same image ID and running PHP container. A broken lock file blocked PHP on fresh startup. With PHP already running, failed reinstallation and restart behaved as the revised README describes. The explicit install returned a failure status, and startup recovered after restoring the lock file.
  • The coding-style update puts the constructor before static factories and gives normal methods a default order based on responsibility. The guidance preserves cohesive method groups and existing member organization. I checked it against AGENTS.md and ran the new CaseLabel snippet with assertions covering identity, naming, transformation, and string conversion on both supported PHP versions.
  • PHP 8.4.28 and 8.5.13 each passed 345 PHPUnit tests, 1,458 assertions, all 25 executable examples, and the PHPStan 2.3.7 CI checks. The selection fixture reported the same 13 expected diagnostics on both versions. Composer validation, platform checks, strict PSR-4, PHP lint, and Git and Composer archive checks also passed. Native Linux file ownership remains unverified because the Compose checks ran on Docker Desktop.

@gachakra
gachakra marked this pull request as ready for review December 3, 2026 07:59
@gachakra
gachakra merged commit dd89613 into main Dec 3, 2026
2 checks passed
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.

1 participant