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

Add initial "NGINX Unit" based image #875

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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
32 changes: 31 additions & 1 deletion Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
def is_alpine:
env.variant | index("alpine")
-}}
{{ if env.variant == "unit" then ( -}}
FROM unit:{{ .unit.version }}-php{{ env.phpVersion }}
{{ ) else ( -}}
FROM php:{{ env.phpVersion }}-{{ env.variant }}
{{ ) end -}}

{{ if env.version != "cli" then ( -}}
# persistent dependencies
Expand Down Expand Up @@ -252,12 +256,38 @@ VOLUME /var/www/html

{{ if env.version != "cli" then ( -}}
COPY --chown=www-data:www-data wp-config-docker.php /usr/src/wordpress/
{{ if env.variant == "unit" then ( -}}

# NGINX Unit specific bits
WORKDIR /var/www/html
RUN set -eux; \
# save Unit's entrypoint so we can successfully/correctly configure Unit at runtime
sed -e 's/docker-entrypoint/unit-entrypoint/g' /usr/local/bin/docker-entrypoint.sh > /usr/local/bin/unit-entrypoint.sh; \
grep -F '/unit-entrypoint.d/' /usr/local/bin/unit-entrypoint.sh; \
chmod +x /usr/local/bin/unit-entrypoint.sh; \
\
{ \
echo; \
echo '// WordPress does not support NGINX Unit (yet), so we have to do a little hackery to let it know that Unit supports nice permalinks (and prevent it from insisting on injecting "/index.php" in all the permalink options) -- the simplest way is teaching it to recognize Unit as if it were NGINX (which is only semi-true, but true enough for these purposes)'; \
echo '$is_nginx = $is_nginx || str_starts_with($_SERVER["SERVER_SOFTWARE"], "Unit/");'; \
echo '// see also https://github.com/WordPress/WordPress/blob/39f7f558d91afdd2f3afc7f3b049a6a800cd3f80/wp-includes/vars.php#L127'; \
} >> /usr/src/wordpress/wp-config-docker.php
COPY unit.json /unit-entrypoint.d/wordpress.json

{{ ) else "" end -}}
{{ ) else "" end -}}
COPY docker-entrypoint.sh /usr/local/bin/

ENTRYPOINT ["docker-entrypoint.sh"]
{{ if env.version != "cli" then ( -}}
CMD {{ [ if env.variant == "apache" then "apache2-foreground" else "php-fpm" end ] | @json }}
CMD {{
{
apache: [ "apache2-foreground" ],
# https://github.com/nginx/unit/blob/fb33ec86a3b6ca6a844dfa6980bb9e083094abec/pkg/docker/Dockerfile.php8.2#L89
unit: [ "unitd", "--no-daemon", "--control", "unix:/var/run/control.unit.sock" ],
Copy link
Member Author

Choose a reason for hiding this comment

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

nextcloud/docker#1610 (comment) makes an excellent case for probably removing --control here 😅

}[env.variant] // [ "php-fpm" ]
| @json
}}
{{ ) else ( -}}
USER www-data
CMD ["wp", "shell"]
Expand Down
8 changes: 8 additions & 0 deletions apply-templates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ for version; do
for variant in "${variants[@]}"; do
export variant

if [ "$variant" = 'unit' ] && jq -e '.[env.version][env.variant].phpVersions | index(env.phpVersion) | not' versions.json > /dev/null; then
continue
fi

dir="$version/php$phpVersion/$variant"
mkdir -p "$dir"

Expand All @@ -58,6 +62,10 @@ for version; do
else
cp -a docker-entrypoint.sh wp-config-docker.php "$dir/"
fi

if [ "$variant" = 'unit' ]; then
cp -a unit.json "$dir/"
fi
done
done
done
10 changes: 9 additions & 1 deletion beta/php8.1/apache/docker-entrypoint.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion beta/php8.1/fpm-alpine/docker-entrypoint.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion beta/php8.1/fpm/docker-entrypoint.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion beta/php8.2/apache/docker-entrypoint.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion beta/php8.2/fpm-alpine/docker-entrypoint.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion beta/php8.2/fpm/docker-entrypoint.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading