diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b7af9d..b4a21a5 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.5' + 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 6e48b4a..aa30779 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,26 @@ 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. 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 \ + 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 --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 && \ + echo extension=utopia.so > /utopia/conf.d/utopia.ini; \ + fi + FROM trusted-base AS final RUN apk upgrade --no-cache @@ -206,6 +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 /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 @@ -217,6 +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 +COPY --from=utopia /utopia/conf.d/ /usr/local/etc/php/conf.d/ EXPOSE 80 diff --git a/Makefile b/Makefile index ae107b7..cdf1c93 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,7 @@ build: test: build container-structure-test test --image $(IMAGE) --config tests.yaml + 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 new file mode 100644 index 0000000..f277838 --- /dev/null +++ b/tests-utopia.yaml @@ -0,0 +1,19 @@ +schemaVersion: '2.0.0' + +# The utopia extension, built on PHP 8.5 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 hashes and verifies passwords with Argon2' + command: "php" + # 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"] diff --git a/versions/8.3.env b/versions/8.3.env index 5b33d1c..bb6e292 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 +# 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 3932eba..64da9ee 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 +# The utopia extension needs PHP 8.5; empty builds the image without it +PHP_UTOPIA_VERSION= 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