Initial commit

This commit is contained in:
Vladimir Hodakov 2025-01-06 23:08:30 +04:00
commit 8099df95b5
Signed by: Vladimir Hodakov
GPG Key ID: 673980B6882F82C6
18 changed files with 574 additions and 0 deletions

3
.dockerignore Normal file
View File

@ -0,0 +1,3 @@
.secrets
.act
examples

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
pkg
.secrets
.idea
.vscode

95
Dockerfile Normal file
View File

@ -0,0 +1,95 @@
# Install Caddy
FROM docker.io/caddy:builder-alpine AS caddy-builder
RUN xcaddy build
# Install PHP
FROM docker.io/alpine
LABEL maintainer="vladimir@hodakov.me"
# Setup document root
WORKDIR /var/www/html
# Get caddy
COPY --from=caddy-builder /usr/bin/caddy /usr/bin/caddy
# Install packages and remove default server definition
RUN apk add --no-cache curl \
imagemagick \
php84 \
php84-fpm \
php84-apache2 \
php84-ctype \
php84-curl \
php84-dom \
php84-ftp \
php84-gd \
php84-iconv \
php84-json \
php84-mbstring \
php84-mysqli \
php84-opcache \
php84-openssl \
php84-pgsql \
php84-sqlite3 \
php84-tokenizer \
php84-xml \
php84-zlib \
php84-zip \
supervisor
# Configure Caddy
COPY config/Caddyfile /etc/caddy/Caddyfile
# Configure PHP-FPM
COPY config/fpm-pool.conf /etc/php84/php-fpm.d/www.conf
COPY config/php.ini /etc/php84/conf.d/custom.ini
# Configure supervisord
COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN mkdir /.config /phpbb
# Add tests app installation
COPY src/ /var/www/html/
# Add phpBB installation
ENV PHPBB_VERSION=3.3.14
ENV PHPBB_SHA256=68cd6cf3faefa175ea3892ba02c6b112e8967ed33703521c79820e35bd15ec9a
WORKDIR /tmp
RUN curl -SL https://download.phpbb.com/pub/release/3.3/${PHPBB_VERSION}/phpBB-${PHPBB_VERSION}.tar.bz2 -o phpbb.tar.bz2 \
&& echo "${PHPBB_SHA256} phpbb.tar.bz2" | sha256sum -c - \
&& tar -xjf phpbb.tar.bz2 \
&& mkdir /phpbb/sqlite \
&& mv phpBB3 /phpbb/www \
&& rm -f phpbb.tar.bz2
COPY phpbb/config.php /phpbb/www
# Expose the ports Caddy is reachable on
EXPOSE 8080
EXPOSE 8181
WORKDIR /phpbb/www
ENV PHPBB_INSTALL= \
PHPBB_DB_DRIVER=sqlite3 \
PHPBB_DB_HOST=/phpbb/sqlite/sqlite.db \
PHPBB_DB_PORT= \
PHPBB_DB_NAME= \
PHPBB_DB_USER= \
PHPBB_DB_PASSWD= \
PHPBB_DB_TABLE_PREFIX=phpbb_ \
PHPBB_DB_AUTOMIGRATE= \
PHPBB_DISPLAY_LOAD_TIME= \
PHPBB_DEBUG= \
PHPBB_DEBUG_CONTAINER=
COPY start.sh /usr/local/bin/
CMD ["start.sh"]
# Configure a healthcheck to validate that everything is up and running
HEALTHCHECK --timeout=10s CMD curl --silent --fail http://127.0.0.1:8080/fpm-ping

22
LICENSE Normal file
View File

@ -0,0 +1,22 @@
MIT License
Copyright (c) 2016 Seleznyov Dmitry
Copyright (c) 2023-2025 Vladimir Hodakov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

210
README.MD Normal file
View File

@ -0,0 +1,210 @@
# phpBB3 docker image
This is updated fork of [selim13's docker-phpbb image](https://github.com/selim13/docker-phpbb).
Now it even bundles caddy instead of apache2. Thanks
[ParaParty/docker-php-caddy](https://github.com/ParaParty/docker-php-caddy) for the inspiration.
Lightweight, Alpine based [phpBB](https://www.phpbb.com/) docker image.
# Supported tags and respective `Dockerfile` links
- [`3.3`, `3.3.11`, `latest`](https://github.com/fat0troll/docker-phpbb/blob/master/Dockerfile) bundled with PHP 8
# How to use this image
## Initial installation
If you don't have a prepared phpBB database, you can use a standard phpBB
installer script, just run a temporary container with `PHPBB_INSTALL=true`
environment variable:
```console
$ docker run -p 8000:8181 --name phpbb-install -e PHPBB_INSTALL=true -d fat0troll/phpbb:3.3
```
Point your browser to the http://localhost:8000 to begin the
installation process.
This image is bundled with SQLite3, MySQL and PostgresSQL database engines
support. Others can be added by creating custom Dockerfile. For MySQL and PostgresSQL
you can use standard container linking or use SQLite if you want a self
sufficient container.
For SQLite3 set `Database server hostname or DSN` field to `/phpbb/sqlite/sqlite.db`.
This file will be created on a docker volume and outside of the webserver's document root
for security. Leave user name, password and database name fields blank.
After the installation process is complete you can safely stop this container:
```console
$ docker stop phpbb-install
```
## Starting
You can start a container as follows:
```console
$ docker run --name phpbb -d fat0troll/phpbb:3.3
```
By default, it uses SQLite3 as a database backend, so you will need to supply
it with a database file. It's default path is `/phpbb/sqlite/sqlite.db`.
You can import it from the temporary installation container above:
```console
$ docker run --volumes-from phpbb-install --name phpbb -d fat0troll/phpbb:3.3
```
Or just copy it inside container if you have one from previous phpBB
installations:
```console
$ docker cp /path/at/host/sqlite.db phpbb:/www/sqlite/sqlite.db
```
For other database engines you will need to pass credentials and driver type
using environment variables:
```console
$ docker run --name phpbb \
-e PHPBB_DB_DRIVER=mysqli \
-e PHPBB_DB_HOST=dbmysql \
-e PHPBB_DB_PORT=3306 \
-e PHPBB_DB_NAME=phpbb \
-e PHPBB_DB_USER=phpbb \
-e PHPBB_DB_PASSWD=pass -d selim13/phpbb:3.3
```
## Environment variables
This image utilises environment variables for basic configuration. Most of
them are passed directly to phpBB's `config.php` or to the startup script.
### PHPBB_INSTALL
If set to `true`, container will start with an empty `config.php` file and
phpBB `/install/` directory intact. This will allow you to initilalize
a forum database upon fresh installation.
### PHPBB_DB_DRIVER
Selects a database driver. phpBB3 ships with following drivers:
- `mssql` - MS SQL Server
- `mysql` - MySQL via outdated php extension
- `mysqli` - MySQL via newer php extension
- `oracle` - Oracle
- `postgres` - PostgreSQL
- `sqlite` - SQLite 2
- `sqlite3` - SQLite 3
This image is bundled with support of `sqlite3`, `mysqli` and `postgres` drivers.
Default value: sqlite3
### PHPBB_DB_HOST
Database hostname or ip address.
For the SQLite3 driver sets database file path.
Default value: /phpbb/sqlite/sqlite.db
### PHPBB_DB_PORT
Database port.
### PHPBB_DB_NAME
Supplies database name for phpBB3.
### PHPBB_DB_USER
Supplies a user name for phpBB3 database.
### PHPBB_DB_PASSWD
Supplies a user password for phpBB3 database.
If you feel paranoid about providing your database password in an environment
variable, you can always ship it with a custom `config.php` file using volumes
or by extending this image.
### PHPBB_DB_TABLE_PREFIX
Table prefix for phpBB3 database.
Default value: phpbb\_
### PHPBB_DB_AUTOMIGRATE
If set to `true`, instructs a container to run database migrations by
executing `bin/phpbbcli.php db:migrate` on every startup.
If migrations fail, container will refuse to start.
### PHPBB_DB_WAIT
If set to `true`, container will wait for database service to become available.
You will need to explicitly set `PHPBB_DB_HOST` and `PHPBB_DB_PORT` for this
to work.
Use in conjunction with `PHPBB_DB_AUTOMIGRATE` to prevent running migrations
before database is ready.
Won't work for SQLite database engine as it is always available.
### PHPBB_DISPLAY_LOAD_TIME
If set to `true`, phpBB will display page loading time, queries count and peak memory
usage at the bottom of the page.
### PHPBB_DEBUG
If set to `true`, enables phpBB debug mode.
### PHPBB_DEBUG_CONTAINER
## Volumes
By default there are four volumes created for each container:
- /phpbb/sqlite
- /phpbb/www/files
- /phpbb/www/store
- /phpbb/www/images/avatars/upload
# Additional configuration
This image is based on a stock official Alpine image with apache2 and php5
packages from the Alpine Linux repository, so you can drop their custom
configuration files to `/etc/apache2/conf.d` and `/etc/php5/conf.d`.
## Pass user's IP from proxy
If you are planning to start a container behind proxy
(like [nginx-proxy](https://github.com/jwilder/nginx-proxy)), it will probably
be a good idea to get user's real IP instead of proxy one. For this, you can use
Apache RemoteIP module. Create a configuration file:
```apache
LoadModule remoteip_module modules/mod_remoteip.so
RemoteIPHeader X-Real-IP
RemoteIPInternalProxy nginx-proxy
```
Here `X-Real-IP` is a header name, where proxy passed user's real IP and
`nginx-proxy` is proxy host name.
Then push it to `/etc/apache2/conf.d/` directory, for example, by extending this
image:
```dockerfile
FROM selim13/phpbb:3.3
COPY remoteip.conf /etc/apache2/conf.d
```

23
config/Caddyfile Normal file
View File

@ -0,0 +1,23 @@
:8080 {
root * /var/www/html/public
php_fastcgi unix//run/php-fpm.sock {
trusted_proxies private_ranges
}
file_server
log stdout
}
:8181 {
root * /phpbb/www
php_fastcgi unix//run/php-fpm.sock {
trusted_proxies private_ranges
}
file_server
log stdout
}

56
config/fpm-pool.conf Normal file
View File

@ -0,0 +1,56 @@
[global]
; Log to stderr
error_log = /dev/stderr
[www]
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
; a specific port;
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /run/php-fpm.sock
; Enable status page
pm.status_path = /fpm-status
; Ondemand process manager
pm = ondemand
; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
pm.max_children = 100
; The number of seconds after which an idle process will be killed.
; Note: Used only when pm is set to 'ondemand'
; Default Value: 10s
pm.process_idle_timeout = 10s;
; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
pm.max_requests = 1000
; Make sure the FPM workers can reach the environment variables for configuration
clear_env = no
; Catch output from PHP
catch_workers_output = yes
; Remove the 'child 10 said into stderr' prefix in the log and only show the actual message
decorate_workers_output = no
; Enable ping page to use in healthcheck
ping.path = /fpm-ping

2
config/php.ini Normal file
View File

@ -0,0 +1,2 @@
[Date]
date.timezone="UTC"

24
config/supervisord.conf Normal file
View File

@ -0,0 +1,24 @@
[supervisord]
nodaemon=true
user=root
logfile=/dev/null
logfile_maxbytes=0
pidfile=/run/supervisord.pid
[program:php-fpm]
command=php-fpm84 -F -R
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autorestart=false
startretries=0
[program:caddy]
command=caddy run --config /etc/caddy/Caddyfile
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autorestart=false
startretries=0

12
docker-compose.test.yml Normal file
View File

@ -0,0 +1,12 @@
version: '3.5'
services:
app:
image: ${IMAGE_NAME}:${IMAGE_TAG}
build: .
sut:
image: alpine:3.13
depends_on:
- app
command: /tmp/run_tests.sh
volumes:
- "./run_tests.sh:/tmp/run_tests.sh:ro"

View File

@ -0,0 +1,18 @@
volumes:
phpbb-sqlite: {}
phpbb-files: {}
phpbb-store: {}
phpbb-avatars: {}
services:
phpbb:
build: .
ports:
- '127.0.0.1:8000:80'
volumes:
- 'phpbb-sqlite:/phpbb/sqlite'
- 'phpbb-files:/phpbb/www/files'
- 'phpbb-store:/phpbb/www/store'
- 'phpbb-avatars:/phpbb/www/images/avatars/upload'
environment:
PHPBB_INSTALL: 'true'

View File

@ -0,0 +1,19 @@
volumes:
phpbb-sqlite: {}
phpbb-files: {}
phpbb-store: {}
phpbb-avatars: {}
services:
phpbb:
image: selim13/phpbb:3.3
ports:
- '127.0.0.1:8000:80'
volumes:
- 'phpbb-sqlite:/phpbb/sqlite'
- 'phpbb-files:/phpbb/www/files'
- 'phpbb-store:/phpbb/www/store'
- 'phpbb-avatars:/phpbb/www/images/avatars/upload'
environment:
#PHPBB_INSTALL: 'true'
PHPBB_DB_AUTOMIGRATE: 'true'

25
phpbb/config.php Normal file
View File

@ -0,0 +1,25 @@
<?php
$dbms = 'phpbb\\db\\driver\\' . getenv('PHPBB_DB_DRIVER');
$dbhost = getenv('PHPBB_DB_HOST');
$dbport = getenv('PHPBB_DB_PORT');
$dbname = getenv('PHPBB_DB_NAME');
$dbuser = getenv('PHPBB_DB_USER');
$dbpasswd = getenv('PHPBB_DB_PASSWD');
$table_prefix = getenv('PHPBB_DB_TABLE_PREFIX');
$phpbb_adm_relative_path = 'adm/';
$acm_type = 'phpbb\\cache\\driver\\file';
@define('PHPBB_INSTALLED', true);
if (getenv('PHPBB_DISPLAY_LOAD_TIME') === 'true') {
@define('PHPBB_DISPLAY_LOAD_TIME', true);
}
if (getenv('PHPBB_DEBUG') === 'true') {
@define('DEBUG', true);
}
if (getenv('PHPBB_DEBUG_CONTAINER') === 'true') {
@define('DEBUG_CONTAINER', true);
}

3
run_tests.sh Normal file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env sh
apk --no-cache add curl
curl --silent --fail http://app:8080 | grep 'PHP 8.1'

2
src/public/index.php Normal file
View File

@ -0,0 +1,2 @@
<?php
phpinfo();

1
src/public/test.html Normal file
View File

@ -0,0 +1 @@
This static HTML file is served by Caddy

24
start.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/sh
set -e
[[ "${PHPBB_INSTALL}" = "true" ]] && rm config.php
[[ "${PHPBB_INSTALL}" != "true" ]] && rm -rf install
db_wait() {
if [[ "${PHPBB_DB_WAIT}" = "true" && "${PHPBB_DB_DRIVER}" != "sqlite3" && "${PHPBB_DB_DRIVER}" != "sqlite" ]]; then
until nc -z ${PHPBB_DB_HOST} ${PHPBB_DB_PORT}; do
echo "$(date) - waiting for database on ${PHPBB_DB_HOST}:${PHPBB_DB_PORT} to start before applying migrations"
sleep 3
done
fi
}
db_migrate() {
if [[ "${PHPBB_DB_AUTOMIGRATE}" = "true" && "${PHPBB_INSTALL}" != "true" ]]; then
echo "$(date) - applying migrations"
php84 bin/phpbbcli.php db:migrate
fi
}
db_wait && db_migrate && exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf

31
update.sh Executable file
View File

@ -0,0 +1,31 @@
#!/bin/bash
set -e
VERSION="$1"
if [ ! -n "$VERSION" ]; then
echo "Usage: $0 phpbb_minor_version"
echo
echo "Example: $0 3.3"
exit 1
fi
VERSIONS_URL="http://version.phpbb.com/phpbb/versions.json"
LATEST_VERSION=$(curl --silent --location $VERSIONS_URL | jq --raw-output ".stable[\"$VERSION\"].current")
if [ "$LATEST_VERSION" == "null" ]; then
echo "PHPBB version not found"
exit 1
fi
SHA_URL="https://download.phpbb.com/pub/release/3.3/$LATEST_VERSION/phpBB-$LATEST_VERSION.tar.bz2.sha256"
SHA=$(curl --silent --location $SHA_URL | cut -d ' ' -f 1)
if [ "${#SHA}" != "64" ]; then
echo "Failed to fetch SHA256 of an archive"
exit 1
fi
sed -i "s/^ENV PHPBB_VERSION .*$/ENV PHPBB_VERSION $LATEST_VERSION/" Dockerfile
sed -i "s/^ENV PHPBB_SHA256 .*$/ENV PHPBB_SHA256 $SHA/" Dockerfile
echo "OK"