feat: add basic Docker configuration for backend and frontend services

This commit is contained in:
2025-10-28 12:28:11 +01:00
parent 7cf72fec7b
commit 79a8c4f229
6 changed files with 224 additions and 0 deletions

73
backend/Dockerfile Normal file
View File

@@ -0,0 +1,73 @@
FROM php:8.3-fpm-bullseye
# Update the system
RUN apt update -y
RUN apt upgrade -y
RUN apt install -y build-essential
RUN apt install -y libonig-dev zlib1g-dev libpng-dev libicu-dev libzip-dev libjpeg-dev libfreetype6-dev libwebp-dev libavif-dev libxpm-dev
RUN apt install -y nano procps git
# Install extensions
RUN docker-php-ext-install -j$(nproc) mbstring
RUN docker-php-ext-install -j$(nproc) intl
RUN docker-php-ext-install -j$(nproc) pdo_mysql
RUN docker-php-ext-install -j$(nproc) zip
RUN pecl install zstd
RUN docker-php-ext-enable zstd
# Install GD module
RUN docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg=/usr/local/lib --with-webp --with-xpm --with-avif
RUN docker-php-ext-install -j$(nproc) gd
# Install EXIF module
RUN docker-php-ext-configure exif --enable-exif
RUN docker-php-ext-install -j$(nproc) exif
# Install OPCache
RUN docker-php-ext-configure opcache --enable-opcache
RUN docker-php-ext-install -j$(nproc) opcache
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
# Add extra configuration options
RUN echo 'memory_limit = 1024M' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini;
RUN echo 'opcache.memory_consumption = 256' >> /usr/local/etc/php/conf.d/docker-php-opcache.ini;
RUN echo 'max_execution_time = 180' >> /usr/local/etc/php/conf.d/docker-php-exec-time.ini;
RUN echo 'pm.max_children = 32' >> /usr/local/etc/php-fpm.d/zz-docker.conf;
RUN echo 'pm.max_requests = 32' >> /usr/local/etc/php-fpm.d/zz-docker.conf;
RUN echo 'listen.backlog = 256' >> /usr/local/etc/php-fpm.d/zz-docker.conf;
# OPCache tuning
RUN echo 'opcache.enable_file_override=1' >> /usr/local/etc/php/conf.d/docker-php-opcache.ini;
RUN echo 'opcache.interned_strings_buffer=20' >> /usr/local/etc/php/conf.d/docker-php-opcache.ini;
# Performance optimizations
RUN echo 'zend.assertions=-1' >> /usr/local/etc/php/conf.d/docker-php-sw-opts.ini;
RUN echo 'zend.detect_unicode=0' >> /usr/local/etc/php/conf.d/docker-php-sw-opts.ini;
RUN echo 'realpath_cache_ttl=3600' >> /usr/local/etc/php/conf.d/docker-php-sw-opts.ini;
# Copy the backend project
COPY . /app
# Run composer
WORKDIR /app
RUN composer install
# Fix permissions
RUN chgrp -R 33 /app
RUN chown -hR 33:33 /app
# Remove .env if copied
RUN rm /app/.env
# Copy the entrypoint script
COPY ./docker/entrypoint.sh /entrypoint.sh
# Make it executable
RUN chmod +x /entrypoint.sh
STOPSIGNAL SIGTERM
# Run php-fpm
CMD ["/entrypoint.sh"]

View File

@@ -0,0 +1,14 @@
#!/bin/bash
function exit_container_SIGTERM(){
echo "Caught SIGTERM"
exit 0
}
trap exit_container_SIGTERM SIGTERM
echo "Setting /app/public ownership..."
chgrp -R 33 /app
chown -hR 33:33 /app
echo "Starting PHP-FPM..."
php-fpm -F & wait

7
docker/.gitignore vendored Normal file
View File

@@ -0,0 +1,7 @@
.Caddyfile
caddy-data/
caddy-config/
mariadb_data/

24
docker/Caddyfile Normal file
View File

@@ -0,0 +1,24 @@
# Leave this section
{
admin off
}
http://localhost {
root * /app/public
encode zstd gzip
php_fastcgi php-fpm:9000
@laravel_not_found {
not file
not path /index.php*
}
rewrite @laravel_not_found /index.php
file_server
}
# Leave this section
http://localhost:2019 {
metrics /metrics
}

86
docker/docker-compose.yml Normal file
View File

@@ -0,0 +1,86 @@
services:
node:
container_name: node
build:
context: ../frontend
dockerfile: Dockerfile
restart: unless-stopped
depends_on:
php-fpm:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost"]
start_period: 10s
interval: 1m
timeout: 5s
retries: 5
# Caddy webserver
caddy:
container_name: caddy
image: caddy:2.10.0-alpine
restart: unless-stopped
ports:
- 80:80 # Needed for HTTP->HTTPS redirection
- 443:443
- 443:443/udp
volumes:
# Caddy routes files (read-only)
- ./Caddyfile:/etc/caddy/Caddyfile:ro
# Caddy certificates and other temporary data
- ./caddy-data:/data
# Caddy configuration
- ./caddy-config:/config
depends_on:
- php-fpm
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:2019/metrics"]
start_period: 10s
interval: 1m
timeout: 5s
retries: 5
# Custom PHP container
php-fpm:
container_name: php-fpm
user: 'www-data:www-data'
build:
context: ../backend
dockerfile: Dockerfile
restart: unless-stopped
env_file:
- ../backend/.env
depends_on:
database:
condition: service_healthy
healthcheck:
test: ["CMD", "pgrep", "-x", "php-fpm"]
start_period: 10s
interval: 1m
timeout: 5s
retries: 5
# MariaDB database
# No ports are open, only Shopware itself has access
database:
container_name: mariadb
image: mariadb:11.8.2-noble
restart: unless-stopped
cap_add:
# Allow memory binding
- SYS_NICE
environment:
# Change these if needed
MARIADB_DATABASE: "isop"
MARIADB_ROOT_PASSWORD: "admin"
volumes:
# Database data
- ./mariadb_data:/var/lib/mysql
healthcheck:
test: [ "CMD", "healthcheck.sh", "--su-mysql", "--connect", "--innodb_initialized" ]
start_period: 10s
interval: 1m
timeout: 5s
retries: 3

20
frontend/Dockerfile Normal file
View File

@@ -0,0 +1,20 @@
FROM node:lts
# Update the system
RUN apt update -y
RUN apt upgrade -y
# Copy the frontend project
COPY . /app
# Run NPM
WORKDIR /app
RUN npm install
# Build
RUN npm run build
STOPSIGNAL SIGTERM
# Run frontend web server
CMD ["node .output/server/index.mjs"]