diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index ab10870..7414710 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - version: [ '8.0', '8.1', '8.2', '8.3' ] + version: [ '8.1', '8.2', '8.3', '8.4' ] type: [ '', '-prod' ] steps: @@ -37,6 +37,7 @@ jobs: docker run kooldev/wordpress:${{ matrix.version }}-nginx${{ matrix.type }} php -v docker run kooldev/wordpress:${{ matrix.version }}-nginx${{ matrix.type }} wp --allow-root --version docker run kooldev/wordpress:${{ matrix.version }}-nginx${{ matrix.type }} nginx -v + docker run kooldev/wordpress:${{ matrix.version }}-nginx${{ matrix.type }} nginx -t docker run kooldev/wordpress:${{ matrix.version }}-nginx${{ matrix.type }} supervisord version - name: Test docker images wordpress code diff --git a/7.4-nginx/Dockerfile b/7.4-nginx/Dockerfile deleted file mode 100644 index 23c5f57..0000000 --- a/7.4-nginx/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM wordpress:cli-php7.4 as wordpress-cli -FROM wordpress:php7.4-fpm-alpine as wordpress -FROM kooldev/php:7.4-nginx - -ENV NGINX_ROOT=/app - -COPY --from=wordpress-cli /usr/local/bin/wp /usr/local/bin/wp -COPY --from=wordpress --chown=kool:kool /usr/src/wordpress /kool/wordpress -COPY --from=wordpress --chown=kool:kool /var/www/html/wp-content /app/wp-content -COPY entrypoint /kool/wordpress-entrypoint - -RUN chmod -R 777 wp-content && chmod +x /kool/wordpress-entrypoint - -ENTRYPOINT [ "/kool/wordpress-entrypoint" ] -CMD [ "supervisord", "-c", "/kool/supervisor.conf" ] diff --git a/7.4-nginx/entrypoint b/7.4-nginx/entrypoint deleted file mode 100644 index 845d991..0000000 --- a/7.4-nginx/entrypoint +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/bash -set -eo pipefail - -# Nginx server config -dockerize -template /kool/default.tmpl:/etc/nginx/conf.d/default.conf - -# Run as current user -CURRENT_USER=${ASUSER:-${UID:-0}} - -if [ ! -z "$CURRENT_USER" ] && [ "$CURRENT_USER" != "0" ]; then - usermod -u $CURRENT_USER kool -fi - -# user/group for Wordpress -user=kool -group=kool -uid=$(id -u) - -if [ "$1" = 'php-fpm' ] || [ "$1" = 'supervisord' ]; then - # Original Wordpress Entrypoint - fresh install if none exists - if [ ! -e index.php ] && [ ! -e wp-includes/version.php ]; then - # if the directory exists and WordPress doesn't appear to be installed AND the permissions of it are root:root, let's chown it (likely a Docker-created directory) - if [ "$uid" = '0' ] && [ "$(stat -c '%u:%g' .)" = '0:0' ]; then - chown "$user:$group" . - fi - - echo >&2 "WordPress not found in $PWD - copying now..." - if [ -n "$(find -mindepth 1 -maxdepth 1 -not -name wp-content)" ]; then - echo >&2 "WARNING: $PWD is not empty! (copying anyhow)" - fi - sourceTarArgs=( - --create - --file - - --directory /kool/wordpress - --owner "$user" --group "$group" - ) - targetTarArgs=( - --extract - --file - - ) - if [ "$uid" != '0' ]; then - # avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted" - targetTarArgs+=( --no-overwrite-dir ) - fi - # loop over "pluggable" content in the source, and if it already exists in the destination, skip it - # https://github.com/docker-library/wordpress/issues/506 ("wp-content" persisted, "akismet" updated, WordPress container restarted/recreated, "akismet" downgraded) - for contentPath in \ - /kool/wordpress/.htaccess \ - /kool/wordpress/wp-content/*/*/ \ - ; do - contentPath="${contentPath%/}" - [ -e "$contentPath" ] || continue - contentPath="${contentPath#/kool/wordpress/}" # "wp-content/plugins/akismet", etc. - if [ -e "$PWD/$contentPath" ]; then - echo >&2 "WARNING: '$PWD/$contentPath' exists! (not copying the WordPress version)" - sourceTarArgs+=( --exclude "./$contentPath" ) - fi - done - tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}" - echo >&2 "Complete! WordPress has been successfully copied to $PWD" - fi - - wpEnvs=( "${!WORDPRESS_@}" ) - if [ ! -s wp-config.php ] && [ "${#wpEnvs[@]}" -gt 0 ]; then - for wpConfigDocker in \ - wp-config-docker.php \ - /kool/wordpress/wp-config-docker.php \ - ; do - if [ -s "$wpConfigDocker" ]; then - echo >&2 "No 'wp-config.php' found in $PWD, but 'WORDPRESS_...' variables supplied; copying '$wpConfigDocker' (${wpEnvs[*]})" - # using "awk" to replace all instances of "put your unique phrase here" with a properly unique string (for AUTH_KEY and friends to have safe defaults if they aren't specified with environment variables) - awk ' - /put your unique phrase here/ { - cmd = "head -c1m /dev/urandom | sha1sum | cut -d\\ -f1" - cmd | getline str - close(cmd) - gsub("put your unique phrase here", str) - } - { print } - ' "$wpConfigDocker" > wp-config.php - if [ "$uid" = '0' ]; then - # attempt to ensure that wp-config.php is owned by the run user - # could be on a filesystem that doesn't allow chown (like some NFS setups) - chown "$user:$group" wp-config.php || true - fi - break - fi - done - fi -fi - -exec /kool/entrypoint "$@" diff --git a/8.0-nginx/Dockerfile b/8.0-nginx/Dockerfile deleted file mode 100644 index fbb1f06..0000000 --- a/8.0-nginx/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM wordpress:cli-php8.0 as wordpress-cli -FROM wordpress:php8.0-fpm-alpine as wordpress -FROM kooldev/php:8.0-nginx - -ENV NGINX_ROOT=/app - -COPY --from=wordpress-cli /usr/local/bin/wp /usr/local/bin/wp -COPY --from=wordpress --chown=kool:kool /usr/src/wordpress /kool/wordpress -COPY --from=wordpress --chown=kool:kool /var/www/html/wp-content /app/wp-content -COPY entrypoint /kool/wordpress-entrypoint - -RUN chmod -R 777 wp-content && chmod +x /kool/wordpress-entrypoint - -ENTRYPOINT [ "/kool/wordpress-entrypoint" ] -CMD [ "supervisord", "-c", "/kool/supervisor.conf" ] diff --git a/8.0-nginx/entrypoint b/8.0-nginx/entrypoint deleted file mode 100644 index 845d991..0000000 --- a/8.0-nginx/entrypoint +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/bash -set -eo pipefail - -# Nginx server config -dockerize -template /kool/default.tmpl:/etc/nginx/conf.d/default.conf - -# Run as current user -CURRENT_USER=${ASUSER:-${UID:-0}} - -if [ ! -z "$CURRENT_USER" ] && [ "$CURRENT_USER" != "0" ]; then - usermod -u $CURRENT_USER kool -fi - -# user/group for Wordpress -user=kool -group=kool -uid=$(id -u) - -if [ "$1" = 'php-fpm' ] || [ "$1" = 'supervisord' ]; then - # Original Wordpress Entrypoint - fresh install if none exists - if [ ! -e index.php ] && [ ! -e wp-includes/version.php ]; then - # if the directory exists and WordPress doesn't appear to be installed AND the permissions of it are root:root, let's chown it (likely a Docker-created directory) - if [ "$uid" = '0' ] && [ "$(stat -c '%u:%g' .)" = '0:0' ]; then - chown "$user:$group" . - fi - - echo >&2 "WordPress not found in $PWD - copying now..." - if [ -n "$(find -mindepth 1 -maxdepth 1 -not -name wp-content)" ]; then - echo >&2 "WARNING: $PWD is not empty! (copying anyhow)" - fi - sourceTarArgs=( - --create - --file - - --directory /kool/wordpress - --owner "$user" --group "$group" - ) - targetTarArgs=( - --extract - --file - - ) - if [ "$uid" != '0' ]; then - # avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted" - targetTarArgs+=( --no-overwrite-dir ) - fi - # loop over "pluggable" content in the source, and if it already exists in the destination, skip it - # https://github.com/docker-library/wordpress/issues/506 ("wp-content" persisted, "akismet" updated, WordPress container restarted/recreated, "akismet" downgraded) - for contentPath in \ - /kool/wordpress/.htaccess \ - /kool/wordpress/wp-content/*/*/ \ - ; do - contentPath="${contentPath%/}" - [ -e "$contentPath" ] || continue - contentPath="${contentPath#/kool/wordpress/}" # "wp-content/plugins/akismet", etc. - if [ -e "$PWD/$contentPath" ]; then - echo >&2 "WARNING: '$PWD/$contentPath' exists! (not copying the WordPress version)" - sourceTarArgs+=( --exclude "./$contentPath" ) - fi - done - tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}" - echo >&2 "Complete! WordPress has been successfully copied to $PWD" - fi - - wpEnvs=( "${!WORDPRESS_@}" ) - if [ ! -s wp-config.php ] && [ "${#wpEnvs[@]}" -gt 0 ]; then - for wpConfigDocker in \ - wp-config-docker.php \ - /kool/wordpress/wp-config-docker.php \ - ; do - if [ -s "$wpConfigDocker" ]; then - echo >&2 "No 'wp-config.php' found in $PWD, but 'WORDPRESS_...' variables supplied; copying '$wpConfigDocker' (${wpEnvs[*]})" - # using "awk" to replace all instances of "put your unique phrase here" with a properly unique string (for AUTH_KEY and friends to have safe defaults if they aren't specified with environment variables) - awk ' - /put your unique phrase here/ { - cmd = "head -c1m /dev/urandom | sha1sum | cut -d\\ -f1" - cmd | getline str - close(cmd) - gsub("put your unique phrase here", str) - } - { print } - ' "$wpConfigDocker" > wp-config.php - if [ "$uid" = '0' ]; then - # attempt to ensure that wp-config.php is owned by the run user - # could be on a filesystem that doesn't allow chown (like some NFS setups) - chown "$user:$group" wp-config.php || true - fi - break - fi - done - fi -fi - -exec /kool/entrypoint "$@" diff --git a/8.1-nginx-prod/Dockerfile b/8.1-nginx-prod/Dockerfile index 29574ed..c90a195 100644 --- a/8.1-nginx-prod/Dockerfile +++ b/8.1-nginx-prod/Dockerfile @@ -1,5 +1,5 @@ -FROM wordpress:cli-php8.1 as wordpress-cli -FROM wordpress:php8.1-fpm-alpine as wordpress +FROM wordpress:cli-php8.1 AS wordpress-cli +FROM wordpress:php8.1-fpm-alpine AS wordpress FROM kooldev/php:8.1-nginx-prod ENV NGINX_ROOT=/app @@ -8,6 +8,7 @@ COPY --from=wordpress-cli /usr/local/bin/wp /usr/local/bin/wp COPY --from=wordpress --chown=kool:kool /usr/src/wordpress /kool/wordpress COPY --from=wordpress --chown=kool:kool /var/www/html/wp-content /app/wp-content COPY entrypoint /kool/wordpress-entrypoint +COPY wordpress-webp.conf /etc/nginx/wordpress-webp.conf RUN chmod -R 777 wp-content && chmod +x /kool/wordpress-entrypoint diff --git a/8.1-nginx-prod/entrypoint b/8.1-nginx-prod/entrypoint index 845d991..e1e4b3c 100644 --- a/8.1-nginx-prod/entrypoint +++ b/8.1-nginx-prod/entrypoint @@ -1,8 +1,9 @@ #!/bin/bash set -eo pipefail -# Nginx server config -dockerize -template /kool/default.tmpl:/etc/nginx/conf.d/default.conf +# Add WebP support for WordPress by injecting include directive +# Insert the include directive before the location / block +sed -i 's/\( location \/ {\)/ # Include WordPress WebP support\n include \/etc\/nginx\/wordpress-webp.conf;\n\n\1/' /kool/default.tmpl # Run as current user CURRENT_USER=${ASUSER:-${UID:-0}} diff --git a/8.1-nginx-prod/wordpress-webp.conf b/8.1-nginx-prod/wordpress-webp.conf new file mode 100644 index 0000000..f1d94fe --- /dev/null +++ b/8.1-nginx-prod/wordpress-webp.conf @@ -0,0 +1,17 @@ +# WordPress WebP support: automatically serve WebP images when available and supported +location ~* ^(.+)\.(jpe?g|png)$ { + set $webp_suffix ""; + + # Check if WebP is supported by the client + if ($http_accept ~* "image/webp") { + set $webp_suffix ".webp"; + } + + # Try to serve the WebP version first, then fallback to original + try_files $uri$webp_suffix $uri /index.php?$query_string; + + # Set appropriate cache headers for images + expires 30d; + add_header Cache-Control "public, immutable"; + add_header Vary "Accept"; +} \ No newline at end of file diff --git a/8.1-nginx/Dockerfile b/8.1-nginx/Dockerfile index db40abc..d4fc5ab 100644 --- a/8.1-nginx/Dockerfile +++ b/8.1-nginx/Dockerfile @@ -1,5 +1,5 @@ -FROM wordpress:cli-php8.1 as wordpress-cli -FROM wordpress:php8.1-fpm-alpine as wordpress +FROM wordpress:cli-php8.1 AS wordpress-cli +FROM wordpress:php8.1-fpm-alpine AS wordpress FROM kooldev/php:8.1-nginx ENV NGINX_ROOT=/app @@ -8,6 +8,7 @@ COPY --from=wordpress-cli /usr/local/bin/wp /usr/local/bin/wp COPY --from=wordpress --chown=kool:kool /usr/src/wordpress /kool/wordpress COPY --from=wordpress --chown=kool:kool /var/www/html/wp-content /app/wp-content COPY entrypoint /kool/wordpress-entrypoint +COPY wordpress-webp.conf /etc/nginx/wordpress-webp.conf RUN chmod -R 777 wp-content && chmod +x /kool/wordpress-entrypoint diff --git a/8.1-nginx/entrypoint b/8.1-nginx/entrypoint index 845d991..e1e4b3c 100644 --- a/8.1-nginx/entrypoint +++ b/8.1-nginx/entrypoint @@ -1,8 +1,9 @@ #!/bin/bash set -eo pipefail -# Nginx server config -dockerize -template /kool/default.tmpl:/etc/nginx/conf.d/default.conf +# Add WebP support for WordPress by injecting include directive +# Insert the include directive before the location / block +sed -i 's/\( location \/ {\)/ # Include WordPress WebP support\n include \/etc\/nginx\/wordpress-webp.conf;\n\n\1/' /kool/default.tmpl # Run as current user CURRENT_USER=${ASUSER:-${UID:-0}} diff --git a/8.1-nginx/wordpress-webp.conf b/8.1-nginx/wordpress-webp.conf new file mode 100644 index 0000000..f1d94fe --- /dev/null +++ b/8.1-nginx/wordpress-webp.conf @@ -0,0 +1,17 @@ +# WordPress WebP support: automatically serve WebP images when available and supported +location ~* ^(.+)\.(jpe?g|png)$ { + set $webp_suffix ""; + + # Check if WebP is supported by the client + if ($http_accept ~* "image/webp") { + set $webp_suffix ".webp"; + } + + # Try to serve the WebP version first, then fallback to original + try_files $uri$webp_suffix $uri /index.php?$query_string; + + # Set appropriate cache headers for images + expires 30d; + add_header Cache-Control "public, immutable"; + add_header Vary "Accept"; +} \ No newline at end of file diff --git a/8.2-nginx-prod/Dockerfile b/8.2-nginx-prod/Dockerfile index cdce9b2..c9991fa 100644 --- a/8.2-nginx-prod/Dockerfile +++ b/8.2-nginx-prod/Dockerfile @@ -1,5 +1,5 @@ -FROM wordpress:cli-php8.2 as wordpress-cli -FROM wordpress:php8.2-fpm-alpine as wordpress +FROM wordpress:cli-php8.2 AS wordpress-cli +FROM wordpress:php8.2-fpm-alpine AS wordpress FROM kooldev/php:8.2-nginx-prod ENV NGINX_ROOT=/app @@ -8,6 +8,7 @@ COPY --from=wordpress-cli /usr/local/bin/wp /usr/local/bin/wp COPY --from=wordpress --chown=kool:kool /usr/src/wordpress /kool/wordpress COPY --from=wordpress --chown=kool:kool /var/www/html/wp-content /app/wp-content COPY entrypoint /kool/wordpress-entrypoint +COPY wordpress-webp.conf /etc/nginx/wordpress-webp.conf RUN chmod -R 777 wp-content && chmod +x /kool/wordpress-entrypoint diff --git a/8.2-nginx-prod/entrypoint b/8.2-nginx-prod/entrypoint index 845d991..e1e4b3c 100644 --- a/8.2-nginx-prod/entrypoint +++ b/8.2-nginx-prod/entrypoint @@ -1,8 +1,9 @@ #!/bin/bash set -eo pipefail -# Nginx server config -dockerize -template /kool/default.tmpl:/etc/nginx/conf.d/default.conf +# Add WebP support for WordPress by injecting include directive +# Insert the include directive before the location / block +sed -i 's/\( location \/ {\)/ # Include WordPress WebP support\n include \/etc\/nginx\/wordpress-webp.conf;\n\n\1/' /kool/default.tmpl # Run as current user CURRENT_USER=${ASUSER:-${UID:-0}} diff --git a/8.2-nginx-prod/wordpress-webp.conf b/8.2-nginx-prod/wordpress-webp.conf new file mode 100644 index 0000000..f1d94fe --- /dev/null +++ b/8.2-nginx-prod/wordpress-webp.conf @@ -0,0 +1,17 @@ +# WordPress WebP support: automatically serve WebP images when available and supported +location ~* ^(.+)\.(jpe?g|png)$ { + set $webp_suffix ""; + + # Check if WebP is supported by the client + if ($http_accept ~* "image/webp") { + set $webp_suffix ".webp"; + } + + # Try to serve the WebP version first, then fallback to original + try_files $uri$webp_suffix $uri /index.php?$query_string; + + # Set appropriate cache headers for images + expires 30d; + add_header Cache-Control "public, immutable"; + add_header Vary "Accept"; +} \ No newline at end of file diff --git a/8.2-nginx/Dockerfile b/8.2-nginx/Dockerfile index f02705b..68fa8f5 100644 --- a/8.2-nginx/Dockerfile +++ b/8.2-nginx/Dockerfile @@ -1,5 +1,5 @@ -FROM wordpress:cli-php8.2 as wordpress-cli -FROM wordpress:php8.2-fpm-alpine as wordpress +FROM wordpress:cli-php8.2 AS wordpress-cli +FROM wordpress:php8.2-fpm-alpine AS wordpress FROM kooldev/php:8.2-nginx ENV NGINX_ROOT=/app @@ -8,6 +8,7 @@ COPY --from=wordpress-cli /usr/local/bin/wp /usr/local/bin/wp COPY --from=wordpress --chown=kool:kool /usr/src/wordpress /kool/wordpress COPY --from=wordpress --chown=kool:kool /var/www/html/wp-content /app/wp-content COPY entrypoint /kool/wordpress-entrypoint +COPY wordpress-webp.conf /etc/nginx/wordpress-webp.conf RUN chmod -R 777 wp-content && chmod +x /kool/wordpress-entrypoint diff --git a/8.2-nginx/entrypoint b/8.2-nginx/entrypoint index 845d991..e1e4b3c 100644 --- a/8.2-nginx/entrypoint +++ b/8.2-nginx/entrypoint @@ -1,8 +1,9 @@ #!/bin/bash set -eo pipefail -# Nginx server config -dockerize -template /kool/default.tmpl:/etc/nginx/conf.d/default.conf +# Add WebP support for WordPress by injecting include directive +# Insert the include directive before the location / block +sed -i 's/\( location \/ {\)/ # Include WordPress WebP support\n include \/etc\/nginx\/wordpress-webp.conf;\n\n\1/' /kool/default.tmpl # Run as current user CURRENT_USER=${ASUSER:-${UID:-0}} diff --git a/8.2-nginx/wordpress-webp.conf b/8.2-nginx/wordpress-webp.conf new file mode 100644 index 0000000..f1d94fe --- /dev/null +++ b/8.2-nginx/wordpress-webp.conf @@ -0,0 +1,17 @@ +# WordPress WebP support: automatically serve WebP images when available and supported +location ~* ^(.+)\.(jpe?g|png)$ { + set $webp_suffix ""; + + # Check if WebP is supported by the client + if ($http_accept ~* "image/webp") { + set $webp_suffix ".webp"; + } + + # Try to serve the WebP version first, then fallback to original + try_files $uri$webp_suffix $uri /index.php?$query_string; + + # Set appropriate cache headers for images + expires 30d; + add_header Cache-Control "public, immutable"; + add_header Vary "Accept"; +} \ No newline at end of file diff --git a/8.3-nginx-prod/Dockerfile b/8.3-nginx-prod/Dockerfile index 8abdb6a..f8342e3 100644 --- a/8.3-nginx-prod/Dockerfile +++ b/8.3-nginx-prod/Dockerfile @@ -1,5 +1,5 @@ -FROM wordpress:cli-php8.3 as wordpress-cli -FROM wordpress:php8.3-fpm-alpine as wordpress +FROM wordpress:cli-php8.3 AS wordpress-cli +FROM wordpress:php8.3-fpm-alpine AS wordpress FROM kooldev/php:8.3-nginx-prod ENV NGINX_ROOT=/app @@ -8,6 +8,7 @@ COPY --from=wordpress-cli /usr/local/bin/wp /usr/local/bin/wp COPY --from=wordpress --chown=kool:kool /usr/src/wordpress /kool/wordpress COPY --from=wordpress --chown=kool:kool /var/www/html/wp-content /app/wp-content COPY entrypoint /kool/wordpress-entrypoint +COPY wordpress-webp.conf /etc/nginx/wordpress-webp.conf RUN chmod -R 777 wp-content && chmod +x /kool/wordpress-entrypoint diff --git a/8.3-nginx-prod/entrypoint b/8.3-nginx-prod/entrypoint index 845d991..e1e4b3c 100644 --- a/8.3-nginx-prod/entrypoint +++ b/8.3-nginx-prod/entrypoint @@ -1,8 +1,9 @@ #!/bin/bash set -eo pipefail -# Nginx server config -dockerize -template /kool/default.tmpl:/etc/nginx/conf.d/default.conf +# Add WebP support for WordPress by injecting include directive +# Insert the include directive before the location / block +sed -i 's/\( location \/ {\)/ # Include WordPress WebP support\n include \/etc\/nginx\/wordpress-webp.conf;\n\n\1/' /kool/default.tmpl # Run as current user CURRENT_USER=${ASUSER:-${UID:-0}} diff --git a/8.3-nginx-prod/wordpress-webp.conf b/8.3-nginx-prod/wordpress-webp.conf new file mode 100644 index 0000000..f1d94fe --- /dev/null +++ b/8.3-nginx-prod/wordpress-webp.conf @@ -0,0 +1,17 @@ +# WordPress WebP support: automatically serve WebP images when available and supported +location ~* ^(.+)\.(jpe?g|png)$ { + set $webp_suffix ""; + + # Check if WebP is supported by the client + if ($http_accept ~* "image/webp") { + set $webp_suffix ".webp"; + } + + # Try to serve the WebP version first, then fallback to original + try_files $uri$webp_suffix $uri /index.php?$query_string; + + # Set appropriate cache headers for images + expires 30d; + add_header Cache-Control "public, immutable"; + add_header Vary "Accept"; +} \ No newline at end of file diff --git a/8.3-nginx/Dockerfile b/8.3-nginx/Dockerfile index f8e8f9b..c9a7c7b 100644 --- a/8.3-nginx/Dockerfile +++ b/8.3-nginx/Dockerfile @@ -1,5 +1,5 @@ -FROM wordpress:cli-php8.3 as wordpress-cli -FROM wordpress:php8.3-fpm-alpine as wordpress +FROM wordpress:cli-php8.3 AS wordpress-cli +FROM wordpress:php8.3-fpm-alpine AS wordpress FROM kooldev/php:8.3-nginx ENV NGINX_ROOT=/app @@ -8,6 +8,7 @@ COPY --from=wordpress-cli /usr/local/bin/wp /usr/local/bin/wp COPY --from=wordpress --chown=kool:kool /usr/src/wordpress /kool/wordpress COPY --from=wordpress --chown=kool:kool /var/www/html/wp-content /app/wp-content COPY entrypoint /kool/wordpress-entrypoint +COPY wordpress-webp.conf /etc/nginx/wordpress-webp.conf RUN chmod -R 777 wp-content && chmod +x /kool/wordpress-entrypoint diff --git a/8.3-nginx/entrypoint b/8.3-nginx/entrypoint index 845d991..e1e4b3c 100644 --- a/8.3-nginx/entrypoint +++ b/8.3-nginx/entrypoint @@ -1,8 +1,9 @@ #!/bin/bash set -eo pipefail -# Nginx server config -dockerize -template /kool/default.tmpl:/etc/nginx/conf.d/default.conf +# Add WebP support for WordPress by injecting include directive +# Insert the include directive before the location / block +sed -i 's/\( location \/ {\)/ # Include WordPress WebP support\n include \/etc\/nginx\/wordpress-webp.conf;\n\n\1/' /kool/default.tmpl # Run as current user CURRENT_USER=${ASUSER:-${UID:-0}} diff --git a/8.3-nginx/wordpress-webp.conf b/8.3-nginx/wordpress-webp.conf new file mode 100644 index 0000000..f1d94fe --- /dev/null +++ b/8.3-nginx/wordpress-webp.conf @@ -0,0 +1,17 @@ +# WordPress WebP support: automatically serve WebP images when available and supported +location ~* ^(.+)\.(jpe?g|png)$ { + set $webp_suffix ""; + + # Check if WebP is supported by the client + if ($http_accept ~* "image/webp") { + set $webp_suffix ".webp"; + } + + # Try to serve the WebP version first, then fallback to original + try_files $uri$webp_suffix $uri /index.php?$query_string; + + # Set appropriate cache headers for images + expires 30d; + add_header Cache-Control "public, immutable"; + add_header Vary "Accept"; +} \ No newline at end of file diff --git a/8.0-nginx-prod/Dockerfile b/8.4-nginx-prod/Dockerfile similarity index 71% rename from 8.0-nginx-prod/Dockerfile rename to 8.4-nginx-prod/Dockerfile index c5a2188..a984e3d 100644 --- a/8.0-nginx-prod/Dockerfile +++ b/8.4-nginx-prod/Dockerfile @@ -1,6 +1,6 @@ -FROM wordpress:cli-php8.0 as wordpress-cli -FROM wordpress:php8.0-fpm-alpine as wordpress -FROM kooldev/php:8.0-nginx-prod +FROM wordpress:cli-php8.4 AS wordpress-cli +FROM wordpress:php8.4-fpm-alpine AS wordpress +FROM kooldev/php:8.4-nginx-prod ENV NGINX_ROOT=/app @@ -8,6 +8,7 @@ COPY --from=wordpress-cli /usr/local/bin/wp /usr/local/bin/wp COPY --from=wordpress --chown=kool:kool /usr/src/wordpress /kool/wordpress COPY --from=wordpress --chown=kool:kool /var/www/html/wp-content /app/wp-content COPY entrypoint /kool/wordpress-entrypoint +COPY wordpress-webp.conf /etc/nginx/wordpress-webp.conf RUN chmod -R 777 wp-content && chmod +x /kool/wordpress-entrypoint diff --git a/8.0-nginx-prod/entrypoint b/8.4-nginx-prod/entrypoint similarity index 93% rename from 8.0-nginx-prod/entrypoint rename to 8.4-nginx-prod/entrypoint index 845d991..e1e4b3c 100644 --- a/8.0-nginx-prod/entrypoint +++ b/8.4-nginx-prod/entrypoint @@ -1,8 +1,9 @@ #!/bin/bash set -eo pipefail -# Nginx server config -dockerize -template /kool/default.tmpl:/etc/nginx/conf.d/default.conf +# Add WebP support for WordPress by injecting include directive +# Insert the include directive before the location / block +sed -i 's/\( location \/ {\)/ # Include WordPress WebP support\n include \/etc\/nginx\/wordpress-webp.conf;\n\n\1/' /kool/default.tmpl # Run as current user CURRENT_USER=${ASUSER:-${UID:-0}} diff --git a/8.4-nginx-prod/wordpress-webp.conf b/8.4-nginx-prod/wordpress-webp.conf new file mode 100644 index 0000000..f1d94fe --- /dev/null +++ b/8.4-nginx-prod/wordpress-webp.conf @@ -0,0 +1,17 @@ +# WordPress WebP support: automatically serve WebP images when available and supported +location ~* ^(.+)\.(jpe?g|png)$ { + set $webp_suffix ""; + + # Check if WebP is supported by the client + if ($http_accept ~* "image/webp") { + set $webp_suffix ".webp"; + } + + # Try to serve the WebP version first, then fallback to original + try_files $uri$webp_suffix $uri /index.php?$query_string; + + # Set appropriate cache headers for images + expires 30d; + add_header Cache-Control "public, immutable"; + add_header Vary "Accept"; +} \ No newline at end of file diff --git a/7.4-nginx-prod/Dockerfile b/8.4-nginx/Dockerfile similarity index 72% rename from 7.4-nginx-prod/Dockerfile rename to 8.4-nginx/Dockerfile index 0e56218..57b3732 100644 --- a/7.4-nginx-prod/Dockerfile +++ b/8.4-nginx/Dockerfile @@ -1,6 +1,6 @@ -FROM wordpress:cli-php7.4 as wordpress-cli -FROM wordpress:php7.4-fpm-alpine as wordpress -FROM kooldev/php:7.4-nginx-prod +FROM wordpress:cli-php8.4 AS wordpress-cli +FROM wordpress:php8.4-fpm-alpine AS wordpress +FROM kooldev/php:8.4-nginx ENV NGINX_ROOT=/app @@ -8,6 +8,7 @@ COPY --from=wordpress-cli /usr/local/bin/wp /usr/local/bin/wp COPY --from=wordpress --chown=kool:kool /usr/src/wordpress /kool/wordpress COPY --from=wordpress --chown=kool:kool /var/www/html/wp-content /app/wp-content COPY entrypoint /kool/wordpress-entrypoint +COPY wordpress-webp.conf /etc/nginx/wordpress-webp.conf RUN chmod -R 777 wp-content && chmod +x /kool/wordpress-entrypoint diff --git a/7.4-nginx-prod/entrypoint b/8.4-nginx/entrypoint similarity index 93% rename from 7.4-nginx-prod/entrypoint rename to 8.4-nginx/entrypoint index 845d991..e1e4b3c 100644 --- a/7.4-nginx-prod/entrypoint +++ b/8.4-nginx/entrypoint @@ -1,8 +1,9 @@ #!/bin/bash set -eo pipefail -# Nginx server config -dockerize -template /kool/default.tmpl:/etc/nginx/conf.d/default.conf +# Add WebP support for WordPress by injecting include directive +# Insert the include directive before the location / block +sed -i 's/\( location \/ {\)/ # Include WordPress WebP support\n include \/etc\/nginx\/wordpress-webp.conf;\n\n\1/' /kool/default.tmpl # Run as current user CURRENT_USER=${ASUSER:-${UID:-0}} diff --git a/8.4-nginx/wordpress-webp.conf b/8.4-nginx/wordpress-webp.conf new file mode 100644 index 0000000..f1d94fe --- /dev/null +++ b/8.4-nginx/wordpress-webp.conf @@ -0,0 +1,17 @@ +# WordPress WebP support: automatically serve WebP images when available and supported +location ~* ^(.+)\.(jpe?g|png)$ { + set $webp_suffix ""; + + # Check if WebP is supported by the client + if ($http_accept ~* "image/webp") { + set $webp_suffix ".webp"; + } + + # Try to serve the WebP version first, then fallback to original + try_files $uri$webp_suffix $uri /index.php?$query_string; + + # Set appropriate cache headers for images + expires 30d; + add_header Cache-Control "public, immutable"; + add_header Vary "Accept"; +} \ No newline at end of file diff --git a/README.md b/README.md index 35268d8..325deb2 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,11 @@ Minimal PHP Docker image for wordpress based on [kooldev/php](https://github.com ## Available Tags +### 8.4 + +- [8.4-nginx](https://github.com/kool-dev/docker-wordpress/blob/master/8.4-nginx/Dockerfile) +- [8.4-nginx-prod](https://github.com/kool-dev/docker-wordpress/blob/master/8.4-nginx-prod/Dockerfile) + ### 8.3 - [8.3-nginx](https://github.com/kool-dev/docker-wordpress/blob/master/8.3-nginx/Dockerfile) @@ -21,14 +26,9 @@ Minimal PHP Docker image for wordpress based on [kooldev/php](https://github.com - [8.1-nginx](https://github.com/kool-dev/docker-wordpress/blob/master/8.1-nginx/Dockerfile) - [8.1-nginx-prod](https://github.com/kool-dev/docker-wordpress/blob/master/8.1-nginx-prod/Dockerfile) -### 8.0 - -- [8.0-nginx](https://github.com/kool-dev/docker-wordpress/blob/master/8.0-nginx/Dockerfile) -- [8.0-nginx-prod](https://github.com/kool-dev/docker-wordpress/blob/master/8.0-nginx-prod/Dockerfile) - ### Legacy Images -Previously supported but now deprecated tags: [8.3](https://github.com/kool-dev/docker-wordpress/blob/master/8.3/Dockerfile), [8.3-prod](https://github.com/kool-dev/docker-wordpress/blob/master/8.3-prod/Dockerfile), [8.2](https://github.com/kool-dev/docker-wordpress/blob/master/8.2/Dockerfile), [8.2-prod](https://github.com/kool-dev/docker-wordpress/blob/master/8.2-prod/Dockerfile), [8.1](https://github.com/kool-dev/docker-wordpress/blob/master/8.1/Dockerfile), [8.1-prod](https://github.com/kool-dev/docker-wordpress/blob/master/8.1-prod/Dockerfile), [8.0](https://github.com/kool-dev/docker-wordpress/blob/master/8.0/Dockerfile), [8.0-prod](https://github.com/kool-dev/docker-wordpress/blob/master/8.0-prod/Dockerfile), [7.4](https://github.com/kool-dev/docker-wordpress/blob/master/7.4/Dockerfile), [7.4-prod](https://github.com/kool-dev/docker-wordpress/blob/master/7.4-prod/Dockerfile), [7.4-nginx](https://github.com/kool-dev/docker-wordpress/blob/master/7.4-nginx/Dockerfile), [7.4-nginx-prod](https://github.com/kool-dev/docker-wordpress/blob/master/7.4-nginx-prod/Dockerfile). +Previously supported but now deprecated tags: [8.3](https://github.com/kool-dev/docker-wordpress/blob/master/8.3/Dockerfile), [8.3-prod](https://github.com/kool-dev/docker-wordpress/blob/master/8.3-prod/Dockerfile), [8.2](https://github.com/kool-dev/docker-wordpress/blob/master/8.2/Dockerfile), [8.2-prod](https://github.com/kool-dev/docker-wordpress/blob/master/8.2-prod/Dockerfile), [8.1](https://github.com/kool-dev/docker-wordpress/blob/master/8.1/Dockerfile), [8.1-prod](https://github.com/kool-dev/docker-wordpress/blob/master/8.1-prod/Dockerfile), [8.0](https://github.com/kool-dev/docker-wordpress/blob/master/8.0/Dockerfile), [8.0-prod](https://github.com/kool-dev/docker-wordpress/blob/master/8.0-prod/Dockerfile), [7.4](https://github.com/kool-dev/docker-wordpress/blob/master/7.4/Dockerfile), [7.4-prod](https://github.com/kool-dev/docker-wordpress/blob/master/7.4-prod/Dockerfile), [7.4-nginx](https://github.com/kool-dev/docker-wordpress/blob/master/7.4-nginx/Dockerfile), [7.4-nginx-prod](https://github.com/kool-dev/docker-wordpress/blob/master/7.4-nginx-prod/Dockerfile), [8.0-nginx](https://github.com/kool-dev/docker-wordpress/blob/master/8.0-nginx/Dockerfile), [8.0-nginx-prod](https://github.com/kool-dev/docker-wordpress/blob/master/8.0-nginx-prod/Dockerfile). ## How to diff --git a/fwd-template.json b/fwd-template.json index 4298129..7807a10 100644 --- a/fwd-template.json +++ b/fwd-template.json @@ -2,11 +2,11 @@ "output": ".", "builds": [ { - "name": "7.4-nginx", + "name": "8.1-nginx", "data": { - "from": "kooldev/php:7.4-nginx", + "from": "kooldev/php:8.1-nginx", "prod": false, - "version": "7.4" + "version": "8.1" }, "files": [ { @@ -16,33 +16,19 @@ { "name": "entrypoint", "path": "template/entrypoint" - } - ] - }, - { - "name": "7.4-nginx-prod", - "data": { - "from": "kooldev/php:7.4-nginx-prod", - "prod": true, - "version": "7.4" - }, - "files": [ - { - "name": "Dockerfile", - "path": "template/Dockerfile" }, { - "name": "entrypoint", - "path": "template/entrypoint" + "name": "wordpress-webp.conf", + "path": "template/wordpress-webp-conf" } ] }, { - "name": "8.0-nginx", + "name": "8.1-nginx-prod", "data": { - "from": "kooldev/php:8.0-nginx", - "prod": false, - "version": "8.0" + "from": "kooldev/php:8.1-nginx-prod", + "prod": true, + "version": "8.1" }, "files": [ { @@ -52,33 +38,19 @@ { "name": "entrypoint", "path": "template/entrypoint" - } - ] - }, - { - "name": "8.0-nginx-prod", - "data": { - "from": "kooldev/php:8.0-nginx-prod", - "prod": true, - "version": "8.0" - }, - "files": [ - { - "name": "Dockerfile", - "path": "template/Dockerfile" }, { - "name": "entrypoint", - "path": "template/entrypoint" + "name": "wordpress-webp.conf", + "path": "template/wordpress-webp-conf" } ] }, { - "name": "8.1-nginx", + "name": "8.2-nginx", "data": { - "from": "kooldev/php:8.1-nginx", + "from": "kooldev/php:8.2-nginx", "prod": false, - "version": "8.1" + "version": "8.2" }, "files": [ { @@ -88,15 +60,19 @@ { "name": "entrypoint", "path": "template/entrypoint" + }, + { + "name": "wordpress-webp.conf", + "path": "template/wordpress-webp-conf" } ] }, { - "name": "8.1-nginx-prod", + "name": "8.2-nginx-prod", "data": { - "from": "kooldev/php:8.1-nginx-prod", + "from": "kooldev/php:8.2-nginx-prod", "prod": true, - "version": "8.1" + "version": "8.2" }, "files": [ { @@ -106,15 +82,19 @@ { "name": "entrypoint", "path": "template/entrypoint" + }, + { + "name": "wordpress-webp.conf", + "path": "template/wordpress-webp-conf" } ] }, { - "name": "8.2-nginx", + "name": "8.3-nginx", "data": { - "from": "kooldev/php:8.2-nginx", + "from": "kooldev/php:8.3-nginx", "prod": false, - "version": "8.2" + "version": "8.3" }, "files": [ { @@ -124,15 +104,19 @@ { "name": "entrypoint", "path": "template/entrypoint" + }, + { + "name": "wordpress-webp.conf", + "path": "template/wordpress-webp-conf" } ] }, { - "name": "8.2-nginx-prod", + "name": "8.3-nginx-prod", "data": { - "from": "kooldev/php:8.2-nginx-prod", + "from": "kooldev/php:8.3-nginx-prod", "prod": true, - "version": "8.2" + "version": "8.3" }, "files": [ { @@ -142,15 +126,19 @@ { "name": "entrypoint", "path": "template/entrypoint" + }, + { + "name": "wordpress-webp.conf", + "path": "template/wordpress-webp-conf" } ] }, { - "name": "8.3-nginx", + "name": "8.4-nginx", "data": { - "from": "kooldev/php:8.3-nginx", + "from": "kooldev/php:8.4-nginx", "prod": false, - "version": "8.3" + "version": "8.4" }, "files": [ { @@ -160,15 +148,19 @@ { "name": "entrypoint", "path": "template/entrypoint" + }, + { + "name": "wordpress-webp.conf", + "path": "template/wordpress-webp-conf" } ] }, { - "name": "8.3-nginx-prod", + "name": "8.4-nginx-prod", "data": { - "from": "kooldev/php:8.3-nginx-prod", + "from": "kooldev/php:8.4-nginx-prod", "prod": true, - "version": "8.3" + "version": "8.4" }, "files": [ { @@ -178,6 +170,10 @@ { "name": "entrypoint", "path": "template/entrypoint" + }, + { + "name": "wordpress-webp.conf", + "path": "template/wordpress-webp-conf" } ] } diff --git a/kool.yml b/kool.yml index 2167f61..7ea94f2 100644 --- a/kool.yml +++ b/kool.yml @@ -18,3 +18,6 @@ scripts: # PHP 8.3 - docker build -t kooldev/wordpress:8.3-nginx 8.3-nginx - docker build -t kooldev/wordpress:8.3-nginx-prod 8.3-nginx-prod + # PHP 8.4 + - docker build -t kooldev/wordpress:8.4-nginx 8.4-nginx + - docker build -t kooldev/wordpress:8.4-nginx-prod 8.4-nginx-prod diff --git a/template/Dockerfile.blade.php b/template/Dockerfile.blade.php index 9dea081..5b1d375 100644 --- a/template/Dockerfile.blade.php +++ b/template/Dockerfile.blade.php @@ -1,5 +1,5 @@ -FROM wordpress:cli-php{{ $version }} as wordpress-cli -FROM wordpress:php{{ $version }}-fpm-alpine as wordpress +FROM wordpress:cli-php{{ $version }} AS wordpress-cli +FROM wordpress:php{{ $version }}-fpm-alpine AS wordpress FROM {{ $from }} ENV NGINX_ROOT=/app @@ -8,6 +8,7 @@ COPY --from=wordpress --chown=kool:kool /usr/src/wordpress /kool/wordpress COPY --from=wordpress --chown=kool:kool /var/www/html/wp-content /app/wp-content COPY entrypoint /kool/wordpress-entrypoint +COPY wordpress-webp.conf /etc/nginx/wordpress-webp.conf RUN chmod -R 777 wp-content && chmod +x /kool/wordpress-entrypoint diff --git a/template/entrypoint.blade.php b/template/entrypoint.blade.php index 845d991..e1e4b3c 100644 --- a/template/entrypoint.blade.php +++ b/template/entrypoint.blade.php @@ -1,8 +1,9 @@ #!/bin/bash set -eo pipefail -# Nginx server config -dockerize -template /kool/default.tmpl:/etc/nginx/conf.d/default.conf +# Add WebP support for WordPress by injecting include directive +# Insert the include directive before the location / block +sed -i 's/\( location \/ {\)/ # Include WordPress WebP support\n include \/etc\/nginx\/wordpress-webp.conf;\n\n\1/' /kool/default.tmpl # Run as current user CURRENT_USER=${ASUSER:-${UID:-0}} diff --git a/template/wordpress-webp-conf.blade.php b/template/wordpress-webp-conf.blade.php new file mode 100644 index 0000000..f1d94fe --- /dev/null +++ b/template/wordpress-webp-conf.blade.php @@ -0,0 +1,17 @@ +# WordPress WebP support: automatically serve WebP images when available and supported +location ~* ^(.+)\.(jpe?g|png)$ { + set $webp_suffix ""; + + # Check if WebP is supported by the client + if ($http_accept ~* "image/webp") { + set $webp_suffix ".webp"; + } + + # Try to serve the WebP version first, then fallback to original + try_files $uri$webp_suffix $uri /index.php?$query_string; + + # Set appropriate cache headers for images + expires 30d; + add_header Cache-Control "public, immutable"; + add_header Vary "Accept"; +} \ No newline at end of file