diff --git a/README.md b/README.md index f8e2b5c..2b37f7b 100644 --- a/README.md +++ b/README.md @@ -87,3 +87,21 @@ docker run -e WORDPRESS_VCS_CHECKOUT=1 ghcr.io/aliasproject/php:8.4-frankenphp-w It is unset by default, and only the exact value `1` turns it on. Every frankenphp image (base, `dev`, `wordpress` and `wordpress-dev`, so a WordPress site on the base image is covered too) sets PHP's `auto_prepend_file` to `/usr/local/share/php-prepend/wordpress-vcs-checkout.php`, in `php.ini`. The file is root-owned, and adds `__return_true` to WordPress's `automatic_updates_is_vcs_checkout` filter before WordPress loads (WordPress 4.7 or newer). That covers web requests, WP-Cron when a web request runs it, and WP-CLI run with `docker exec` in the frankenphp container (a system cron calling `docker exec php wp-cli.phar cron event run`, for example; the images don't ship WP-CLI itself). Only WP-CLI in a separate CLI container needs the image built from `php/8.4/cli/Dockerfile.wordpress`, which carries the same file; CI doesn't build or publish that image. With the variable unset the file does nothing. With it set, the only effect on code that isn't WordPress is a global `$wp_filter` array with that one entry. Manual updates from wp-admin or `wp core update` still work. If `getenv` is in `PHP_DISABLE_FUNCTIONS`, the file can't read the variable and does nothing. A derived image that sets its own `auto_prepend_file` (a Wordfence WAF, say) replaces this one, whether it edits the `auto_prepend_file` line in `php.ini`, appends its own line there or adds any `conf.d` file: PHP reads `conf.d` after `php.ini`, and the last setting wins. When `PHP_OPEN_BASEDIR` is set, the frankenphp images add `/usr/local/share/php-prepend/` to it, because PHP refuses every request whose prepend file it can't open. An image that sets `open_basedir` some other way (its own `conf.d` file) has to add that directory itself. + +## Laravel for Rust dev image + +`laravel-rust/Dockerfile.dev` is a development image for [Laravel for Rust](https://laravel.com/rust/docs) apps (the `laravel-rust` crate), as [Ingot](https://github.com/aliasproject/ingot) runs them. It isn't built by CI or published yet. Build it from its folder: + +```sh +docker build -f laravel-rust/Dockerfile.dev -t laravel-rust:dev laravel-rust +``` + +It has Rust 1.99 with `rustfmt` and `clippy`, Node 24, and the Laravel CLI 0.3.0. The CLI is a pinned release archive, checked against the release's `sha256.sum`. The image is Debian-based because the CLI has no Alpine build for arm64. + +The project is mounted at `/app`, and the container runs `laravel dev`, which runs the app's `npm run dev`. In an app made with `laravel new`, that script runs three processes: the server, which `nodemon` restarts with `cargo run` when `src/`, `Cargo.toml`, `Cargo.lock` or `.env` changes; a queue worker; and Vite. If `node_modules` isn't installed, the container's own `laravel dev` command installs it first. Other commands, such as `laravel migrate`, don't, and neither does `laravel dev` wrapped in a shell or with options before `dev`. After a lockfile change, run `npm ci` in the container yourself. Those packages are built for Linux. On macOS or Windows, where `/app` is your host folder, a host-side `npm run dev` then fails on them, so run npm in the container, or run `npm ci` again on the host before using it there. + +- **Address:** the app listens on `SERVER_HOST=0.0.0.0` and `SERVER_PORT=80`. Real environment variables take precedence over the app's `.env`. +- **User:** run the container as your own UID in group 0 (`--user "$(id -u):0"`), so the files it writes to `/app` (`target/`, `node_modules/`, `public/build/`) belong to you. `HOME` is `/home/app`, writable by group 0. +- **Caches:** `CARGO_HOME` is `/usr/local/cargo`. Mount volumes at its `registry`, `git` and `build` folders to keep downloaded crates and compiled dependencies across containers. New apps compile into `build/`, through Cargo's `build-dir`. The folders exist in the image, writable by group 0, so a new volume mounted there is writable too. Don't mount a volume over `CARGO_HOME` itself: it also holds `cargo` and `rustc`, which the volume would pin to an old version. +- **Stopping:** `tini` is PID 1 and passes `docker stop`'s signal to the whole process group, so `laravel dev` and the processes it runs stop promptly. +- **Console commands:** use `laravel migrate`, `laravel route:list` and so on. diff --git a/laravel-rust/Dockerfile.dev b/laravel-rust/Dockerfile.dev new file mode 100644 index 0000000..5e87a4d --- /dev/null +++ b/laravel-rust/Dockerfile.dev @@ -0,0 +1,106 @@ +# syntax=docker/dockerfile:1 +# +# Development image for Laravel for Rust apps (the laravel-rust crate), as +# Ingot runs them: the project is bind-mounted at /app and `laravel dev` +# serves it. That command runs the app's `npm run dev`, which in a new +# Laravel for Rust app restarts `cargo run` on every change to src/, +# Cargo.toml, Cargo.lock or .env, runs a queue worker, and runs Vite. +# +# Build context: this folder. +# +# Not for production: a Laravel for Rust app ships as one release binary +# (see the app's own Dockerfile). +ARG RUST_VERSION=1.99 +ARG NODE_VERSION=24 +FROM node:${NODE_VERSION}-bookworm-slim AS node + +FROM rust:${RUST_VERSION}-bookworm + +LABEL maintainer="Michael Aguiar " + +# The Laravel CLI (`laravel dev`, `laravel migrate`, ...). Pinned to a +# release of laravel/cli-releases and checked against its published +# sha256.sum, instead of piping laravel.com/install.sh to a shell. There +# are only glibc builds for arm64, which is why this image is Debian, not +# Alpine. +ARG LARAVEL_CLI_VERSION=0.3.0 +ARG LARAVEL_CLI_SHA256_AMD64=b9271c4f929a24875c915681fe0d004139e004d4d4ade95c743569066b98ce69 +ARG LARAVEL_CLI_SHA256_ARM64=005faf367ee41acd30b39bf7e86654fa37474c67ad662ec86392e48932840525 +ARG TARGETARCH + +# Node and npm for Vite, copied from the official image (same Debian +# release, so the same glibc). +COPY --from=node /usr/local/bin/node /usr/local/bin/node +COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules + +RUN set -eux; \ + ln -s ../lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm; \ + ln -s ../lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx; \ + node --version; npm --version; \ + \ + # TARGETARCH is only set by BuildKit; the legacy builder leaves it empty. + arch="${TARGETARCH:-$(dpkg --print-architecture)}"; \ + case "$arch" in \ + amd64) target=x86_64-unknown-linux-gnu; sha256=$LARAVEL_CLI_SHA256_AMD64 ;; \ + arm64) target=aarch64-unknown-linux-gnu; sha256=$LARAVEL_CLI_SHA256_ARM64 ;; \ + *) echo "unsupported architecture: $arch" >&2; exit 1 ;; \ + esac; \ + archive="laravel-cli-$target.tar.xz"; \ + curl -fsSLo "/tmp/$archive" "https://github.com/laravel/cli-releases/releases/download/v$LARAVEL_CLI_VERSION/$archive"; \ + echo "$sha256 /tmp/$archive" | sha256sum -c -; \ + mkdir /tmp/laravel-cli; \ + tar -xJf "/tmp/$archive" -C /tmp/laravel-cli; \ + install -m 0755 "$(find /tmp/laravel-cli -type f -name laravel | head -n1)" /usr/local/bin/laravel; \ + rm -rf /tmp/laravel-cli "/tmp/$archive"; \ + laravel --version; \ + \ + rustup component add rustfmt clippy; \ + # The official image leaves RUSTUP_HOME world-writable so any user can + # install a toolchain or component (an app's rust-toolchain.toml can ask + # for one); keep that true for what was just added as root. Only the + # files that aren't yet: a chmod on the rest could copy the whole + # toolchain into this layer. + find "$RUSTUP_HOME" ! -perm -o+w -exec chmod a+w {} +; \ + \ + # tini runs as PID 1 and (with -g) passes signals to the whole process + # group, so `docker stop` (and Ingot's idle stop) reaches laravel dev + # and its nodemon and cargo children instead of waiting out the timeout + # and killing them mid-build. + apt-get update; \ + apt-get install -y --no-install-recommends tini; \ + rm -rf /var/lib/apt/lists/*; \ + \ + # Ingot mounts shared volumes at these folders so downloaded crates and + # compiled dependencies outlive the container (new Laravel for Rust apps + # set Cargo's build-dir to {cargo-cache-home}/build/laravel-rust). A new + # volume takes the ownership and mode of the folder it is mounted on, + # and the container runs as the host user's UID in group 0, so the + # folders must exist here, writable by group 0. (The rest of CARGO_HOME + # is already world-writable in the official image.) + mkdir -p "$CARGO_HOME/registry" "$CARGO_HOME/git" "$CARGO_HOME/build"; \ + chgrp 0 "$CARGO_HOME/registry" "$CARGO_HOME/git" "$CARGO_HOME/build"; \ + chmod 2775 "$CARGO_HOME/registry" "$CARGO_HOME/git" "$CARGO_HOME/build"; \ + \ + # A home for whatever UID the container runs as: npm's cache and the + # Laravel CLI's config live under $HOME. + mkdir -p /home/app; \ + chgrp 0 /home/app; \ + chmod 2775 /home/app + +ENV HOME=/home/app \ + SERVER_HOST=0.0.0.0 \ + SERVER_PORT=80 + +WORKDIR /app + +# Ingot runs the container as the host user's UID in group 0, so files the +# app writes to /app (target/, public/build/, storage/) belong to that +# user. Without Ingot, pass --user "$(id -u):0" for the same. +USER 1000:0 + +COPY docker-entrypoint /usr/local/bin/docker-entrypoint + +EXPOSE 80 + +ENTRYPOINT ["tini", "-g", "--", "docker-entrypoint"] +CMD ["laravel", "dev"] diff --git a/laravel-rust/docker-entrypoint b/laravel-rust/docker-entrypoint new file mode 100755 index 0000000..52ea2b1 --- /dev/null +++ b/laravel-rust/docker-entrypoint @@ -0,0 +1,20 @@ +#!/bin/sh +# `laravel dev` runs the app's `npm run dev` (server, queue worker and Vite +# under concurrently and nodemon), so it needs node_modules, and nothing +# else installs them in a project that was cloned rather than made with +# `laravel new`. Install them before `laravel dev` when npm hasn't (no +# node_modules/.package-lock.json, which npm writes once an install has +# finished). Other commands (`laravel migrate`, a shell) start as they are. +# After a lockfile change, run `npm ci` in the container yourself. +set -e + +if [ "$1" = laravel ] && [ "$2" = dev ] && [ -f package.json ] && [ ! -f node_modules/.package-lock.json ]; then + echo "docker-entrypoint: node_modules isn't installed, installing it" >&2 + if [ -f package-lock.json ]; then + npm ci --no-audit --no-fund + else + npm install --no-audit --no-fund + fi +fi + +exec "$@"