Add Dockerfile and entrypoint optimizations, Composer auto-install, and dependency updates

- Use `__DIR__` for `vendor/autoload.php` in PHP autoload path.
- Add Composer dependency auto-installation at container startup with `docker-entrypoint.sh`.
- Extend Docker image to include `libssl-dev` and `ca-certificates` for TLS support.
- Enable dynamic installation of application dependencies during runtime via entrypoint.
- Update Composer dependencies, including AWS SDK, Guzzle, and OpenTelemetry libraries.
This commit is contained in:
Jeppe Bundgaard
2026-02-13 22:21:46 +01:00
parent e66aaecac5
commit 081d8ad284
5 changed files with 459 additions and 216 deletions
+9 -2
View File
@@ -44,6 +44,10 @@ COPY nginx.conf /etc/nginx/nginx.conf
# Install Composer
COPY --from=composer:2.6 /usr/bin/composer /usr/bin/composer
# Runtime bootstrap: lightweight entrypoint to ensure Composer deps exist when app is bind-mounted
COPY services/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Install PHP dependencies through Composer (only where composer.json exists)
# Main app dependencies
RUN set -e \
@@ -64,5 +68,8 @@ RUN chown -R www-data:www-data /var/www/html && chmod -R 755 /var/www/html
# Expose port 80 (HTTP) and 443 (HTTPS)
EXPOSE 80 443
# Start services (Nginx and Redis) when the container starts
CMD service redis-server start && nginx -g "daemon off;" && php-fpm
# Default entrypoint ensures vendor/autoload.php exists, then executes the given command (overridden by docker-compose)
ENTRYPOINT ["docker-entrypoint.sh"]
# Start services when no command is provided (docker-compose overrides this with ["php-fpm"])
CMD ["php-fpm"]
+355 -203
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -21,7 +21,7 @@ header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Customer-Nu
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
/** Autoload */
require_once 'vendor/autoload.php';
require_once __DIR__ . '/vendor/autoload.php';
/** Load all Interfaces */
foreach ( glob(WD . '/interfaces/*.php') as $interface ) {
require_once $interface;
+16 -10
View File
@@ -9,6 +9,7 @@ COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Install required extensions and dependencies
# - Include libssl-dev and ca-certificates to guarantee PHP openssl extension and TLS trust store
RUN apt-get update && apt-get install -y \
libpng-dev \
libonig-dev \
@@ -20,29 +21,34 @@ RUN apt-get update && apt-get install -y \
git \
curl \
libzip-dev \
libssl-dev \
ca-certificates \
default-mysql-client \
&& docker-php-ext-install mbstring exif pcntl bcmath gd pdo_mysql mysqli zip \
&& update-ca-certificates \
&& docker-php-ext-install mbstring exif pcntl bcmath gd pdo_mysql mysqli zip openssl \
&& pecl install imagick \
&& docker-php-ext-enable imagick
# Copy application files into the container
COPY /nginx/app /var/www/html
## Do not copy application code at build time; it will be bind-mounted by docker-compose
## If you wish to build a self-contained image, uncomment the next line and adjust the path:
## COPY services/nginx/app /var/www/html
# Set the appropriate permissions for the working directory
RUN chown -R www-data:www-data /var/www/html \
&& chmod -R 755 /var/www/html
# Install using Composer
RUN composer install --no-dev
# Install the /var/www/html/modules/washcertificates directory
WORKDIR /var/www/html/modules/washcertificates
RUN composer install --no-dev
## Composer installs are performed at container start by docker-entrypoint.sh
ENV COMPOSER_ALLOW_SUPERUSER=1
## Ensure workdir is correct
WORKDIR /var/www/html
# Copy and enable entrypoint that installs Composer deps on first run
COPY services/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Expose port 9000
EXPOSE 9000
# Start PHP-FPM when the container starts
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["php-fpm"]
+78
View File
@@ -0,0 +1,78 @@
#!/bin/sh
set -e
# Config
APP_DIR="/var/www/html"
MODULE_DIR="$APP_DIR/modules/washcertificates"
LOG_FILE="/var/log/php/composer-install.log"
# Gate auto-install (set to "true" only on one PHP container, e.g. php1)
AUTO_COMPOSER_INSTALL="${AUTO_COMPOSER_INSTALL:-true}"
log() { printf "[entrypoint] %s\n" "$*"; }
wait_for_file() {
target="$1"; timeout="${2:-120}"; i=0
while [ "$i" -lt "$timeout" ]; do
if [ -e "$target" ]; then return 0; fi
sleep 1; i=$((i+1))
done
return 1
}
with_install_lock() {
# Poor-man's lock using a directory
while ! mkdir /tmp/composer-install.lock 2>/dev/null; do
sleep 1
done
trap 'rmdir /tmp/composer-install.lock 2>/dev/null || true' EXIT HUP INT TERM
"$@"
rmdir /tmp/composer-install.lock 2>/dev/null || true
trap - EXIT HUP INT TERM
}
install_if_needed() {
dir="$1"
if [ -f "$dir/composer.json" ]; then
if [ ! -f "$dir/vendor/autoload.php" ]; then
log "Installing Composer deps in $dir ..."
# Ensure log directory exists
mkdir -p "$(dirname "$LOG_FILE")" 2>/dev/null || true
# Run install and log output
if ! COMPOSER_ALLOW_SUPERUSER=1 composer install \
--no-dev --prefer-dist --optimize-autoloader --no-interaction \
-d "$dir" 2>&1 | tee -a "$LOG_FILE"; then
log "ERROR: composer install failed in $dir. See $LOG_FILE"
exit 1
fi
# Verify autoload was created
if [ ! -f "$dir/vendor/autoload.php" ]; then
log "ERROR: autoload.php still missing after install in $dir. See $LOG_FILE"
exit 1
fi
# Best-effort permissions fix (ignore errors on non-Linux filesystems)
chown -R www-data:www-data "$dir/vendor" 2>/dev/null || true
else
log "vendor already present in $dir — skipping"
fi
fi
}
# Optionally perform auto-install (only on the designated container)
if [ "$AUTO_COMPOSER_INSTALL" = "true" ]; then
# Wait for the bind mount and composer.json to appear (common on Windows/macOS)
if ! wait_for_file "$APP_DIR/composer.json" 120; then
log "WARNING: $APP_DIR/composer.json not found after waiting — skipping auto-install"
else
with_install_lock install_if_needed "$APP_DIR"
fi
# Module (optional)
if [ -f "$MODULE_DIR/composer.json" ]; then
with_install_lock install_if_needed "$MODULE_DIR"
fi
else
log "AUTO_COMPOSER_INSTALL=false — skipping Composer auto-install"
fi
exec "$@"