Skip to content

Commit

Permalink
Merge pull request #17 from bap14/feature/719-add-php-spx-support
Browse files Browse the repository at this point in the history
wardenenv/images#719 - Add PHP-SPX image build
  • Loading branch information
navarr authored Aug 6, 2024
2 parents 6aa3e76 + 9e1a50e commit 833af28
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
3 changes: 3 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ ENV NGINX_UPSTREAM_HOST php-fpm
ENV NGINX_UPSTREAM_PORT 9000
ENV NGINX_UPSTREAM_DEBUG_HOST php-debug
ENV NGINX_UPSTREAM_DEBUG_PORT 9000
ENV NGINX_UPSTREAM_SPX_HOST php-spx
ENV NGINX_UPSTREAM_SPX_PORT 9000
ENV NGINX_UPSTREAM_BLACKFIRE_HOST php-blackfire
ENV NGINX_UPSTREAM_BLACKFIRE_PORT 9000
ENV NGINX_ROOT /var/www/html
Expand All @@ -20,6 +22,7 @@ COPY etc/nginx/available.d/*.conf /etc/nginx/available.d/
CMD envsubst '${NGINX_UPSTREAM_HOST} ${NGINX_UPSTREAM_PORT} \
${NGINX_UPSTREAM_BLACKFIRE_HOST} ${NGINX_UPSTREAM_BLACKFIRE_PORT} \
${NGINX_UPSTREAM_DEBUG_HOST} ${NGINX_UPSTREAM_DEBUG_PORT} \
${NGINX_UPSTREAM_SPX_HOST} ${NGINX_UPSTREAM_SPX_PORT} \
${NGINX_ROOT} ${NGINX_PUBLIC} ${NGINX_TEMPLATE}' \
< /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf \
&& envsubst '${XDEBUG_CONNECT_BACK_HOST}' \
Expand Down
9 changes: 6 additions & 3 deletions nginx/etc/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
resolver 127.0.0.11;

# Select upstream backend to use based on presense of Xdebug cookies and Blackfire headers
map "$http_X_BLACKFIRE_QUERY:$cookie_XDEBUG_SESSION$cookie_XDEBUG_PROFILE$cookie_XDEBUG_TRACE$arg_XDEBUG_SESSION$arg_XDEBUG_SESSION_START" $fastcgi_backend {
map "$http_X_BLACKFIRE_QUERY:$cookie_XDEBUG_SESSION$cookie_XDEBUG_PROFILE$cookie_XDEBUG_TRACE$arg_XDEBUG_SESSION$arg_XDEBUG_SESSION_START:$cookie_SPX_ENABLED$cookie_SPX_KEY$arg_SPX_ENABLED$arg_SPX_KEY$arg_SPX_UI_URI" $fastcgi_backend {
# Nothing for debug and nothing for blackfire means its a pure request
":" ${NGINX_UPSTREAM_HOST}:${NGINX_UPSTREAM_PORT};
"::" ${NGINX_UPSTREAM_HOST}:${NGINX_UPSTREAM_PORT};

# Use blackfire if the blackfire query is specified AND no debug cookie is set
"~:$" ${NGINX_UPSTREAM_BLACKFIRE_HOST}:${NGINX_UPSTREAM_BLACKFIRE_PORT};
"~::$" ${NGINX_UPSTREAM_BLACKFIRE_HOST}:${NGINX_UPSTREAM_BLACKFIRE_PORT};

# Use SPX if the SPX cookie is specified AND no xdebug cookie is set
"~::.+" ${NGINX_UPSTREAM_SPX_HOST}:${NGINX_UPSTREAM_SPX_PORT};

# In all other cases, a debug cookie will be present; use debug container
default ${NGINX_UPSTREAM_DEBUG_HOST}:${NGINX_UPSTREAM_DEBUG_PORT};
Expand Down
25 changes: 25 additions & 0 deletions php-fpm/spx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ARG ENV_SOURCE_IMAGE
ARG PHP_VERSION
FROM ${ENV_SOURCE_IMAGE}:${PHP_VERSION} AS spx-builder

USER root
RUN dnf install -y php-devel \
&& dnf clean all \
&& rm -rf /var/cache/dnf

RUN set -eux \
&& cd /tmp \
&& git clone https://github.com/NoiseByNorthwest/php-spx.git \
&& cd php-spx \
&& phpize \
&& ./configure \
&& make \
&& sudo make install

FROM ${ENV_SOURCE_IMAGE}:${PHP_VERSION}
COPY --from=spx-builder /usr/lib64/php/modules/spx.so /usr/lib64/php/modules/spx.so
COPY --from=spx-builder /usr/share/misc/php-spx /usr/share/misc/php-spx
COPY spx.ini /etc/php.d/30-spx.ini

ENV SPX_ENABLED=1
USER www-data
13 changes: 13 additions & 0 deletions php-fpm/spx/spx.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extension=spx.so

[spx]
spx.debug=1
spx.http_enabled=1
spx.http_key=warden
spx.http_ip_whitelist="*"
spx.http_profiling_enabled=1
spx.http_profiling_auto_start=1
spx.http_trusted_proxies=REMOTE_ADDR

[zlib]
zlib.output_compression = 0
5 changes: 5 additions & 0 deletions varnish/default.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ sub vcl_recv {
}
}

# Do not handle requests going through SPX
if (req.http.Cookie ~ "SPX_ENABLED" || req.http.Cookie ~ "SPX_KEY" || req.url ~ "(?i)(\?|\&)SPX_UI_URI=" || req.url ~ "(?i)(\?|\&)SPX_KEY=") {
return (pass);
}

# We only deal with GET and HEAD by default
if (req.method != "GET" && req.method != "HEAD") {
return (pass);
Expand Down

0 comments on commit 833af28

Please sign in to comment.