From 8099df95b5e811ffc4381417d09b1659bd022628 Mon Sep 17 00:00:00 2001 From: Vladimir Hodakov Date: Mon, 6 Jan 2025 23:08:30 +0400 Subject: [PATCH] Initial commit --- .dockerignore | 3 + .gitignore | 4 + Dockerfile | 95 ++++++++++++++ LICENSE | 22 ++++ README.MD | 210 ++++++++++++++++++++++++++++++ config/Caddyfile | 23 ++++ config/fpm-pool.conf | 56 ++++++++ config/php.ini | 2 + config/supervisord.conf | 24 ++++ docker-compose.test.yml | 12 ++ examples/docker-compose.build.yml | 18 +++ examples/docker-compose.yml | 19 +++ phpbb/config.php | 25 ++++ run_tests.sh | 3 + src/public/index.php | 2 + src/public/test.html | 1 + start.sh | 24 ++++ update.sh | 31 +++++ 18 files changed, 574 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.MD create mode 100644 config/Caddyfile create mode 100644 config/fpm-pool.conf create mode 100644 config/php.ini create mode 100644 config/supervisord.conf create mode 100644 docker-compose.test.yml create mode 100644 examples/docker-compose.build.yml create mode 100644 examples/docker-compose.yml create mode 100644 phpbb/config.php create mode 100644 run_tests.sh create mode 100644 src/public/index.php create mode 100644 src/public/test.html create mode 100755 start.sh create mode 100755 update.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3cb5182 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.secrets +.act +examples diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e0dc53 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +pkg +.secrets +.idea +.vscode diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..76c3b2b --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6a04821 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..701bb94 --- /dev/null +++ b/README.MD @@ -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 +``` diff --git a/config/Caddyfile b/config/Caddyfile new file mode 100644 index 0000000..f22d5e1 --- /dev/null +++ b/config/Caddyfile @@ -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 +} diff --git a/config/fpm-pool.conf b/config/fpm-pool.conf new file mode 100644 index 0000000..4be2061 --- /dev/null +++ b/config/fpm-pool.conf @@ -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 diff --git a/config/php.ini b/config/php.ini new file mode 100644 index 0000000..7bb1be5 --- /dev/null +++ b/config/php.ini @@ -0,0 +1,2 @@ +[Date] +date.timezone="UTC" diff --git a/config/supervisord.conf b/config/supervisord.conf new file mode 100644 index 0000000..e1192bb --- /dev/null +++ b/config/supervisord.conf @@ -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 diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 0000000..ae8a05b --- /dev/null +++ b/docker-compose.test.yml @@ -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" diff --git a/examples/docker-compose.build.yml b/examples/docker-compose.build.yml new file mode 100644 index 0000000..1ef4013 --- /dev/null +++ b/examples/docker-compose.build.yml @@ -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' \ No newline at end of file diff --git a/examples/docker-compose.yml b/examples/docker-compose.yml new file mode 100644 index 0000000..4d849f9 --- /dev/null +++ b/examples/docker-compose.yml @@ -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' diff --git a/phpbb/config.php b/phpbb/config.php new file mode 100644 index 0000000..368484d --- /dev/null +++ b/phpbb/config.php @@ -0,0 +1,25 @@ +