Refactor Docker setup for Laravel 5.0 compatibility and optimize deployment process
- Updated Dockerfile configurations for various environments (alpine, basic, cloudrun, minimal, simple, test) to ensure compatibility with Laravel 5.0 and PHP 5.6. - Added PHP compatibility documentation outlining mcrypt requirements and upgrade paths. - Created cloudbuild.yaml for Google Cloud Build integration to streamline deployment to Cloud Run. - Introduced docker-compose.local.yml for local development with MySQL and Redis services. - Enhanced rebuild.sh script for easier local development and migration handling. - Updated Laravel Blade views to correct asset paths. - Added start-local.sh script for quick local setup and service management.
This commit is contained in:
132
Dockerfile.cloudrun
Normal file
132
Dockerfile.cloudrun
Normal file
@@ -0,0 +1,132 @@
|
||||
# Dockerfile optimized for Google Cloud Run
|
||||
# Use PHP 5.6 with Apache (matches Laravel 5.0 requirements perfectly)
|
||||
FROM php:5.6-apache
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /var/www/html
|
||||
|
||||
# Install system dependencies and PHP extensions required for Laravel
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libpng-dev \
|
||||
libjpeg62-turbo-dev \
|
||||
libfreetype6-dev \
|
||||
libmcrypt-dev \
|
||||
zlib1g-dev \
|
||||
zip \
|
||||
unzip \
|
||||
git \
|
||||
curl \
|
||||
libxml2-dev \
|
||||
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
|
||||
&& docker-php-ext-install \
|
||||
pdo \
|
||||
pdo_mysql \
|
||||
mbstring \
|
||||
zip \
|
||||
gd \
|
||||
xml \
|
||||
mcrypt \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Composer
|
||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||
|
||||
# Enable Apache modules and configure
|
||||
RUN a2enmod rewrite headers
|
||||
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
|
||||
|
||||
# Configure Apache document root for Laravel
|
||||
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
|
||||
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
|
||||
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
|
||||
|
||||
# Copy Apache virtual host configuration
|
||||
COPY <<EOF /etc/apache2/sites-available/000-default.conf
|
||||
<VirtualHost *:80>
|
||||
ServerAdmin webmaster@localhost
|
||||
DocumentRoot /var/www/html/public
|
||||
|
||||
<Directory /var/www/html/public>
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
# Logging
|
||||
ErrorLog \${APACHE_LOG_DIR}/error.log
|
||||
CustomLog \${APACHE_LOG_DIR}/access.log combined
|
||||
|
||||
# Security headers
|
||||
Header always set X-Content-Type-Options nosniff
|
||||
Header always set X-Frame-Options DENY
|
||||
Header always set X-XSS-Protection "1; mode=block"
|
||||
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
|
||||
Header always set Referrer-Policy "strict-origin-when-cross-origin"
|
||||
</VirtualHost>
|
||||
EOF
|
||||
|
||||
# Copy application files
|
||||
COPY . /var/www/html/
|
||||
|
||||
# Fix Git ownership issue for the repository
|
||||
RUN git config --global --add safe.directory /var/www/html || true
|
||||
|
||||
# Install PHP dependencies
|
||||
RUN composer install --no-dev --optimize-autoloader --no-interaction
|
||||
|
||||
# Set proper permissions for Laravel
|
||||
RUN chown -R www-data:www-data /var/www/html \
|
||||
&& chmod -R 755 /var/www/html \
|
||||
&& chmod -R 775 /var/www/html/storage \
|
||||
&& chmod -R 775 /var/www/html/bootstrap/cache
|
||||
|
||||
# Create .env file from .env.example if it doesn't exist
|
||||
RUN if [ ! -f /var/www/html/.env ]; then \
|
||||
cp /var/www/html/.env.example /var/www/html/.env; \
|
||||
fi
|
||||
|
||||
# Switch to www-data user for Laravel commands to avoid ownership issues
|
||||
USER www-data
|
||||
|
||||
# Generate application key (will be overridden by environment variables in Cloud Run)
|
||||
RUN php artisan key:generate || true
|
||||
|
||||
# Clear and cache configuration for production
|
||||
RUN php artisan config:clear || true \
|
||||
&& php artisan route:clear || true \
|
||||
&& php artisan view:clear || true
|
||||
|
||||
# Switch back to root for the remaining setup
|
||||
USER root
|
||||
|
||||
# Create startup script
|
||||
COPY <<EOF /usr/local/bin/start.sh
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Fix Git ownership issue
|
||||
git config --global --add safe.directory /var/www/html || true
|
||||
|
||||
# Wait for database to be ready (if using Cloud SQL)
|
||||
echo "Starting Laravel application..."
|
||||
|
||||
# Run Laravel optimizations
|
||||
php artisan config:cache || true
|
||||
php artisan route:cache || true
|
||||
php artisan view:cache || true
|
||||
|
||||
# Start Apache in foreground
|
||||
exec apache2-foreground
|
||||
EOF
|
||||
|
||||
RUN chmod +x /usr/local/bin/start.sh
|
||||
|
||||
# Expose port 80 (Cloud Run will map this to 8080)
|
||||
EXPOSE 80
|
||||
|
||||
# Health check for Cloud Run
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
||||
CMD curl -f http://localhost/ || exit 1
|
||||
|
||||
# Use the startup script
|
||||
CMD ["/usr/local/bin/start.sh"]
|
||||
Reference in New Issue
Block a user