Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests-utopia.yaml
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 2 additions & 0 deletions versions/8.3.env
Original file line number Diff line number Diff line change
Expand Up @@ -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=
2 changes: 2 additions & 0 deletions versions/8.4.env
Original file line number Diff line number Diff line change
Expand Up @@ -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=
2 changes: 2 additions & 0 deletions versions/8.5.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading