Skip to content

Add a Laravel for Rust dev image (ALI-2447) - #23

Closed
michaelaguiar wants to merge 5 commits into
mainfrom
ali-2447-laravel-rust-dev-image
Closed

michaelaguiar wants to merge 5 commits into
mainfrom
ali-2447-laravel-rust-dev-image

Conversation

@michaelaguiar

@michaelaguiar michaelaguiar commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Part of ALI-2446. This adds laravel-rust/Dockerfile.dev, a development image for Laravel for Rust apps, the way Ingot runs them (aliasproject/ingot#19). The project is mounted at /app, and the container runs laravel dev as the host user in group 0.

What's in it

  • Toolchain: Rust 1.99 (official Debian image) with rustfmt and clippy, plus Node 24 copied from the official Node image.
  • Laravel CLI 0.3.0: a pinned release archive from laravel/cli-releases, checked against the release's sha256.sum, instead of piping laravel.com/install.sh to a shell. The CLI has no Alpine (musl) build for arm64, so the image is Debian.
  • Entrypoint: laravel dev runs the app's npm run dev (server, queue worker and Vite) but doesn't install node_modules. Before laravel dev, the entrypoint installs them when npm's node_modules/.package-lock.json is missing. Other commands start as they are.
  • tini: PID 1, with -g, so docker stop (and Ingot's idle stop) reaches laravel dev, nodemon and cargo at once.
  • Cache folders: CARGO_HOME's registry, git and build folders exist and are writable by group 0. Ingot mounts shared volumes there, and a new volume takes the ownership of the folder it's mounted on.
  • Environment: HOME=/home/app is writable by any UID in group 0, and SERVER_HOST=0.0.0.0 / SERVER_PORT=80 are set.
  • Builders: both work. TARGETARCH falls back to dpkg --print-architecture, because the legacy builder doesn't set it.

Not in this PR: publishing

CI doesn't build or publish this image: build-and-push.yml is unchanged, so merging publishes nothing. Publishing needs decisions first:

  • the package name (Ingot expects ghcr.io/aliasproject/laravel-rust:dev, in project.LaravelRustImage);
  • making the new GHCR package public, as Ingot pulls without logging in;
  • the tag scheme (by Rust version, for example 1.99-dev);
  • whether it joins the weekly rebuild and the smoke test.

That can be a follow-up PR once those are settled.

Testing

On the M1 (arm64, Docker 29, legacy builder):

  • The image builds, the CLI checksum passes, and laravel --version prints 0.3.0.
  • Fresh app: laravel new example-app --rust inside the image downloaded, installed and compiled the starter app in about 33s, using cache volumes mounted like Ingot's.
  • The fresh app under laravel dev, run as Ingot will run it (--user <uid>:0, bind mount, the three cache volumes, SERVER_HOST, SERVER_PORT, APP_URL), with node_modules deleted first:
    • the entrypoint installed it;
    • /up returned 200 about 10s after start;
    • laravel migrate, run through docker exec, worked;
    • appending to a file in src/ made nodemon rebuild and restart the server in 4.8s.
  • Ownership: target/ and node_modules/ belong to the host user, and the cache folders are 775, group 0.
  • GPS server/: compiled in 26s, ran its 16 migrations and served /up (200) and / (302 to sign-in).

On the desktop (amd64, BuildKit), at head ca4859b:

  • The image builds, and the toolchain step's layer is 30 MB (the toolchain itself is 617 MB, so it isn't copied).
  • A fresh app compiles in 21s.
  • laravel migrate runs without an npm install.
  • Under laravel dev, the entrypoint installs node_modules, and /up returns 200 in about 10s.
  • An edit restarts the server under nodemon.
  • target/ and node_modules/ belong to the host user.
  • docker stop takes 0.3s.

On the M1, the review fixes were rechecked: rustfmt is writable as a non-root UID, and tini -g stops a whole process group in about 0.1s.

Not tested: GPS under laravel dev. GPS's package.json only has "dev": "vite", so laravel dev would start only Vite. GPS needs the starter's dev, dev:server and dev:queue scripts (ALI-2452). The GPS test above ran cargo run directly.

Rust 1.99, Node 24 and the Laravel CLI 0.3.0 (pinned, checked against
the release's sha256.sum), running laravel dev against /app as the host
user in group 0. Cargo's registry, git and build folders exist and are
group-0 writable, so the shared volumes Ingot mounts there are writable.
…E (ALI-2447)

laravel dev runs the app's npm run dev and doesn't install node_modules,
so a cloned project started with only Vite's 'not found'. The entrypoint
installs them when they're missing.

TARGETARCH is only set by BuildKit; fall back to dpkg's architecture so
the legacy builder works too.
…e_modules (ALI-2447)

The recursive chgrp/chmod over CARGO_HOME and RUSTUP_HOME changed
nothing (the official image already makes them world-writable), so it
now sets only the three cache folders Ingot mounts volumes on.

The README now says node_modules installed in the container are built
for Linux, which breaks a host-side npm run dev on macOS and Windows.
@michaelaguiar

michaelaguiar commented Dec 1, 2026 •

Copy link
Copy Markdown
Member Author

Review round 1

A fresh-context review of 186a999. The code-review skill ran against the wrong repository (it looked for the branch in the Ingot checkout), so the reviewer discarded its output and reviewed the diff by hand. The review was static only, with no Docker builds, because a benchmark was running on that machine. No P1 or P2 findings. The reviewer confirmed:

  • both CLI checksums match the v0.3.0 sha256.sum;
  • the glibc-only claim for arm64 holds;
  • the cache folders match the framework's build-dir;
  • the user, HOME and environment match the ticket;
  • the branch triggers no publish.

Fixed in ef04d13

  • Recursive chgrp/chmod over CARGO_HOME and RUSTUP_HOME. The reviewer expected this to copy the toolchain into a new layer. Measuring on the M1 showed it didn't: the RUN layer is 26.7 MB, and the base already has both folders at mode 777, owned by root. The step was redundant, though, so it now sets only the three cache folders. Rebuilt on the M1: the folders are 2775 0:0, and a brand-new volume mounted on build/ is writable as UID 1001 in group 0.
  • On Docker Desktop, node_modules installed by the entrypoint are built for Linux, which breaks a host-side npm run dev. The README now says so.

Declined

  • The README tags the image laravel-rust:dev, but the ticket proposes 1.99-dev. The tag scheme belongs to the publishing follow-up, which also changes Ingot's project.LaravelRustImage, as the PR body lists. This PR publishes nothing.

…for laravel dev (ALI-2447)

rustfmt and clippy were added as root after the base image made
RUSTUP_HOME world-writable, so a non-root update or removal of them
failed; restore the base's a+w.

Without an init, laravel dev was PID 1 and docker stop (and Ingot's idle
stop) waited out the timeout before killing it mid-build; tini forwards
the signal (stop now takes ~0.1s).

The entrypoint installed node_modules before any command, so a one-off
laravel migrate in a fresh clone ran a full npm ci first, and it trusted
a partial node_modules from an interrupted install. It now installs only
before laravel dev, when npm's node_modules/.package-lock.json is
missing.
@michaelaguiar

Copy link
Copy Markdown
Member Author

Review round 2

A fresh-context review of ef04d13. code-review ran against the PR this time. The review was static; the M1 results below are mine.

Fixed in 9f305fc (rebuilt on the M1 and the whole loop re-run with a fresh laravel new --rust app)

  • RUSTUP_HOME was no longer fully writable (P2). rustfmt and clippy are added as root after the base image's chmod -R a+w, and ef04d13 had dropped the recursive change that covered them. A non-root user could still add a component (tested: rustup component add rust-src as UID 1001 worked), but couldn't update or remove those two. The base's a+w is now reapplied after rustup component add. Checked: rustfmt is writable as UID 1001, and the layer costs nothing extra because those files are new in it.
  • No init process. laravel dev was PID 1, so docker stop (and Ingot's idle stop) would wait out the timeout and kill it mid-build. tini is now PID 1. Checked: docker stop on the running app took 104 ms.
  • The entrypoint ran npm ci before any command, and accepted a partial node_modules. It now installs only before laravel dev, and only when npm's node_modules/.package-lock.json is missing. Checked: laravel migrate in an app without node_modules ran three migrations with no npm install, and laravel dev then installed it and served /up (200) in about 10s. An edit to src/ restarted the app under nodemon.

Declined

  • Group-0 folders are 2775, so --user 1000:1000 can't write the caches. The README and Ingot both use group 0. A world-writable shared cache would let any UID tamper with another's compiled dependencies.
  • Binding port 80 as non-root depends on Docker's ip_unprivileged_port_start=0. Docker sets it on bridge networks, which is what Ingot uses, and SERVER_PORT can be changed for anything else.
  • A node_modules installed on a macOS or Windows host is accepted. It passes the marker check, and Vite would then fail on Linux binaries. Telling that apart means guessing at platform packages; the README note covers the case.
  • amd64 hasn't been built yet. That's waiting for the desktop to be free and will be reported here.

…roup (ALI-2447)

A recursive chmod over the toolchain could copy all of it into the layer
under BuildKit (the legacy builder measured 28.5 MB either way); find
now touches only files that aren't already world-writable.

tini -g sends docker stop's signal to the whole process group, so
nodemon and cargo get it too, not only the laravel CLI. The README says
which commands install node_modules.
@michaelaguiar

Copy link
Copy Markdown
Member Author

Review round 3

A narrow fresh-context review of 9f305fc. code-review ran. No P1. The reviewer confirmed the entrypoint's quoting and set -e handling, the retry after a partial install, and tini's placement and apt cleanup.

Fixed in ca4859b (rebuilt and checked on the M1)

  • chmod -R a+w over the toolchain could copy it into the layer (P2). On the M1's legacy builder it doesn't: the layer is 28.5 MB against a 520 MB toolchain. BuildKit, which CI and the amd64 build use, computes diffs differently, so the step now uses find "$RUSTUP_HOME" ! -perm -o+w -exec chmod a+w {} + and touches only the files that need it. Checked: the layer is still 28.5 MB, no file under RUSTUP_HOME is left non-writable, and rustfmt is writable as UID 1001.
  • tini passed the signal to laravel only. It now runs with -g and signals the whole process group. Checked: a container with child processes in the group stopped in 105 ms.
  • The README now says which commands install node_modules: only the container's own laravel dev, not laravel dev wrapped in a shell or with options before dev.

Declined

  • A package.json with no dependencies may never produce node_modules/.package-lock.json. If so, laravel dev reruns a quick, harmless npm install on each start. Laravel for Rust apps always have dependencies (Vite at least).

Stopping the review here: three rounds, and this round's fixes are small and verified. Left: the amd64 build, which waits for the desktop to be free.

@michaelaguiar

Copy link
Copy Markdown
Member Author

Closing: the image moved, unchanged, to its own repo in aliasproject/docker-rust#1, which adds CI that builds it on native amd64 and arm64 runners and boots a new laravel new --rust app on each. Publishing there stays off until the PUBLISH_IMAGES repository variable is set.

@michaelaguiar
michaelaguiar deleted the ali-2447-laravel-rust-dev-image branch December 2, 2026 12:12
michaelaguiar added a commit to aliasproject/docker-rust that referenced this pull request Dec 2, 2026
* Add the Laravel for Rust dev image, with CI that builds and boots it (ALI-2447)

Moved from aliasproject/docker-php#23, where it was reviewed and tested
on amd64 and arm64: a dev image for Laravel for Rust apps as Ingot runs
them (Rust 1.99, Node 24, the Laravel CLI 0.3.0 checked against its
sha256, an entrypoint that installs node_modules before laravel dev,
tini as PID 1, Cargo cache folders writable by group 0).

build.yml builds it on native amd64 and arm64 runners and runs
smoke-test.sh, which makes a new app with laravel new --rust and checks
laravel dev serves /up, restarts on an edit, writes files as the calling
user and stops promptly. Publishing to ghcr.io/aliasproject/laravel-rust
stays off until the PUBLISH_IMAGES repository variable is true.

* Smoke test: don't pipe docker logs into grep -q under pipefail

The amd64 run failed 'the entrypoint didn't install node_modules' although
/up had answered (laravel dev can't start without node_modules). grep -q
exits at its first match; docker logs, still writing, then fails, and
pipefail fails the whole check. arm64 passed only by timing. The log
checks now read the logs into a string first, and the container check
compares docker ps output instead of piping it.

* Publish only from main; harden the smoke test (ALI-2447)

Review findings on the new workflow and smoke test:
- With PUBLISH_IMAGES on, a manual run on any branch would have tagged
  that branch's image as dev, the tag Ingot pulls. Publishing now also
  requires refs/heads/main.
- The publish job can't be cancelled part-way by a newer run (its own
  concurrency group), so dev and dev-<sha> aren't split.
- Jobs time out (45 and 10 minutes) instead of GitHub's 6 hours.
- The restart check also waits for cargo's Finished after nodemon's
  restart line, since the old server answers /up until it's killed.
- laravel migrate waits for Postgres to accept connections first.
- The final rm in cleanup can't fail a passing run.
- The README says Markdown-only changes don't trigger a build.

* Don't cancel runs on main; wait for Postgres over TCP (ALI-2447)

Round 2 review: the workflow-level concurrency group still cancelled an
older run on main, publish job included, so the job-level group didn't
keep dev and dev-<sha> together. Runs on main now queue; other refs
still cancel. And pg_isready over the Unix socket can answer during the
image's first-start temporary server, before Postgres listens on TCP,
which the app uses; it now checks 127.0.0.1.

* Describe how runs on main wait for each other (ALI-2447)
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