Skip to content

Commit

Permalink
[5.x] Improve debug messages (#58)
Browse files Browse the repository at this point in the history
Some minor improvements to the content of debug messages and variable naming.
  • Loading branch information
shinsenter authored Feb 16, 2024
1 parent cee2b4a commit ed90244
Show file tree
Hide file tree
Showing 80 changed files with 443 additions and 238 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ jobs:
file: ${{ env.BUILD_DOCKERFILE }}
context: ${{ env.BUILD_CONTEXT }}
tags: ${{ env.BUILD_TMP_NAME }}
sbom: true
build-args: |
BUILD_CACHE_KEY=${{ env.BUILD_CACHE_KEY }}
BUILD_CACHE_PATH=${{ env.BUILD_CACHE_PATH }}
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/php-web-servers-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,11 @@ jobs:
- "app-cakephp4"
- "app-codeigniter4"
- "app-drupal"
- "app-fuelphp"
- "app-laminas"
- "app-laravel"
- "app-phpmyadmin"
- "app-slim"
- "app-symfony"
- "app-wordpress"
php_version:
Expand Down Expand Up @@ -175,13 +178,11 @@ jobs:
app:
- "app-crater"
- "app-flarum"
- "app-fuelphp"
- "app-grav"
- "app-hyperf"
- "app-kirby"
- "app-laminas"
- "app-mautic"
- "app-slim"
- "app-phpixie"
- "app-statamic"
- "app-yii"
php_version:
Expand Down
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@

All notable changes to this project will be documented in this file.

## [5.0.1] - 2024-02-16

We have made some minor improvements to the content of debug messages and variable naming.

## [5.0.0] - 2024-02-15

We are rolling out updated Docker images based on the [official PHP Docker images](https://hub.docker.com/_/php). We have taken steps to minimize the impact of this change on your existing setup.
We are thrilled to announce the rollout of updated Docker images (v5) built directly from the [official PHP Docker images](https://hub.docker.com/_/php) to ensure you get the most up-to-date packages and bug fixes!

Check out the document and available tags on Docker Hub:
https://hub.docker.com/r/shinsenter/php
> The `-alpine` and `-tidy` tags are lightweight Alpine-based images to speed up your builds and save bandwidth.
These images are updated daily to stay current with the latest PHP, OS, and tooling updates for maximum freshness. We also apply stable version tags on a separate repo for dependable production images:
https://hub.docker.com/r/shinsenter/php-archives/tags

We are using different Docker image tags to maintain the old Docker image versions. All old Docker images have been published with `*-deprecated` tag names. However, we will no longer provide any update for the old Docker images. https://hub.docker.com/r/shinsenter/php/tags?page=1&name=-deprecated
Old image versions (pre v5.x) now have `-deprecated` tags but will no longer receive updates. See them here:
https://hub.docker.com/r/shinsenter/php/tags?name=-deprecated

<!--
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Customizable PHP Docker Images
# PHP Docker Images

📦 A set of prebuilt PHP Docker images that simplify customization and extension installation.

Expand All @@ -8,9 +8,9 @@

## Introduction

Our PHP Docker images are built on top of [the official PHP Docker images](https://hub.docker.com/_/php) to enable easy tuning of PHP and PHP-FPM settings via environment variables. This avoids having to rebuild images to change settings.
Our PHP Docker images are built on top of [the official PHP Docker images](https://hub.docker.com/_/php). These images enable easy tuning of PHP and PHP-FPM settings through environment variables. This eliminates the need to rebuild images when changing settings.

These images also include the latest version of [Composer](https://getcomposer.org), and well-known web servers like [Apache2](https://httpd.apache.org), [Nginx](https://nginx.org), [Nginx Unit](https://unit.nginx.org) or [FrankenPHP](https://frankenphp.dev) pre-installed so your projects can get started faster without extra setup.
These images also include the latest version of [Composer](https://getcomposer.org), well-known web servers like [Apache2](https://httpd.apache.org), [Nginx](https://nginx.org), [Nginx Unit](https://unit.nginx.org) or [FrankenPHP](https://frankenphp.dev), allowing projects to get started faster without additional installation.

> 🪶 Note: Though built on top of the official PHP images and including more useful extensions, we have **drastically reduced the sizes** compared to the base images while maintaining compatibility. This optimization improves download times and resource usage without sacrificing functionality, thanks to the [docker-squash](https://code.shin.company/docker-squash) project.
Expand Down Expand Up @@ -127,7 +127,7 @@ services:

## Pre-installed PHP Extensions

Popular PHP extensions are pre-installed by default, so your projects can get started faster without extra setup.
Popular PHP extensions are pre-installed by default, allowing projects to get started faster without additional installation.

```list
apcu
Expand Down Expand Up @@ -240,16 +240,16 @@ This mechanism can be used to initialize projects before the main program on the

#### Usage

For example, a script called `00-cache-config` could be copied into `/startup/` via a Dockerfile.
For example, a script called `00-copy-config` could be copied into `/startup/` via a Dockerfile.

> Note: The script file must have executable permissions to run.

```Dockerfile
FROM shinsenter/php:8.3-cli
ADD ./application /var/www/html
ADD ./00-cache-config /startup/00-cache-config
RUN chmod +x /startup/00-cache-config
ADD ./autorun/00-copy-config /startup/00-copy-config
RUN chmod +x /startup/00-copy-config
```

> 👉🏻 Info: The startup directory already includes a script called `99-greeting` that prints a welcome message when container starts:
Expand Down
3 changes: 3 additions & 0 deletions build/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ app-*)
LATEST_PHP="8.1"
verlt "$PHP_VERSION" "8.0" && SKIP_BUILD=1
;;
phpixie)
# https://phpixie.com/quickstart.html
;;
phpmyadmin)
# https://docs.phpmyadmin.net/en/latest/setup.html
;;
Expand Down
2 changes: 1 addition & 1 deletion build/docker-squash
6 changes: 3 additions & 3 deletions src/php/base-os.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ This mechanism can be used to initialize projects before the main program on the

#### Usage

For example, a script called `00-cache-config` could be copied into `/startup/` via a Dockerfile.
For example, a script called `00-copy-config` could be copied into `/startup/` via a Dockerfile.

> Note: The script file must have executable permissions to run.

```Dockerfile
FROM shinsenter/ubuntu-s6:latest
ADD ./00-cache-config /startup/00-cache-config
RUN chmod +x /startup/00-cache-config
ADD ./autorun/00-copy-config /startup/00-copy-config
RUN chmod +x /startup/00-copy-config
```

> 👉🏻 Info: The startup directory already includes a script called `99-greeting` that prints a welcome message when container starts.
Expand Down
7 changes: 4 additions & 3 deletions src/php/common/docker-php-entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

export TZ="${TZ:=UTC}"

# setuid bit
chmod 4755 /usr/local/bin/web-*
debug-echo "Initialize container"
web-mkdir "$(app-path)"

# activity logging
touch /var/log/startup.log
echo "$(date): $0 $@" >>/var/log/startup.log
echo "$(date) $(whoami)@$(hostname):$(pwd)\$ $0 $@" >>/var/log/startup.log

# set timezone
if [ ! -z "$TZ" ] && [ -e /usr/share/zoneinfo/$TZ ]; then
Expand Down Expand Up @@ -44,4 +44,5 @@ fi
# move to application directory
if [ -d "$(app-path)" ]; then cd "$(app-path)"; fi

debug-echo "Start container with command $@"
exec with-env "$@"
7 changes: 5 additions & 2 deletions src/php/common/os-base.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
################################################################################

# set defaults from build arguments
ARG DEBCONF_NOWARNINGS=yes
ARG DEBIAN_FRONTEND=noninteractive
ARG DOCKER_ENTRYPOINT=/usr/local/bin/docker-php-entrypoint

ARG APP_PATH=${APP_PATH:-/var/www/html}
ARG DOCUMENT_ROOT=${DOCUMENT_ROOT:-}
ARG APP_GROUP=${APP_GROUP:-www-data}
ARG APP_USER=${APP_USER:-www-data}

Expand All @@ -35,6 +35,9 @@ RUN <<'EOF'
echo 'Configure OS middlewares'
set -e

# setuid bit
chmod 4755 /usr/local/bin/web-*

# install common packages
APK_PACKAGES='bash shadow su-exec tar xz' \
APT_PACKAGES='procps xz-utils' \
Expand Down Expand Up @@ -81,7 +84,7 @@ env-default 'alias ll="ls -alh"'
# Set OS default settings
env-default '# Environment variables for OS'
env-default DEBIAN_FRONTEND $DEBIAN_FRONTEND
env-default DOCUMENT_ROOT $DOCUMENT_ROOT
env-default DEBCONF_NOWARNINGS $DEBCONF_NOWARNINGS
env-default HISTCONTROL 'ignoredups:ignorespace'
env-default HISTFILESIZE '2000'
env-default HISTSIZE '1000'
Expand Down
2 changes: 1 addition & 1 deletion src/php/common/rootfs/etc/cleanup.d/00-php-source
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
rm -rf /usr/src/php* || true

if is-true $CLEANUP_PHPDBG && has-cmd phpdbg; then
echo 'Removing phpdbg binary'
debug-echo -w 'Removing phpdbg binary'
rm -rf "$(command -v phpdbg)" || true
fi

Expand Down
12 changes: 7 additions & 5 deletions src/php/common/rootfs/etc/cont-init.d/00-usergroup
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,35 @@ DEFAULT_GROUP="www-data"
DEFAULT_UID="$(id -u $DEFAULT_USER)"
DEFAULT_GID="$(id -g $DEFAULT_USER)"

APPPATH="$(app-path)"
APP_PATH="$(app-path)"
APP_USER="${APP_USER:=$DEFAULT_USER}"
APP_GROUP="${APP_GROUP:=$DEFAULT_GROUP}"
APP_UID="${APP_UID:=$DEFAULT_UID}"
APP_GID="${APP_GID:=$DEFAULT_GID}"
USER_HOME="/home/$APP_USER"

rand_id() { echo "$((RANDOM % 500 + 499))"; }

################################################################################

debug-echo "Verify group $APP_GROUP"
if [ "$APP_GROUP" != "$DEFAULT_GROUP" ]; then
APP_GID="${APP_GID:=$(rand_id)}"
groupadd -o -r -g $APP_GID $APP_GROUP 2>&1 >/dev/null
else
APP_GID="${APP_GID:=$DEFAULT_GID}"
if [ "$APP_GID" != "$DEFAULT_GID" ]; then
groupmod -o -g $APP_GID $APP_GROUP 2>&1
web-chown "GID changed to $APP_GROUP ($APP_GID)."
fi
fi

debug-echo "Verify user $APP_USER"
if [ "$APP_USER" != "$DEFAULT_USER" ]; then
APP_UID="${APP_UID:=$(rand_id)}"
useradd -o -r -g $APP_GID \
-G $APP_GROUP,$DEFAULT_GROUP --no-log-init \
-d $USER_HOME -s /sbin/nologin -u $APP_UID $APP_USER 2>&1 >/dev/null
else
APP_UID="${APP_UID:=$DEFAULT_UID}"
usermod -g $APP_GID -G $APP_GROUP,$DEFAULT_GROUP \
-d $USER_HOME -s /sbin/nologin $APP_USER 2>&1

Expand All @@ -48,5 +50,5 @@ else
fi
fi

web-mkdir $USER_HOME
web-mkdir $APPPATH
debug-echo "Create $APP_PATH if not exists"
web-mkdir $APP_PATH
4 changes: 2 additions & 2 deletions src/php/common/rootfs/etc/cont-init.d/10-optimize
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env sh

# generate PHP config
if has-cmd php-envvars; then
debug-echo "Generate PHP config"
php-envvars export_dynamic_conf 2>&1
fi

# tune PHP-FPM performance
if is-true $ENABLE_TUNING_FPM && has-cmd fpm-pm; then
debug-echo -w "Tune PHP-FPM performance"
fpm-pm
fi
60 changes: 35 additions & 25 deletions src/php/common/rootfs/etc/cont-init.d/10-project
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,37 @@
# License: https://code.shin.company/php/blob/main/LICENSE
################################################################################

APPPATH="$(app-path)"
APPROOT="$(app-root)"
APP_PATH="$(app-path)"
APP_ROOT="$(app-root)"

web-mkdir "$APP_PATH"

# copy from source
if ! is-true $DISABLE_AUTORUN_COPYING_SOURCE && [ -d /source/ ]; then
mv {/source/*,/source/.*} $APPPATH/ 2>&1 >/dev/null
web-chown "Source code copied to $APPPATH."
if ! is-true $DISABLE_AUTORUN_COPYING_SOURCE; then
if [ -d /source/ ] && [ -z "$(ls -A "$APP_PATH")" ]; then
debug-echo "Copy files from /source/ to $APP_PATH"
mv {/source/*,/source/.*} $APP_PATH/ 2>&1 >/dev/null
web-chown "Source code copied to $APP_PATH."
fi
fi

# create Composer project
if ! is-true $DISABLE_AUTORUN_CREATING_PROJECT && [ ! -z "$INITIAL_PROJECT" ]; then
web-mkdir "$APPPATH"
if [ -z "$(ls -A "$APPPATH")" ] && has-cmd composer; then
if [ -z "$(ls -A "$APP_PATH")" ] && has-cmd composer; then
debug-echo "Create Composer project $INITIAL_PROJECT in $APP_PATH"
cd "$APP_PATH"
set -e
cd "$APPPATH"

composer create-project $COMPOSER_CREATE_OPTIONS \
-n --no-secure-http --no-install --no-scripts \
-- "$INITIAL_PROJECT" "$APPPATH"
-- "$INITIAL_PROJECT" "$APP_PATH"

config="$APPPATH/composer.json"
config="$APP_PATH/composer.json"

# intall git if needed
if grep -q -F '"git"' $config || is-true $COMPOSER_REQUIRES_GIT; then
pkg-add git
git config --global --add safe.directory "$APPPATH"
git config --global --add safe.directory "$APP_PATH"
fi

# intall npm if needed
Expand All @@ -51,28 +57,31 @@ if ! is-true $DISABLE_AUTORUN_CREATING_PROJECT && [ ! -z "$INITIAL_PROJECT" ]; t
fi

composer config -n --unset "allow-plugins.*/*"
web-chown "Project $INITIAL_PROJECT created in $APPPATH."
web-chown "Project $INITIAL_PROJECT created in $APP_PATH."
else
web-debug "Skip creating project $INITIAL_PROJECT because $APPPATH is not empty."
debug-echo "Skip creating project $INITIAL_PROJECT because $APP_PATH is not empty."
fi
fi

# run composer install when vendor directory or ClassLoader.php is missing
if ! is-true $DISABLE_AUTORUN_COMPOSER_INSTALL && [ -f "$APPPATH/composer.json" ] && has-cmd composer; then
cd "$APPPATH"
if ! is-true $DISABLE_AUTORUN_COMPOSER_INSTALL && [ -e "$APP_PATH/composer.json" ] && has-cmd composer; then
cd "$APP_PATH"
set -e
vendor_dir=$(composer config vendor-dir)
if [ ! -d "$APPPATH/$vendor_dir" ] || [ ! -f "$vendor_dir/composer/ClassLoader.php" ]; then
if [ ! -d "$APP_PATH/$vendor_dir" ] || [ ! -e "$vendor_dir/composer/ClassLoader.php" ]; then
debug-echo "Run composer install because ClassLoader.php is missing"
composer install $COMPOSER_INSTALL_OPTIONS -n
web-chown "Composer packages were installed in $APPPATH."
web-chown "Composer packages were installed in $APP_PATH."
fi
fi

web-mkdir "$APPROOT"
web-mkdir "$APP_ROOT"

# create index.php when it doesn't exist
if ! is-true $DISABLE_AUTORUN_GENERATING_INDEX; then
if [ -z "$(ls -A "$APPROOT")" ]; then
cat <<PHP >"$APPROOT/index.php"
if [ -z "$(ls -A "$APP_ROOT")" ]; then
debug-echo "Create index.php"
cat <<PHP >"$APP_ROOT/index.php"
<?php
// generated at $(date)
if ((bool) trim((string) shell_exec('is-debug && echo 1 || echo 0'))) {
Expand All @@ -81,14 +90,15 @@ if ((bool) trim((string) shell_exec('is-debug && echo 1 || echo 0'))) {
echo 'It works!';
}
PHP
web-chown fix "$APPROOT/index.php" 2>&1 >/dev/null
web-chown fix "$APP_ROOT/index.php" 2>&1 >/dev/null
else
web-debug "Skip creating index.php because $APPROOT is not empty."
debug-echo "Skip creating index.php because $APP_ROOT is not empty."
fi
fi

# fix .htaccess to allow uri path after index.php
if [ -f "$APPROOT/.htaccess" ]; then
sed -i 's|index\.php/|index.php?/|g' "$APPROOT/.htaccess" 2>&1 >/dev/null
web-chown fix "$APPROOT/.htaccess" 2>&1 >/dev/null
if [ -f "$APP_ROOT/.htaccess" ]; then
debug-echo "Fix .htaccess to allow uri path after index.php"
sed -i 's|index\.php/|index.php?/|g' "$APP_ROOT/.htaccess" 2>&1 >/dev/null
web-chown fix "$APP_ROOT/.htaccess" 2>&1 >/dev/null
fi
2 changes: 2 additions & 0 deletions src/php/common/rootfs/etc/cont-init.d/10-sendmail
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
################################################################################

if has-cmd msmtp; then
debug-echo "Configure MSMTP"
cat >/etc/msmtprc <<EOF
account default
host ${SENDMAIL_SERVER_HOSTNAME:-"mailhog"}
Expand All @@ -17,6 +18,7 @@ EOF
fi

if has-cmd ssmtp; then
debug-echo "Configure SSMTP"
cat > /etc/ssmtp/ssmtp.conf << EOF
root=postmaster
mailhub=${SENDMAIL_SERVER_HOSTNAME:-"mailhog"}:${SENDMAIL_SERVER_PORT:-"1025"}
Expand Down
2 changes: 2 additions & 0 deletions src/php/common/rootfs/etc/cont-init.d/50-autorun
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
################################################################################

if is-true $DISABLE_AUTORUN_SCRIPTS; then exit 0; fi

cd "$(app-path)"
exec autorun /startup/ 2>&1
Loading

0 comments on commit ed90244

Please sign in to comment.