From 7fff56f59211903c3a3c1c4dc73f1097a8767bad Mon Sep 17 00:00:00 2001 From: Juan Felipe Zapata Moreno Date: Wed, 10 Sep 2025 11:55:22 -0600 Subject: [PATCH] Dockerfile desarrollo --- Docker/nginx/nginx.conf | 56 ++++++++++++++------------------- docker-compose-dev.yml | 69 +++++++++++++++++++++++++++++++++++++++++ dockerfile | 10 +----- dockerfile.dev | 33 ++++++++++++++++++++ 4 files changed, 126 insertions(+), 42 deletions(-) create mode 100644 docker-compose-dev.yml create mode 100644 dockerfile.dev diff --git a/Docker/nginx/nginx.conf b/Docker/nginx/nginx.conf index 1d1ebc5..482d69f 100644 --- a/Docker/nginx/nginx.conf +++ b/Docker/nginx/nginx.conf @@ -8,15 +8,7 @@ server { error_log /var/log/nginx/error.log; access_log /var/log/nginx/access.log; - # Gzip compression - gzip on; - gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; - - # Security headers - add_header X-Frame-Options "SAMEORIGIN"; - add_header X-Content-Type-Options "nosniff"; - - # Handle Laravel routes + # Handle Laravel routes (Front Controller) location / { try_files $uri $uri/ /index.php?$query_string; } @@ -25,22 +17,28 @@ server { location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_pass holos-backend:9000; # Nombre del servicio en docker-compose + fastcgi_pass holos-backend:9000; fastcgi_index index.php; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param PATH_INFO $fastcgi_path_info; + + # Timeouts importantes para evitar errores 500 + fastcgi_read_timeout 300; + fastcgi_connect_timeout 300; + fastcgi_send_timeout 300; + + # Carga los parámetros por defecto include fastcgi_params; - # Timeouts para requests largos - fastcgi_read_timeout 300; - fastcgi_send_timeout 300; - } - - # Handle static files with caching - location ~* \.(jpg|jpeg|png|gif|ico|css|js|pdf|txt|tar|woff|woff2|ttf|svg|eot)$ { - expires 1y; - add_header Cache-Control "public, immutable"; - try_files $uri =404; + # Parámetros críticos para Laravel + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + fastcgi_param REQUEST_URI $request_uri; + fastcgi_param QUERY_STRING $query_string; + fastcgi_param REQUEST_METHOD $request_method; + fastcgi_param CONTENT_TYPE $content_type; + fastcgi_param CONTENT_LENGTH $content_length; + fastcgi_param HTTP_HOST $http_host; + fastcgi_param HTTPS $https if_not_empty; + fastcgi_param HTTP_PROXY ""; } # Handle storage files (Laravel storage link) @@ -49,16 +47,8 @@ server { try_files $uri =404; } - # Handle profile images - location /profile { - alias /var/www/holos.backend/storage/app/profile; - try_files $uri =404; + # Denegar acceso a archivos ocultos como .htaccess + location ~ /\.ht { + deny all; } - - # Handle images - location /images { - alias /var/www/holos.backend/storage/app/images; - try_files $uri =404; - } - } diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml new file mode 100644 index 0000000..28d9354 --- /dev/null +++ b/docker-compose-dev.yml @@ -0,0 +1,69 @@ +services: + holos-backend: + build: + context: . + dockerfile: dockerfile.dev + working_dir: /var/www/holos.backend + volumes: + - ./:/var/www/holos.backend + - ./storage:/var/www/holos.backend/storage + networks: + - holos-network + depends_on: + - mysql + - redis + + nginx: + image: nginx:alpine + ports: + - "8080:80" + volumes: + - ./public:/var/www/holos.backend/public + - ./Docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf + networks: + - holos-network + depends_on: + - holos-backend + + mysql: + image: mysql:8.0 + environment: + MYSQL_DATABASE: ${DB_DATABASE} + MYSQL_ROOT_PASSWORD: ${DB_PASSWORD} + MYSQL_PASSWORD: ${DB_PASSWORD} + MYSQL_USER: ${DB_USERNAME} + ports: + - ${DB_PORT}:${DB_PORT} + volumes: + - mysql_data:/var/lib/mysql + networks: + - holos-network + + phpmyadmin: + image: phpmyadmin/phpmyadmin + environment: + PMA_HOST: mysql + PMA_PORT: 3306 + ports: + - '${PMA_PORT}:80' + depends_on: + - mysql + networks: + - holos-network + + redis: + image: redis:alpine + volumes: + - redis_data:/data + networks: + - holos-network + +volumes: + mysql_data: + driver: local + redis_data: + driver: local + +networks: + holos-network: + driver: bridge diff --git a/dockerfile b/dockerfile index e5dfa00..914e48f 100644 --- a/dockerfile +++ b/dockerfile @@ -12,8 +12,7 @@ RUN apt-get update && apt-get install -y\ libxml2-dev \ zip \ unzip \ - libzip-dev \ - && curl -fsSL https://deb.nodesource.com/setup_18.x | bash - + libzip-dev RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip @@ -25,13 +24,6 @@ RUN composer install --no-dev --no-scripts --optimize-autoloader --no-interactio COPY . . -RUN php artisan config:cache \ - && php artisan route:cache - -RUN chown -R www-data:www-data /var/www/holos.backend \ - && chmod -R 755 /var/www/holos.backend/storage \ - && chmod -R 755 /var/www/holos.backend/bootstrap/cache - EXPOSE 9000 CMD ["php-fpm"] diff --git a/dockerfile.dev b/dockerfile.dev new file mode 100644 index 0000000..6bd38e6 --- /dev/null +++ b/dockerfile.dev @@ -0,0 +1,33 @@ +FROM php:8.3-fpm + +RUN mkdir -p /var/www/holos.backend + +WORKDIR /var/www/holos.backend + +RUN apt-get update && apt-get install -y\ + git \ + curl \ + libpng-dev \ + libonig-dev \ + libxml2-dev \ + zip \ + unzip \ + libzip-dev\ + nano + +RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip + +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +COPY composer.json composer.lock ./ + +RUN composer install --optimize-autoloader --no-interaction --no-scripts + +COPY . . + +# Ejecutar los scripts de Laravel después de copiar el código +RUN composer run-script post-autoload-dump + +EXPOSE 9000 + +CMD ["php-fpm"]