- make it possible to run a custom CMD

- rename volume according to their origin
- Add arguments for required, suggested and extra php-modules
This commit is contained in:
Benjamin Brummer
2024-12-05 10:34:45 +01:00
parent d437dab72c
commit 806a340a00
3 changed files with 66 additions and 64 deletions

39
debian/Dockerfile vendored
View File

@@ -1,6 +1,9 @@
FROM php:8.3-fpm AS base FROM php:8.3-fpm AS base
ARG saxon=12.5.0 ARG php_require="bcmath gd pdo_mysql zip"
ARG php_suggest="exif imagick intl pcntl soap"
ARG php_suggest_debian="saxon-12.5.0"
ARG php_extra="opcache"
# Install system dependencies # Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
@@ -53,22 +56,20 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Install Required PHP extensions. # Install Required PHP extensions.
RUN ( curl -sSLf https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions -o - || echo 'return 1' ) | sh -s \ RUN if [ "$(dpkg --print-architecture)" = "amd64" ]; then \
bcmath \ ( curl -sSLf https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions -o - || echo 'return 1' ) | sh -s \
exif \ ${php_require} \
gd \ ${php_suggest} \
gmp \ ${php_suggest_debian} \
imagick \ ${php_extra} \
intl \ @composer; \
mysqli \ elif [ "$(dpkg --print-architecture)" = "arm64" ]; then \
opcache \ ( curl -sSLf https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions -o - || echo 'return 1' ) | sh -s \
pcntl \ ${php_require} \
pdo_mysql \ ${php_suggest} \
redis \ ${php_extra} \
saxon-${saxon} \ @composer; \
soap \ fi
zip \
@composer
# Configure PHP # Configure PHP
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
@@ -84,8 +85,8 @@ WORKDIR /var/www/html
RUN curl -s "https://api.github.com/repos/invoiceninja/invoiceninja/releases/latest" | \ RUN curl -s "https://api.github.com/repos/invoiceninja/invoiceninja/releases/latest" | \
grep -o '"browser_download_url": "[^"]*invoiceninja.tar"' | \ grep -o '"browser_download_url": "[^"]*invoiceninja.tar"' | \
cut -d '"' -f 4 | \ cut -d '"' -f 4 | \
xargs curl -L | \ xargs curl -sL | \
tar -oxvz -C /var/www/html \ tar -oxz -C /var/www/html \
&& cp /var/www/html/resources/views/react/index.blade.php /var/www/html/public/index.html \ && cp /var/www/html/resources/views/react/index.blade.php /var/www/html/public/index.html \
# File permissions # File permissions
&& find /var/www/html/ -type f -exec chmod 644 {} \; \ && find /var/www/html/ -type f -exec chmod 644 {} \; \

View File

@@ -17,9 +17,9 @@ services:
- ./php/php.ini:/usr/local/etc/php/conf.d/zzz-php.ini:ro - ./php/php.ini:/usr/local/etc/php/conf.d/zzz-php.ini:ro
- ./php/php-fpm.conf:/usr/local/etc/php-fpm.d/zzz-php-fpm.conf:ro - ./php/php-fpm.conf:/usr/local/etc/php-fpm.d/zzz-php-fpm.conf:ro
- ./supervisor/supervisord.conf:/etc/supervisor/conf.d/supervisord.conf:ro - ./supervisor/supervisord.conf:/etc/supervisor/conf.d/supervisord.conf:ro
- app_storage:/var/www/html/storage
- app_cache:/var/www/html/bootstrap/cache - app_cache:/var/www/html/bootstrap/cache
- image_public:/var/www/html/public - app_public:/var/www/html/public
- app_storage:/var/www/html/storage
networks: networks:
- app-network - app-network
depends_on: depends_on:
@@ -36,6 +36,7 @@ services:
- "80:80" - "80:80"
volumes: volumes:
- ./nginx:/etc/nginx/conf.d:ro - ./nginx:/etc/nginx/conf.d:ro
- app_public:/var/www/html/public:ro
- app_storage:/var/www/html/storage:ro - app_storage:/var/www/html/storage:ro
- image_public:/var/www/html/public:ro - image_public:/var/www/html/public:ro
networks: networks:
@@ -84,13 +85,13 @@ networks:
driver: bridge driver: bridge
volumes: volumes:
app_storage:
driver: local
app_cache: app_cache:
driver: local driver: local
app_public:
driver: local
app_storage:
driver: local
mysql_data: mysql_data:
driver: local driver: local
redis_data: redis_data:
driver: local driver: local
image_public:
driver: local

View File

@@ -29,52 +29,52 @@ docker_process_init_files() {
done done
} }
# Workaround for application updates if [ "$*" = 'supervisord -n -c /etc/supervisor/conf.d/supervisord.conf' ]; then
if [ "$(ls -A /tmp/public)" ]; then # Workaround for application updates
echo "Updating public folder..." if [ "$(ls -A /tmp/public)" ]; then
rm -rf /var/www/html/public/* \ echo "Updating public folder..."
/var/www/html/public/.htaccess \ rm -rf /var/www/html/public/.htaccess \
/var/www/html/public/.well-known /var/www/html/public/.well-known \
mv /tmp/public/* \ /var/www/html/public/*
/tmp/public/.htaccess \ mv /tmp/public/* \
/tmp/public/.well-known \ /tmp/public/.htaccess \
/var/www/html/public/ /tmp/public/.well-known \
else /var/www/html/public/
fi
echo "Public Folder is up to date" echo "Public Folder is up to date"
fi
# Ensure owner, file and directory permissions are correct # Ensure owner, file and directory permissions are correct
chown -R www-data:www-data \ chown -R www-data:www-data \
/var/www/html/storage \ /var/www/html/public \
/var/www/html/public /var/www/html/storage
find /var/www/html/storage \ find /var/www/html/public \
/var/www/html/public \ /var/www/html/storage \
-type f -exec chmod 644 {} \; -type f -exec chmod 644 {} \;
find /var/www/html/storage \ find /var/www/html/public \
/var/www/html/public \ /var/www/html/storage \
-type d -exec chmod 755 {} \; -type d -exec chmod 755 {} \;
# Clear and cache config in production # Clear and cache config in production
if [ "$APP_ENV" = "production" ]; then if [ "$APP_ENV" = "production" ]; then
gosu www-data php artisan optimize gosu www-data php artisan optimize
gosu www-data php artisan package:discover gosu www-data php artisan package:discover
gosu www-data php artisan migrate --force gosu www-data php artisan migrate --force
# If first IN run, it needs to be initialized # If first IN run, it needs to be initialized
echo "Checking initialization status..." echo "Checking initialization status..."
IN_INIT=$(php artisan tinker --execute='echo Schema::hasTable("accounts") && !App\Models\Account::all()->first();') IN_INIT=$(php artisan tinker --execute='echo Schema::hasTable("accounts") && !App\Models\Account::all()->first();')
echo "IN_INIT value: $IN_INIT" echo "IN_INIT value: $IN_INIT"
if [ "$IN_INIT" = "1" ]; then
echo "Running initialization scripts..."
docker_process_init_files /docker-entrypoint-init.d/*
fi
echo "Production setup completed"
echo "IN_INIT value: $IN_INIT"
if [ "$IN_INIT" = "1" ]; then
echo "Running initialization scripts..."
docker_process_init_files /docker-entrypoint-init.d/*
fi fi
echo "Production setup completed" echo "Starting supervisord..."
echo "IN_INIT value: $IN_INIT"
fi fi
exec "$@"
echo "Starting supervisord..."
# Start supervisord in the foreground
exec /usr/bin/supervisord -n -c /etc/supervisor/conf.d/supervisord.conf