Consolidate containers

This commit is contained in:
myrmidex 2025-07-15 20:36:49 +02:00
parent 9ef05f9f57
commit e82dfb03fc
5 changed files with 50 additions and 33 deletions

View file

@ -32,7 +32,9 @@ RUN apk add --no-cache \
zip \
unzip \
oniguruma-dev \
mysql-client
mysql-client \
nginx \
supervisor
# Install PHP extensions
RUN docker-php-ext-install \
@ -58,22 +60,18 @@ RUN composer install --no-dev --optimize-autoloader --no-interaction
# Copy built frontend assets from builder stage
COPY --from=frontend-builder /app/public/build/ ./public/build/
# Copy nginx and supervisor configurations
COPY docker/nginx.conf /etc/nginx/http.d/default.conf
COPY docker/supervisord.conf /etc/supervisord.conf
COPY docker/start-app.sh /usr/local/bin/start-app
# Set proper permissions
RUN chown -R www-data:www-data storage bootstrap/cache public/build \
&& chmod -R 755 storage bootstrap/cache
# Create a startup script
RUN echo '#!/bin/sh' > /usr/local/bin/start-app \
&& echo 'cp -r /var/www/html/public/. /var/www/html/public_shared/ 2>/dev/null || true' >> /usr/local/bin/start-app \
&& echo 'php artisan config:cache' >> /usr/local/bin/start-app \
&& echo 'php artisan route:cache' >> /usr/local/bin/start-app \
&& echo 'php artisan view:cache' >> /usr/local/bin/start-app \
&& echo 'php artisan migrate --force' >> /usr/local/bin/start-app \
&& echo 'php-fpm' >> /usr/local/bin/start-app \
&& chmod -R 755 storage bootstrap/cache \
&& chmod +x /usr/local/bin/start-app
# Expose port 9000 for PHP-FPM
EXPOSE 9000
# Expose port 80 for nginx
EXPOSE 80
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \

View file

@ -2,10 +2,7 @@ version: '3.8'
services:
app:
image: codeberg.org/lvl0/incr:0.1.0
# build:
# context: ../
# dockerfile: docker/Dockerfile
image: codeberg.org/lvl0/incr:0.1.14
container_name: incr-app
restart: unless-stopped
working_dir: /var/www/html
@ -21,6 +18,8 @@ services:
volumes:
- ../storage:/var/www/html/storage
- ../public:/var/www/html/public
ports:
- "80:80"
depends_on:
- db
networks:
@ -42,24 +41,10 @@ services:
networks:
- incr-network
nginx:
image: nginx:alpine
container_name: incr-nginx
restart: unless-stopped
ports:
- "80:80"
volumes:
- ../public:/var/www/html/public:ro
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- app
networks:
- incr-network
networks:
incr-network:
driver: bridge
volumes:
db_data:
driver: local
driver: local

View file

@ -9,7 +9,7 @@ server {
}
location ~ \.php$ {
fastcgi_pass app:9000;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;

13
docker/start-app.sh Normal file
View file

@ -0,0 +1,13 @@
#!/bin/sh
# Copy public files to shared volume if needed
cp -r /var/www/html/public/. /var/www/html/public_shared/ 2>/dev/null || true
# Laravel optimizations
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan migrate --force
# Start supervisor to manage nginx and php-fpm
supervisord -c /etc/supervisord.conf

21
docker/supervisord.conf Normal file
View file

@ -0,0 +1,21 @@
[supervisord]
nodaemon=true
user=root
[program:nginx]
command=nginx -g "daemon off;"
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:php-fpm]
command=php-fpm --nodaemonize
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0