From 474bd10a3e20e15a484a281368b446d0a0b5b5db Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 23 Nov 2026 19:13:59 +0530 Subject: [PATCH 1/4] feat: build the utopia PHP extension into the image utopia-php/auth 0.13 gets its password hashes from the utopia extension (ext-utopia), a Rust extension built from appwrite/appwrite's crates, and services on utopia-base can't load it today. A new stage builds it at a commit pinned in versions/*.env, like the other extensions; rustup takes the toolchain from the checkout's rust-toolchain.toml. The final image already has libheif and libwebp, which it links against. Co-Authored-By: Claude Opus 5.5 --- Dockerfile | 18 ++++++++++++++++++ tests.yaml | 13 ++++++++++++- versions/8.3.env | 2 ++ versions/8.4.env | 2 ++ versions/8.5.env | 2 ++ 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6e48b4a..1b8514a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,6 +25,7 @@ ARG PHP_SNAPPY_VERSION ARG PHP_LZ4_VERSION ARG PHP_XDEBUG_VERSION ARG PHP_MONGO_VERSION +ARG PHP_UTOPIA_VERSION RUN \ apk add --no-cache --virtual .deps \ @@ -164,6 +165,21 @@ RUN \ make && make install && \ strip --strip-unneeded /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/*.so +# The utopia extension: Utopia libraries implemented in Rust (auth's password hashes, +# validators, image, ...), built from appwrite/appwrite's crates at a pinned commit. +# rustup reads the toolchain from the checkout's rust-toolchain.toml. +FROM compile AS utopia +RUN apk add --no-cache rustup clang-dev libheif-dev libwebp-dev && \ + rustup-init -y --profile minimal --default-toolchain none +RUN git init appwrite && cd appwrite && \ + git remote add origin https://github.com/appwrite/appwrite.git && \ + git sparse-checkout set --no-cone /Cargo.toml /Cargo.lock /rust-toolchain.toml /rustfmt.toml /.cargo /crates && \ + git fetch --depth 1 origin $PHP_UTOPIA_VERSION && git checkout -q FETCH_HEAD && \ + . "$HOME/.cargo/env" && \ + cargo build --release --locked -p utopia-extension && \ + strip --strip-unneeded target/release/libutopia.so && \ + cp target/release/libutopia.so /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/utopia.so + FROM trusted-base AS final RUN apk upgrade --no-cache @@ -206,6 +222,7 @@ COPY --from=lz4 /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/lz4.so COPY --from=snappy /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/snappy.so /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/ COPY --from=xdebug /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/xdebug.so /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/ COPY --from=mongodb /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/mongodb.so /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/ +COPY --from=utopia /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/utopia.so /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/ RUN echo extension=swoole.so >> /usr/local/etc/php/conf.d/swoole.ini RUN echo extension=redis.so >> /usr/local/etc/php/conf.d/redis.ini @@ -217,6 +234,7 @@ RUN echo extension=brotli.so >> /usr/local/etc/php/conf.d/brotli.ini RUN echo extension=lz4.so >> /usr/local/etc/php/conf.d/lz4.ini RUN echo extension=snappy.so >> /usr/local/etc/php/conf.d/snappy.ini RUN echo extension=mongodb.so >> /usr/local/etc/php/conf.d/mongodb.ini +RUN echo extension=utopia.so >> /usr/local/etc/php/conf.d/utopia.ini EXPOSE 80 diff --git a/tests.yaml b/tests.yaml index 3b6df27..2542f84 100644 --- a/tests.yaml +++ b/tests.yaml @@ -32,6 +32,9 @@ fileExistenceTests: - name: 'Check mongodb ini' path: /usr/local/etc/php/conf.d/mongodb.ini shouldExist: true + - name: 'Check utopia ini' + path: /usr/local/etc/php/conf.d/utopia.ini + shouldExist: true fileContentTests: - name: 'swoole ini' @@ -64,6 +67,9 @@ fileContentTests: - name: 'mongodb ini' path: '/usr/local/etc/php/conf.d/mongodb.ini' expectedContents: ['extension=mongodb.so'] + - name: 'utopia ini' + path: '/usr/local/etc/php/conf.d/utopia.ini' + expectedContents: ['extension=utopia.so'] commandTests: - name: 'Imagemagick command' @@ -88,4 +94,9 @@ commandTests: - ".*brotli.*" - ".*lz4.*" - ".*snappy.*" - - ".*mongodb.*" \ No newline at end of file + - ".*mongodb.*" + - ".*utopia.*" + - name: 'utopia extension provides auth password hashes' + command: "php" + args: ["-r", "echo class_exists('Utopia\\Auth\\Hashes\\Argon2') ? 'argon2 ok' : 'argon2 missing';"] + expectedOutput: ["argon2 ok"] diff --git a/versions/8.3.env b/versions/8.3.env index 5b33d1c..5b61252 100644 --- a/versions/8.3.env +++ b/versions/8.3.env @@ -14,3 +14,5 @@ PHP_SNAPPY_VERSION=0.2.2 PHP_LZ4_VERSION=0.4.4 PHP_XDEBUG_VERSION=3.5.1 PHP_MONGO_VERSION=2.2.1 +# appwrite/appwrite commit the utopia extension is built from (the auth/0.13.0 release) +PHP_UTOPIA_VERSION=93cadfb09067ddef3e52aa730a7caff805c2fcf3 diff --git a/versions/8.4.env b/versions/8.4.env index 3932eba..a0d3338 100644 --- a/versions/8.4.env +++ b/versions/8.4.env @@ -14,3 +14,5 @@ PHP_SNAPPY_VERSION=0.2.2 PHP_LZ4_VERSION=0.4.4 PHP_XDEBUG_VERSION=3.5.1 PHP_MONGO_VERSION=2.2.1 +# appwrite/appwrite commit the utopia extension is built from (the auth/0.13.0 release) +PHP_UTOPIA_VERSION=93cadfb09067ddef3e52aa730a7caff805c2fcf3 diff --git a/versions/8.5.env b/versions/8.5.env index 732e294..90a484f 100644 --- a/versions/8.5.env +++ b/versions/8.5.env @@ -14,3 +14,5 @@ PHP_SNAPPY_VERSION=ddc8b58d8892593695a17c2b83d72ba3e9f41f64 PHP_LZ4_VERSION=bf27b2c13922b6fbeb2eac5251be4e8a95d01e36 PHP_XDEBUG_VERSION=3.5.1 PHP_MONGO_VERSION=2.2.1 +# appwrite/appwrite commit the utopia extension is built from (the auth/0.13.0 release) +PHP_UTOPIA_VERSION=93cadfb09067ddef3e52aa730a7caff805c2fcf3 From 1d79913ddd7985d7ada2ea0848f36b049e103e8b Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 23 Nov 2026 19:22:33 +0530 Subject: [PATCH 2/4] fix: build the utopia extension on PHP 8.4+ only The extension's crate needs PHP 8.4 (it calls ext-php-rs's is_lazy, which exists only for 8.4+), so the PHP 8.3 build failed. 8.3 now leaves PHP_UTOPIA_VERSION empty and the stage builds nothing; the 8.3 image stays as before. The utopia checks move to tests-utopia.yaml, which CI and `make test` run on 8.4+. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 4 ++++ Dockerfile | 31 ++++++++++++++++++------------- Makefile | 1 + tests-utopia.yaml | 18 ++++++++++++++++++ tests.yaml | 13 +------------ versions/8.3.env | 4 ++-- 6 files changed, 44 insertions(+), 27 deletions(-) create mode 100644 tests-utopia.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b7af9d..e4acda0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -96,6 +96,10 @@ jobs: - name: Run container structure tests run: container-structure-test test --image utopia-base-test --config tests.yaml + - name: Run utopia extension structure tests + if: matrix.php-versions != '8.3' + run: container-structure-test test --image utopia-base-test --config tests-utopia.yaml + - name: Check Swoole upload marker handling run: docker run --rm -v "$PWD/tests-swoole.php:/tests-swoole.php:ro" utopia-base-test php /tests-swoole.php diff --git a/Dockerfile b/Dockerfile index 1b8514a..380f8ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -167,18 +167,23 @@ RUN \ # The utopia extension: Utopia libraries implemented in Rust (auth's password hashes, # validators, image, ...), built from appwrite/appwrite's crates at a pinned commit. -# rustup reads the toolchain from the checkout's rust-toolchain.toml. +# rustup reads the toolchain from the checkout's rust-toolchain.toml. It needs PHP 8.4+, +# so an empty PHP_UTOPIA_VERSION (PHP 8.3) builds nothing and the image goes without it. FROM compile AS utopia -RUN apk add --no-cache rustup clang-dev libheif-dev libwebp-dev && \ - rustup-init -y --profile minimal --default-toolchain none -RUN git init appwrite && cd appwrite && \ - git remote add origin https://github.com/appwrite/appwrite.git && \ - git sparse-checkout set --no-cone /Cargo.toml /Cargo.lock /rust-toolchain.toml /rustfmt.toml /.cargo /crates && \ - git fetch --depth 1 origin $PHP_UTOPIA_VERSION && git checkout -q FETCH_HEAD && \ - . "$HOME/.cargo/env" && \ - cargo build --release --locked -p utopia-extension && \ - strip --strip-unneeded target/release/libutopia.so && \ - cp target/release/libutopia.so /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/utopia.so +RUN mkdir -p /utopia/extensions /utopia/conf.d && \ + if [ -n "$PHP_UTOPIA_VERSION" ]; then \ + apk add --no-cache rustup clang-dev libheif-dev libwebp-dev && \ + rustup-init -y --profile minimal --default-toolchain none && \ + . "$HOME/.cargo/env" && \ + git init appwrite && cd appwrite && \ + git remote add origin https://github.com/appwrite/appwrite.git && \ + git sparse-checkout set --no-cone /Cargo.toml /Cargo.lock /rust-toolchain.toml /rustfmt.toml /.cargo /crates && \ + git fetch --depth 1 origin "$PHP_UTOPIA_VERSION" && git checkout -q FETCH_HEAD && \ + cargo build --release --locked -p utopia-extension && \ + strip --strip-unneeded target/release/libutopia.so && \ + cp target/release/libutopia.so /utopia/extensions/utopia.so && \ + echo extension=utopia.so > /utopia/conf.d/utopia.ini; \ + fi FROM trusted-base AS final @@ -222,7 +227,7 @@ COPY --from=lz4 /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/lz4.so COPY --from=snappy /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/snappy.so /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/ COPY --from=xdebug /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/xdebug.so /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/ COPY --from=mongodb /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/mongodb.so /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/ -COPY --from=utopia /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/utopia.so /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/ +COPY --from=utopia /utopia/extensions/ /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API}/ RUN echo extension=swoole.so >> /usr/local/etc/php/conf.d/swoole.ini RUN echo extension=redis.so >> /usr/local/etc/php/conf.d/redis.ini @@ -234,7 +239,7 @@ RUN echo extension=brotli.so >> /usr/local/etc/php/conf.d/brotli.ini RUN echo extension=lz4.so >> /usr/local/etc/php/conf.d/lz4.ini RUN echo extension=snappy.so >> /usr/local/etc/php/conf.d/snappy.ini RUN echo extension=mongodb.so >> /usr/local/etc/php/conf.d/mongodb.ini -RUN echo extension=utopia.so >> /usr/local/etc/php/conf.d/utopia.ini +COPY --from=utopia /utopia/conf.d/ /usr/local/etc/php/conf.d/ EXPOSE 80 diff --git a/Makefile b/Makefile index ae107b7..32e0166 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,7 @@ build: test: build container-structure-test test --image $(IMAGE) --config tests.yaml + if [ "$(VERSION)" != "8.3" ]; then container-structure-test test --image $(IMAGE) --config tests-utopia.yaml; fi all: @for v in $(VERSIONS); do $(MAKE) build VERSION=$$v || exit $$?; done diff --git a/tests-utopia.yaml b/tests-utopia.yaml new file mode 100644 index 0000000..3b6c25c --- /dev/null +++ b/tests-utopia.yaml @@ -0,0 +1,18 @@ +schemaVersion: '2.0.0' + +# The utopia extension, built on PHP 8.4+ only (see Dockerfile). + +fileContentTests: + - name: 'utopia ini' + path: '/usr/local/etc/php/conf.d/utopia.ini' + expectedContents: ['extension=utopia.so'] + +commandTests: + - name: 'utopia extension loaded' + command: "php" + args: ["-m"] + expectedOutput: [".*utopia.*"] + - name: 'utopia extension provides auth password hashes' + command: "php" + args: ["-r", "echo class_exists('Utopia\\Auth\\Hashes\\Argon2') ? 'argon2 ok' : 'argon2 missing';"] + expectedOutput: ["argon2 ok"] diff --git a/tests.yaml b/tests.yaml index 2542f84..3b6df27 100644 --- a/tests.yaml +++ b/tests.yaml @@ -32,9 +32,6 @@ fileExistenceTests: - name: 'Check mongodb ini' path: /usr/local/etc/php/conf.d/mongodb.ini shouldExist: true - - name: 'Check utopia ini' - path: /usr/local/etc/php/conf.d/utopia.ini - shouldExist: true fileContentTests: - name: 'swoole ini' @@ -67,9 +64,6 @@ fileContentTests: - name: 'mongodb ini' path: '/usr/local/etc/php/conf.d/mongodb.ini' expectedContents: ['extension=mongodb.so'] - - name: 'utopia ini' - path: '/usr/local/etc/php/conf.d/utopia.ini' - expectedContents: ['extension=utopia.so'] commandTests: - name: 'Imagemagick command' @@ -94,9 +88,4 @@ commandTests: - ".*brotli.*" - ".*lz4.*" - ".*snappy.*" - - ".*mongodb.*" - - ".*utopia.*" - - name: 'utopia extension provides auth password hashes' - command: "php" - args: ["-r", "echo class_exists('Utopia\\Auth\\Hashes\\Argon2') ? 'argon2 ok' : 'argon2 missing';"] - expectedOutput: ["argon2 ok"] + - ".*mongodb.*" \ No newline at end of file diff --git a/versions/8.3.env b/versions/8.3.env index 5b61252..b20e982 100644 --- a/versions/8.3.env +++ b/versions/8.3.env @@ -14,5 +14,5 @@ PHP_SNAPPY_VERSION=0.2.2 PHP_LZ4_VERSION=0.4.4 PHP_XDEBUG_VERSION=3.5.1 PHP_MONGO_VERSION=2.2.1 -# appwrite/appwrite commit the utopia extension is built from (the auth/0.13.0 release) -PHP_UTOPIA_VERSION=93cadfb09067ddef3e52aa730a7caff805c2fcf3 +# The utopia extension needs PHP 8.4+; empty builds the image without it +PHP_UTOPIA_VERSION= From 5f2215b8313362abf064088a5c8f9cf813295fee Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 23 Nov 2026 19:40:38 +0530 Subject: [PATCH 3/4] fix: build the utopia extension on PHP 8.5 only On PHP 8.4 the extension builds but doesn't load: it calls zend_undefined_method, which only PHP 8.5's engine exports. Build and test it on 8.5 only; the 8.3 and 8.4 images stay as before. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 2 +- Dockerfile | 4 ++-- Makefile | 2 +- tests-utopia.yaml | 2 +- versions/8.3.env | 2 +- versions/8.4.env | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e4acda0..b4a21a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -97,7 +97,7 @@ jobs: run: container-structure-test test --image utopia-base-test --config tests.yaml - name: Run utopia extension structure tests - if: matrix.php-versions != '8.3' + if: matrix.php-versions == '8.5' run: container-structure-test test --image utopia-base-test --config tests-utopia.yaml - name: Check Swoole upload marker handling diff --git a/Dockerfile b/Dockerfile index 380f8ce..8657ef5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -167,8 +167,8 @@ RUN \ # The utopia extension: Utopia libraries implemented in Rust (auth's password hashes, # validators, image, ...), built from appwrite/appwrite's crates at a pinned commit. -# rustup reads the toolchain from the checkout's rust-toolchain.toml. It needs PHP 8.4+, -# so an empty PHP_UTOPIA_VERSION (PHP 8.3) builds nothing and the image goes without it. +# rustup reads the toolchain from the checkout's rust-toolchain.toml. It uses PHP 8.5's +# engine API, so an empty PHP_UTOPIA_VERSION (8.3, 8.4) builds nothing and the image goes without it. FROM compile AS utopia RUN mkdir -p /utopia/extensions /utopia/conf.d && \ if [ -n "$PHP_UTOPIA_VERSION" ]; then \ diff --git a/Makefile b/Makefile index 32e0166..cdf1c93 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ build: test: build container-structure-test test --image $(IMAGE) --config tests.yaml - if [ "$(VERSION)" != "8.3" ]; then container-structure-test test --image $(IMAGE) --config tests-utopia.yaml; fi + if [ "$(VERSION)" = "8.5" ]; then container-structure-test test --image $(IMAGE) --config tests-utopia.yaml; fi all: @for v in $(VERSIONS); do $(MAKE) build VERSION=$$v || exit $$?; done diff --git a/tests-utopia.yaml b/tests-utopia.yaml index 3b6c25c..0bb5cc0 100644 --- a/tests-utopia.yaml +++ b/tests-utopia.yaml @@ -1,6 +1,6 @@ schemaVersion: '2.0.0' -# The utopia extension, built on PHP 8.4+ only (see Dockerfile). +# The utopia extension, built on PHP 8.5 only (see Dockerfile). fileContentTests: - name: 'utopia ini' diff --git a/versions/8.3.env b/versions/8.3.env index b20e982..bb6e292 100644 --- a/versions/8.3.env +++ b/versions/8.3.env @@ -14,5 +14,5 @@ PHP_SNAPPY_VERSION=0.2.2 PHP_LZ4_VERSION=0.4.4 PHP_XDEBUG_VERSION=3.5.1 PHP_MONGO_VERSION=2.2.1 -# The utopia extension needs PHP 8.4+; empty builds the image without it +# The utopia extension needs PHP 8.5; empty builds the image without it PHP_UTOPIA_VERSION= diff --git a/versions/8.4.env b/versions/8.4.env index a0d3338..64da9ee 100644 --- a/versions/8.4.env +++ b/versions/8.4.env @@ -14,5 +14,5 @@ PHP_SNAPPY_VERSION=0.2.2 PHP_LZ4_VERSION=0.4.4 PHP_XDEBUG_VERSION=3.5.1 PHP_MONGO_VERSION=2.2.1 -# appwrite/appwrite commit the utopia extension is built from (the auth/0.13.0 release) -PHP_UTOPIA_VERSION=93cadfb09067ddef3e52aa730a7caff805c2fcf3 +# The utopia extension needs PHP 8.5; empty builds the image without it +PHP_UTOPIA_VERSION= From 2508f60c202c0788984ea05b3262cad08adf3c8e Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 23 Nov 2026 20:01:21 +0530 Subject: [PATCH 4/4] fix: fetch only the needed files and test Argon2 end to end The sparse checkout still fetched every file of the appwrite commit; --filter=blob:none fetches only the checked-out ones (483 MB to 6 MB, same files). The structure test now hashes a password and verifies the right and a wrong one, instead of only checking that the class exists. Co-Authored-By: Claude Opus 5.5 --- Dockerfile | 2 +- tests-utopia.yaml | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8657ef5..aa30779 100644 --- a/Dockerfile +++ b/Dockerfile @@ -178,7 +178,7 @@ RUN mkdir -p /utopia/extensions /utopia/conf.d && \ git init appwrite && cd appwrite && \ git remote add origin https://github.com/appwrite/appwrite.git && \ git sparse-checkout set --no-cone /Cargo.toml /Cargo.lock /rust-toolchain.toml /rustfmt.toml /.cargo /crates && \ - git fetch --depth 1 origin "$PHP_UTOPIA_VERSION" && git checkout -q FETCH_HEAD && \ + git fetch --depth 1 --filter=blob:none origin "$PHP_UTOPIA_VERSION" && git checkout -q FETCH_HEAD && \ cargo build --release --locked -p utopia-extension && \ strip --strip-unneeded target/release/libutopia.so && \ cp target/release/libutopia.so /utopia/extensions/utopia.so && \ diff --git a/tests-utopia.yaml b/tests-utopia.yaml index 0bb5cc0..f277838 100644 --- a/tests-utopia.yaml +++ b/tests-utopia.yaml @@ -12,7 +12,8 @@ commandTests: command: "php" args: ["-m"] expectedOutput: [".*utopia.*"] - - name: 'utopia extension provides auth password hashes' + - name: 'utopia extension hashes and verifies passwords with Argon2' command: "php" - args: ["-r", "echo class_exists('Utopia\\Auth\\Hashes\\Argon2') ? 'argon2 ok' : 'argon2 missing';"] + # No `$` in the code: container-structure-test expands $NAME in args as environment variables. + args: ["-r", "define('HASH', (new Utopia\\Auth\\Hashes\\Argon2())->hash('pw')); echo str_starts_with(HASH, chr(36) . 'argon2') && (new Utopia\\Auth\\Hashes\\Argon2())->verify('pw', HASH) && !(new Utopia\\Auth\\Hashes\\Argon2())->verify('wrong', HASH) ? 'argon2 ok' : 'argon2 broken';"] expectedOutput: ["argon2 ok"]