Add Docker and Nginx configuration for Cloud Run deployment
This commit is contained in:
72
cloudrun/Dockerfile.cloudrun
Normal file
72
cloudrun/Dockerfile.cloudrun
Normal file
@@ -0,0 +1,72 @@
|
||||
# Combined image for Cloud Run: nginx + php-fpm (PHP 5.6) for legacy Laravel 5
|
||||
# NOTE: PHP 5.6 is EOL; use only for legacy maintenance. Consider upgrading.
|
||||
|
||||
FROM php:5.6-fpm
|
||||
|
||||
# Set build args/env
|
||||
ARG APP_ENV=production
|
||||
ENV APP_ENV=${APP_ENV} \
|
||||
APP_DEBUG=false \
|
||||
OPCACHE_VALIDATE_TIMESTAMPS=0 \
|
||||
COMPOSER_ALLOW_SUPERUSER=1 \
|
||||
PORT=8080 \
|
||||
PATH="/var/www/artisan:$PATH"
|
||||
|
||||
WORKDIR /var/www
|
||||
|
||||
# Install system deps (Debian variant easier than alpine for mixed services)
|
||||
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
||||
git curl unzip zip supervisor nginx \
|
||||
libmcrypt4 libmcrypt-dev \
|
||||
libpng-dev libjpeg62-turbo-dev libfreetype6-dev libzip-dev zlib1g-dev \
|
||||
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
|
||||
&& docker-php-ext-install gd mcrypt mbstring pdo pdo_mysql zip opcache \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Composer (v1)
|
||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
|
||||
&& composer self-update --1
|
||||
|
||||
# Copy composer files & install deps first (cache layer)
|
||||
COPY composer.* ./
|
||||
RUN composer config platform.php 5.6.40 \
|
||||
&& composer install --no-dev --no-scripts --no-autoloader --prefer-dist
|
||||
|
||||
# Copy application code
|
||||
COPY . .
|
||||
RUN composer dump-autoload --optimize --no-dev --classmap-authoritative || true
|
||||
|
||||
# Nginx config
|
||||
COPY cloudrun/nginx.conf /etc/nginx/nginx.conf
|
||||
|
||||
# Supervisord config
|
||||
COPY cloudrun/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||
|
||||
# Remove default nginx site configs if present
|
||||
RUN rm -f /etc/nginx/sites-enabled/default /etc/nginx/conf.d/default.conf || true
|
||||
|
||||
# Create runtime dirs
|
||||
RUN mkdir -p /run/php /var/log/supervisor /var/www/storage /var/www/bootstrap/cache \
|
||||
&& chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache
|
||||
|
||||
# PHP production ini tweaks
|
||||
RUN { \
|
||||
echo "opcache.enable=1"; \
|
||||
echo "opcache.memory_consumption=128"; \
|
||||
echo "opcache.interned_strings_buffer=8"; \
|
||||
echo "opcache.max_accelerated_files=4000"; \
|
||||
echo "opcache.revalidate_freq=60"; \
|
||||
echo "opcache.fast_shutdown=1"; \
|
||||
echo "date.timezone=UTC"; \
|
||||
} > /usr/local/etc/php/conf.d/zz-custom.ini
|
||||
|
||||
# Generate app key if missing (non-fatal if artisan fails early)
|
||||
RUN php artisan key:generate || true
|
||||
|
||||
# Cloud Run listens on $PORT
|
||||
EXPOSE 8080
|
||||
|
||||
# Health check path suggestion: /healthz (configure in Cloud Run if desired)
|
||||
|
||||
# Start supervisor (manages php-fpm + nginx)
|
||||
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
|
||||
42
cloudrun/nginx.conf
Normal file
42
cloudrun/nginx.conf
Normal file
@@ -0,0 +1,42 @@
|
||||
user nginx;
|
||||
worker_processes auto;
|
||||
error_log /dev/stderr warn;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
events { worker_connections 1024; }
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
access_log /dev/stdout main;
|
||||
sendfile on;
|
||||
keepalive_timeout 65;
|
||||
server_tokens off;
|
||||
|
||||
server {
|
||||
listen 8080 default_server;
|
||||
listen [::]:8080 default_server;
|
||||
root /var/www/public;
|
||||
index index.php index.html;
|
||||
|
||||
location /healthz { return 200 'ok'; add_header Content-Type text/plain; }
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php?$query_string;
|
||||
}
|
||||
|
||||
location ~ \.php$ {
|
||||
include fastcgi_params;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
fastcgi_pass 127.0.0.1:9000; # php-fpm
|
||||
fastcgi_index index.php;
|
||||
fastcgi_buffers 16 16k;
|
||||
fastcgi_buffer_size 32k;
|
||||
}
|
||||
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
|
||||
expires 30d;
|
||||
access_log off;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
cloudrun/supervisord.conf
Normal file
24
cloudrun/supervisord.conf
Normal file
@@ -0,0 +1,24 @@
|
||||
[supervisord]
|
||||
nodaemon=true
|
||||
logfile=/dev/stdout
|
||||
logfile_maxbytes=0
|
||||
|
||||
[program:php-fpm]
|
||||
command=/usr/sbin/php-fpm5.6 -F
|
||||
priority=10
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
stderr_logfile=/dev/stderr
|
||||
stderr_logfile_maxbytes=0
|
||||
|
||||
[program:nginx]
|
||||
command=/usr/sbin/nginx -g 'daemon off;'
|
||||
priority=20
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
stderr_logfile=/dev/stderr
|
||||
stderr_logfile_maxbytes=0
|
||||
Reference in New Issue
Block a user