Refactor Docker setup: move Dockerfiles to respective directories and add supervisor configurations
Build - Docker Image - PROD / publish (push) Has been cancelled

This commit is contained in:
Jonatan Rek
2026-01-28 10:40:10 +01:00
parent 33f9ca082a
commit 189dc975bd
5 changed files with 116 additions and 3 deletions
+112
View File
@@ -0,0 +1,112 @@
# Use PHP with Apache as the base image
FROM php:8.4-apache
# Environment
ENV TZ="Europe/Prague" \
APACHE_DOCUMENT_ROOT="/var/www/html/public" \
PHP_INI_FILE="$PHP_INI_DIR/php.ini" \
PHP_OPCACHE_VALIDATE_TIMESTAMPS="1" \
PHP_OPCACHE_MAX_ACCELERATED_FILES="10000" \
PHP_OPCACHE_MEMORY_CONSUMPTION="192" \
PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10" \
COMPOSER_ALLOW_SUPERUSER=1
# Timezone
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# Install Additional System Dependencies
RUN rm -f /etc/apt/apt.conf.d/docker-clean
RUN --mount=type=cache,target=/var/cache/apt \
apt-get update && apt-get install -yqq --no-install-recommends \
git \
libpq-dev \
libzip-dev \
zip \
unzip \
nodejs \
npm \
cron \
nano \
default-mysql-client \
postgresql-client \
imagemagick \
libmagickwand-dev \
librsvg2-2 \
librsvg2-dev \
librsvg2-bin \
supervisor && \
git clone https://github.com/Imagick/imagick --depth 1 /tmp/imagick && \
cd /tmp/imagick && \
phpize && \
./configure --with-rsvg && \
ldconfig && \
make && \
make install && \
apt-get autoremove && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
npm config set cache /tmp --global && \
mkdir -p /var/log/supervisor
# Enable Apache mod_rewrite for URL rewriting
RUN a2enmod rewrite
# Install PHP extensions
RUN docker-php-ext-install \
pdo_mysql \
pgsql \
pdo_pgsql \
zip \
opcache \
pcntl \
sockets\
bcmath \
soap \
gd
RUN docker-php-ext-enable imagick
# PHP
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_FILE" && \
sed -i "s|memory_limit = 128M|memory_limit = 256M |g" "$PHP_INI_FILE" && \
sed -i "s|upload_max_filesize = 2M|upload_max_filesize = 100M |g" "$PHP_INI_FILE" && \
sed -i "s|post_max_size = 8M|post_max_size = 100M |g" "$PHP_INI_FILE" && \
printf '[Date]\ndate.timezone="%s"\n', $TZ > "$PHP_INI_DIR/conf.d/tzone.ini"
#OPCACHE
RUN echo '\n\
[opcache]\n\
opcache.enable=1\n\
opcache.revalidate_freq=0\n\
opcache.validate_timestamps=${PHP_OPCACHE_VALIDATE_TIMESTAMPS}\n\
opcache.max_accelerated_files=${PHP_OPCACHE_MAX_ACCELERATED_FILES}\n\
opcache.memory_consumption=${PHP_OPCACHE_MEMORY_CONSUMPTION}\n\
opcache.max_wasted_percentage=${PHP_OPCACHE_MAX_WASTED_PERCENTAGE}\n\
opcache.interned_strings_buffer=16\n\
opcache.fast_shutdown=1' >> "$PHP_INI_DIR/conf.d/opcache.ini"
#SUPERVISORD
RUN mkdir -p /var/log/supervisor
COPY ./supervisor/supervisord.conf /etc/supervisor/supervisord.conf
COPY ./supervisor/conf.d/laravel-queues.conf /etc/supervisor/conf.d/laravel-queues.conf
# Setup Crone
RUN mkdir -p /var/log/cron && \
echo "* * * * * www-data cd /var/www/html && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1" >> /etc/crontab
# Install composer # bun
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Configure Apache DocumentRoot to point to Laravel's public directory
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf && \
sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf && \
sed -i 's/^exec /printenv > \/etc\/environment\n\nexec /' /usr/local/bin/apache2-foreground && \
sed -i 's/^exec /service cron start\n\nexec /' /usr/local/bin/apache2-foreground
#Cleaning
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/cache/apt/* && \
rm -rf /usr/share/man/* && \
rm -rf /usr/share/doc/* && \
rm -rf /tmp/*
@@ -0,0 +1,20 @@
[program:queue-default]
command=/usr/local/bin/php /var/www/html/artisan queue:work --queue=default,importstatistics
user=www-data
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/queue-default.log
[program:queue-statistics]
command=/usr/local/bin/php /var/www/html/artisan queue:work --queue=statistics
user=www-data
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/queue-statistics.log
[program:queue-detections]
command=/usr/local/bin/php /var/www/html/artisan queue:work --queue=detections
user=www-data
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/queue-detections.log
+6
View File
@@ -0,0 +1,6 @@
[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log
[include]
files = /etc/supervisor/conf.d/*.conf