diff --git a/docker/Dockerfile b/docker/Dockerfile index eed5510..2cc673a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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 \ diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 173e35d..1b0e27d 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -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 \ No newline at end of file + driver: local diff --git a/docker/nginx.conf b/docker/nginx.conf index 3877706..b462ad6 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -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; diff --git a/docker/start-app.sh b/docker/start-app.sh new file mode 100644 index 0000000..d0db65d --- /dev/null +++ b/docker/start-app.sh @@ -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 \ No newline at end of file diff --git a/docker/supervisord.conf b/docker/supervisord.conf new file mode 100644 index 0000000..8a7a5b6 --- /dev/null +++ b/docker/supervisord.conf @@ -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 \ No newline at end of file