Skip to content
Merged
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/actions/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ inputs:
user_id:
description: user id
required: true
web:
description: web server variant, such as apache
required: false
runs:
using: "composite"
steps:
- name: Build image
env:
PHP_VER: ${{ inputs.version }}
PHP_DEV: ${{ inputs.dev }}
PHP_WEB: ${{ inputs.web }}
WODBY_USER_ID: ${{ inputs.user_id }}
LATEST: ${{ inputs.latest }}
LATEST_MAJOR: ${{ inputs.latest_major }}
Expand Down
8 changes: 7 additions & 1 deletion .github/actions/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ if [[ "${GITHUB_REF}" == refs/heads/master || "${GITHUB_REF}" == refs/tags/* ]];
fi
fi

# Web server variants, such as apache, carry their name in every tag.
if [[ -n "${PHP_WEB}" ]]; then
minor_tag="${minor_tag}-${PHP_WEB}"
major_tag="${major_tag}-${PHP_WEB}"
fi

tags=("${minor_tag}")
if [[ -n "${LATEST_MAJOR}" ]]; then
tags+=("${major_tag}")
Expand All @@ -38,7 +44,7 @@ if [[ "${GITHUB_REF}" == refs/heads/master || "${GITHUB_REF}" == refs/tags/* ]];
tags+=("${major_tag}-${image_revision}")
fi
else
if [[ -n "${LATEST}" ]]; then
if [[ -n "${LATEST}" && -z "${PHP_WEB}" ]]; then
if [[ -z "${PHP_DEV}" ]]; then
tags+=("latest")
else
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ jobs:
user_id:
- 1000
- 501
web:
- ''
- 'apache'
include:
- arch: amd64
runner: ubuntu-24.04
Expand All @@ -74,6 +77,9 @@ jobs:
exclude:
- dev: ''
user_id: 501
# The Apache variant has no development images.
- dev: 'dev'
web: 'apache'
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v7
Expand All @@ -84,6 +90,7 @@ jobs:
PHP_VER: ${{ matrix.php.version }}
ARCH: ${{ matrix.arch }}
PHP_DEV: ${{ matrix.dev }}
PHP_WEB: ${{ matrix.web }}
WODBY_USER_ID: ${{ matrix.user_id }}
WODBY_GROUP_ID: ${{ matrix.group_id }}
working-directory: ${{ matrix.php.workdir }}
Expand All @@ -106,6 +113,7 @@ jobs:
PHP_VER: ${{ matrix.php.version }}
ARCH: ${{ matrix.arch }}
PHP_DEV: ${{ matrix.dev }}
PHP_WEB: ${{ matrix.web }}
WODBY_USER_ID: ${{ matrix.user_id }}
WODBY_GROUP_ID: ${{ matrix.group_id }}
working-directory: ${{ matrix.php.workdir }}
Expand All @@ -126,9 +134,14 @@ jobs:
user_id:
- 1000
- 501
web:
- ''
- 'apache'
exclude:
- dev: ''
user_id: 501
- dev: 'dev'
web: 'apache'
steps:
- uses: actions/checkout@v7
- uses: docker/login-action@v4
Expand All @@ -141,6 +154,7 @@ jobs:
workdir: ${{ matrix.php.workdir }}
dev: ${{ matrix.dev }}
user_id: ${{ matrix.user_id }}
web: ${{ matrix.web }}
latest: ${{ matrix.php.latest }}
latest_major: ${{ matrix.php.latest_major }}

Expand Down
25 changes: 25 additions & 0 deletions .image-revision-aliases.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
"{major}-dev-macos"
],
"full": "{version}-dev-macos"
},
{
"short": [
"{minor}-apache",
"{major}-apache"
],
"full": "{version}-apache"
}
]
},
Expand All @@ -52,6 +59,12 @@
"{minor}-dev-macos"
],
"full": "{version}-dev-macos"
},
{
"short": [
"{minor}-apache"
],
"full": "{version}-apache"
}
]
},
Expand All @@ -77,6 +90,12 @@
"{minor}-dev-macos"
],
"full": "{version}-dev-macos"
},
{
"short": [
"{minor}-apache"
],
"full": "{version}-apache"
}
]
},
Expand All @@ -102,6 +121,12 @@
"{minor}-dev-macos"
],
"full": "{version}-dev-macos"
},
{
"short": [
"{minor}-apache"
],
"full": "{version}-apache"
}
]
}
Expand Down
33 changes: 31 additions & 2 deletions 8/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# check=skip=InvalidDefaultArgInFrom

# The Makefile supplies the required digest-pinned BASE_IMAGE argument.
# The Makefile supplies the required digest-pinned BASE_IMAGE argument and
# selects the stage: php (the default) or apache.
ARG PHP_VER
ARG BASE_IMAGE
FROM ${BASE_IMAGE}
FROM ${BASE_IMAGE} AS php

LABEL com.wodby.ci.cache="composer"

Expand Down Expand Up @@ -445,3 +446,31 @@ COPY init /docker-entrypoint-init.d/

ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["sudo", "-E", "php-fpm"]

# PHP-FPM with Apache in front of it in the same container. Apache serves the
# application's static files and passes PHP scripts to the local PHP-FPM, so
# one image runs an application without a separate web server service.
FROM php AS apache

USER root

RUN set -xe; \
apk add --update --no-cache apache2 apache2-proxy; \
# The image's own configuration replaces Alpine's defaults. \
rm -f /etc/apache2/conf.d/*.conf; \
touch /etc/apache2/vhost.conf; \
chown wodby:wodby /etc/apache2/httpd.conf /etc/apache2/vhost.conf; \
install -d -o root -g root /run/apache2; \
echo 'wodby ALL=(root) NOPASSWD:SETENV: /usr/sbin/httpd' > /etc/sudoers.d/wodby-apache

USER wodby

EXPOSE 80

COPY apache/templates /etc/gotpl/apache/
COPY apache/bin /usr/local/bin/

CMD ["php-fpm-apache"]

# Builds without a target get the PHP-FPM image.
FROM php
26 changes: 25 additions & 1 deletion 8/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,24 @@ ifeq ($(WODBY_GROUP_ID),)
WODBY_GROUP_ID := 1000
endif

# PHP_WEB=apache builds the variant with Apache in front of PHP-FPM.
ifneq ($(PHP_WEB),)
ifneq ($(PHP_WEB),apache)
$(error Unsupported PHP_WEB: $(PHP_WEB))
endif
ifneq ($(PHP_DEV),)
$(error PHP_WEB has no development variant)
endif
TARGET := $(PHP_WEB)
else
TARGET := php
endif

ifeq ($(TAG),)
ifneq ($(PHP_DEV),)
ifneq ($(PHP_WEB),)
TAG := $(PHP_VER_MINOR)-$(PHP_WEB)
NAME := $(NAME)-$(PHP_WEB)
else ifneq ($(PHP_DEV),)
ifeq ($(WODBY_USER_ID),501)
TAG := $(PHP_VER_MINOR)-dev-macos
NAME := $(NAME)-dev-macos
Expand Down Expand Up @@ -59,6 +75,7 @@ build:
--build-arg PHP_DEV=$(PHP_DEV) \
--build-arg WODBY_USER_ID=$(WODBY_USER_ID) \
--build-arg WODBY_GROUP_ID=$(WODBY_GROUP_ID) \
--target $(TARGET) \
$(PROXY_BUILD_ARGS) $(PIE_BUILD_SECRET) \
./

Expand All @@ -68,6 +85,7 @@ build-debug:
--build-arg PHP_DEV=$(PHP_DEV) \
--build-arg WODBY_USER_ID=$(WODBY_USER_ID) \
--build-arg WODBY_GROUP_ID=$(WODBY_GROUP_ID) \
--target $(TARGET) \
$(PROXY_BUILD_ARGS) $(PIE_BUILD_SECRET) \
--no-cache --progress=plain ./ 2>&1 | tee build.log

Expand All @@ -77,6 +95,7 @@ buildx-build:
--build-arg PHP_DEV=$(PHP_DEV) \
--build-arg WODBY_USER_ID=$(WODBY_USER_ID) \
--build-arg WODBY_GROUP_ID=$(WODBY_GROUP_ID) \
--target $(TARGET) \
$(PROXY_BUILD_ARGS) $(PIE_BUILD_SECRET) \
--load \
./
Expand All @@ -87,6 +106,7 @@ buildx-push:
--build-arg PHP_DEV=$(PHP_DEV) \
--build-arg WODBY_USER_ID=$(WODBY_USER_ID) \
--build-arg WODBY_GROUP_ID=$(WODBY_GROUP_ID) \
--target $(TARGET) \
$(PROXY_BUILD_ARGS) $(PIE_BUILD_SECRET) \
./

Expand All @@ -97,7 +117,11 @@ buildx-imagetools-create:
.PHONY: buildx-imagetools-create

test:
ifneq ($(PHP_WEB),)
cd ./tests && IMAGE=$(REPO):$(TAG) ./$(PHP_WEB).sh
else
cd ./tests && IMAGE=$(REPO):$(TAG) ./run.sh
endif

push:
docker push $(REPO):$(TAG)
Expand Down
37 changes: 37 additions & 0 deletions 8/apache/bin/php-fpm-apache
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

# Runs PHP-FPM and Apache side by side in the foreground. The container stops
# when either of them exits, so the orchestrator restarts it. A stop signal
# shuts both down gracefully: Apache finishes the requests it is serving and
# PHP-FPM the scripts it is running.

set -o pipefail

if [[ -n "${DEBUG}" ]]; then
set -x
fi

sudo -E php-fpm &
fpm=$!

sudo -E httpd -DFOREGROUND &
httpd=$!

stop() {
trap - TERM INT QUIT
sudo -E httpd -k graceful-stop
kill -QUIT "${fpm}" 2>/dev/null
wait
exit 0
}

trap stop TERM INT QUIT

wait -n
status=$?

trap - TERM INT QUIT
echo "PHP-FPM or Apache exited with status ${status}; stopping the container." >&2
kill -TERM "${fpm}" "${httpd}" 2>/dev/null
wait
exit "${status}"
88 changes: 88 additions & 0 deletions 8/apache/templates/httpd.conf.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
ServerRoot "/etc/apache2"
PidFile /run/apache2/httpd.pid

Listen {{ getenv "APACHE_PORT" "80" }}

# PHP runs in PHP-FPM, so Apache uses the threaded event MPM.
LoadModule mpm_event_module /usr/lib/apache2/mod_mpm_event.so

LoadModule access_compat_module /usr/lib/apache2/mod_access_compat.so
LoadModule alias_module /usr/lib/apache2/mod_alias.so
LoadModule auth_basic_module /usr/lib/apache2/mod_auth_basic.so
LoadModule authn_core_module /usr/lib/apache2/mod_authn_core.so
LoadModule authn_file_module /usr/lib/apache2/mod_authn_file.so
LoadModule authz_core_module /usr/lib/apache2/mod_authz_core.so
LoadModule authz_groupfile_module /usr/lib/apache2/mod_authz_groupfile.so
LoadModule authz_host_module /usr/lib/apache2/mod_authz_host.so
LoadModule authz_user_module /usr/lib/apache2/mod_authz_user.so
LoadModule deflate_module /usr/lib/apache2/mod_deflate.so
LoadModule dir_module /usr/lib/apache2/mod_dir.so
LoadModule env_module /usr/lib/apache2/mod_env.so
LoadModule expires_module /usr/lib/apache2/mod_expires.so
LoadModule filter_module /usr/lib/apache2/mod_filter.so
LoadModule headers_module /usr/lib/apache2/mod_headers.so
LoadModule log_config_module /usr/lib/apache2/mod_log_config.so
LoadModule mime_module /usr/lib/apache2/mod_mime.so
LoadModule negotiation_module /usr/lib/apache2/mod_negotiation.so
LoadModule proxy_module /usr/lib/apache2/mod_proxy.so
LoadModule proxy_fcgi_module /usr/lib/apache2/mod_proxy_fcgi.so
LoadModule remoteip_module /usr/lib/apache2/mod_remoteip.so
LoadModule reqtimeout_module /usr/lib/apache2/mod_reqtimeout.so
LoadModule rewrite_module /usr/lib/apache2/mod_rewrite.so
LoadModule setenvif_module /usr/lib/apache2/mod_setenvif.so
LoadModule unixd_module /usr/lib/apache2/mod_unixd.so
LoadModule version_module /usr/lib/apache2/mod_version.so

# Apache only reads files; PHP-FPM writes them as its own user.
User {{ getenv "APACHE_USER" "www-data" }}
Group {{ getenv "APACHE_GROUP" "www-data" }}

ServerName localhost

<Directory />
AllowOverride None
Require all denied
</Directory>

<Directory ~ "/\.(?!well-known/)">
Require all denied
</Directory>

ErrorLog /proc/self/fd/2
LogLevel {{ getenv "APACHE_LOG_LEVEL" "warn" }}

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog /proc/self/fd/1 {{ getenv "APACHE_LOG_FORMAT" "common" }} env=!dontlog

RequestHeader unset Proxy early

TypesConfig /etc/apache2/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz

Timeout {{ getenv "APACHE_TIMEOUT" "60" }}
KeepAlive {{ getenv "APACHE_KEEP_ALIVE" "On" }}
MaxKeepAliveRequests {{ getenv "APACHE_MAX_KEEP_ALIVE_REQUESTS" "100" }}
KeepAliveTimeout {{ getenv "APACHE_KEEP_ALIVE_TIMEOUT" "5" }}
UseCanonicalName {{ getenv "APACHE_USE_CANONICAL_NAME" "Off" }}
AccessFileName .htaccess
ServerTokens {{ getenv "APACHE_SERVER_TOKENS" "Prod" }}
ServerSignature {{ getenv "APACHE_SERVER_SIGNATURE" "Off" }}
HostnameLookups Off
# A stop lets running requests finish for at most this many seconds.
GracefulShutdownTimeout {{ getenv "APACHE_GRACEFUL_SHUTDOWN_TIMEOUT" "20" }}

RequestReadTimeout {{ getenv "APACHE_REQUEST_READ_TIMEOUT" "header=20-40,MinRate=500 body=20,MinRate=500" }}

<IfModule mpm_event_module>
ServerLimit {{ getenv "APACHE_MPM_EVENT_SERVER_LIMIT" "16" }}
MaxRequestWorkers {{ getenv "APACHE_MPM_EVENT_MAX_REQUEST_WORKERS" "400" }}
StartServers {{ getenv "APACHE_MPM_EVENT_START_SERVERS" "3" }}
ThreadsPerChild {{ getenv "APACHE_MPM_EVENT_THREADS_PER_CHILD" "25" }}
ThreadLimit {{ getenv "APACHE_MPM_EVENT_THREAD_LIMIT" "64" }}
</IfModule>

Include /etc/apache2/vhost.conf
# Extra configuration files, for example mounted by a deployment.
IncludeOptional /etc/apache2/conf.d/*.conf
Loading
Loading