Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wardenenv/images#719 - Add PHP-SPX image build #17

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
11 changes: 8 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,17 @@
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 {
volatile;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@navarr I was having issues with cookies not being respected; however, it could have been because of Varnish caching the requests. This line shouldn't need to be there.


# 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
14 changes: 14 additions & 0 deletions php-fpm/spx/spx.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extension=spx.so

[spx]
spx.debug=1
spx.http_enabled=1
spx.http_key=warden
; spx.http_ip_var=X_FORWARDED_FOR
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