Dockerfile:
Код: Выделить всё
FROM php:8.2-fpm
# Set env vars
ENV NODE_VERSION=20
RUN apt-get update && apt-get install -y \
zip \
curl \
unzip \
libonig-dev \
libzip-dev \
libpng-dev \
nginx \
git && \
docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
COPY ./nginx.conf /etc/nginx/sites-enabled/default
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
EXPOSE 8080
# Copy the application code
COPY . /var/www/html
# Set the working directory
WORKDIR /var/www/html
# Add vendor binaries to PATH
ENV PATH=/var/www/html/vendor/bin:$PATH
COPY composer.json composer.lock ./
# Install project dependencies
RUN composer install
# Install Node.js and npm
RUN curl -sL https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash - && apt-get install -y nodejs
# Set permissions
RUN chown -R www-data:www-data ./
RUN chgrp -R www-data storage bootstrap/cache && \
chmod -R ug+rwx storage bootstrap/cache
RUN npm install
# Build and version Vite assets for production
RUN npm run build
# Make the file executable, or use "chmod 777" instead of "chmod +x"
RUN chmod +x /var/www/html/db-migration.sh
RUN php artisan optimize:clear
RUN php artisan route:clear
RUN php artisan route:cache
RUN php artisan config:clear
RUN php artisan config:cache
RUN php artisan view:clear
RUN php artisan view:cache
# This will run the shell file at the time when container is up-and-running successfully (and NOT at the BUILD time)
ENTRYPOINT ["/var/www/html/db-migration.sh"]
Код: Выделить всё
#!/bin/bash
php artisan migrate --force
php artisan optimize
php-fpm -D && nginx -g "daemon off;"
Код: Выделить всё
server {
listen 8080;
index index.php index.html;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
# the Cloud run service url
server_name dev-xxxxxxxxxx.region-value.run.app;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
# this should be the path of your public folder in laravel which from our dockerfile
root /var/www/html/public;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_buffering off;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
Код: Выделить всё
> GET 200 9.1 KB 726 ms Chrome 131 https://dev-xxxxxxxxxx.us-central1.run.app/
> 169.xxx.xxx.xxx - - [17/Dec/2024:03:05:39 +0000] "GET / HTTP/1.1" 200 9116 "https://console.cloud.google.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7))"
> 127.0.0.1 - 17/Dec/2024:03:05:39 +0000 "GET /index.php" 200
Буду благодарен за любую помощь!
Подробнее здесь: https://stackoverflow.com/questions/792 ... d-by-cloud