From 5c96b6b72e3dc5e05041ea8974918304e47bd260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Cmit=20Tun=C3=A7?= Date: Mon, 20 Jan 2025 22:10:47 +0300 Subject: [PATCH] Update Docker configuration and Dockerfile for Laravel application - Changed the Docker image for the app service to 'truncgil-finance-app' and updated the container name accordingly. - Modified the web service to use 'truncgil-finance-web' and changed the port mapping to 8081. - Upgraded the database image to MySQL 8.0 and updated the container name to 'truncgil-finance-db', adding a restart policy. - Added environment variables for timezone and application settings in the app service. - Updated the Dockerfile to use PHP 8.2, added necessary dependencies, and configured cron jobs for Laravel tasks. - Enhanced file permission settings for the application directory to improve security and functionality. These changes improve the overall configuration and performance of the Laravel application within the Docker environment. --- docker-compose.yml | 22 +++++++----- dockerfile | 86 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 83 insertions(+), 25 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index c9102f2..c3536dc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,24 @@ -version: '3.8' - services: app: build: context: . dockerfile: Dockerfile - image: laravel-app - container_name: laravel-app + image: truncgil-finance-app + container_name: truncgil-finance-app volumes: - .:/var/www networks: - laravel-network + environment: + - TZ=Europe/Istanbul + - APP_ENV=production + - APP_DEBUG=false web: image: nginx:alpine - container_name: nginx + container_name: truncgil-finance-web ports: - - "80:80" + - "8081:80" volumes: - .:/var/www - ./nginx/default.conf:/etc/nginx/conf.d/default.conf @@ -24,18 +26,20 @@ services: - laravel-network db: - image: mysql:5.7 - container_name: mysql + image: mysql:8.0 + container_name: truncgil-finance-db + restart: unless-stopped environment: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: truncgil_finance MYSQL_USER: truncgil_finance MYSQL_PASSWORD: "QWEFaca123++" - MYSQL_PORT: 3307:3306 volumes: - db_data:/var/lib/mysql networks: - laravel-network + ports: + - "3307:3306" networks: laravel-network: diff --git a/dockerfile b/dockerfile index a597f42..0a53a18 100644 --- a/dockerfile +++ b/dockerfile @@ -1,26 +1,80 @@ -# ... mevcut kod ... -FROM php:8.1-fpm +# Laravel için PHP 8.2 resmi imajını kullanıyoruz +FROM php:8.2-fpm -# Gerekli uzantıları yükleyin -RUN docker-php-ext-install pdo pdo_mysql +ENV TZ=Europe/Istanbul +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone -# Composer'ı yükleyin -COPY --from=composer:latest /usr/bin/composer /usr/bin/composer -# Çalışma dizinini ayarlayın +# Çalışma dizinini belirleyelim WORKDIR /var/www -# Uygulama dosyalarını kopyalayın +# Gerekli bağımlılıkları yükleyelim +RUN apt-get update && apt-get install -y \ + git \ + unzip \ + curl \ + libpng-dev \ + libonig-dev \ + libxml2-dev \ + zip \ + cron \ + && docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd \ + && echo "* * * * * cd /var/www && php artisan schedule:run >> /dev/null 2>&1" >> /etc/cron.d/laravel-cron \ + && chmod 0644 /etc/cron.d/laravel-cron \ + && crontab /etc/cron.d/laravel-cron \ + && service cron start + +# Composer'ı yükleyelim +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +# Laravel proje dosyalarını kopyalayalım COPY . . -# Bağımlılıkları yükleyin -RUN composer install +# Gerekli dizinleri oluşturma +RUN mkdir -p /var/www/storage/app/private/scribe -# Dosya izinlerini ayarlama -RUN chown -R www-data:www-data /var/www && \ - chmod -R 755 /var/www && \ +# Start of Selection +RUN set -x && \ + echo "Dosya izinleri ayarlanıyor..." && \ + chown -R www-data:www-data /var/www && \ + echo "chown komutu tamamlandı" && \ + find /var/www -type d -exec chmod 775 {} \; && \ + echo "Dizin izinleri ayarlandı" && \ + find /var/www -type f -exec chmod 664 {} \; && \ + echo "Dosya izinleri ayarlandı" && \ chmod -R 775 /var/www/storage && \ - chmod -R 775 /var/www/storage/app/private && \ - chmod -R 775 /var/www/storage/app/private/scribe + echo "Storage izinleri ayarlandı" && \ + chmod -R 775 /var/www/bootstrap/cache && \ + echo "Cache izinleri ayarlandı" && \ + chmod -R 775 /var/www/storage/framework/views && \ + echo "Views izinleri ayarlandı" && \ + chmod -R 775 /var/www/public && \ + echo "Public dizin izinleri ayarlandı" -# ... mevcut kod ... \ No newline at end of file +# Laravel uygulamasını başlatma ve loglama +RUN set -x && \ + echo "Laravel kurulum komutları başlatılıyor..." && \ + php artisan migrate && \ + echo "Migrasyon tamamlandı" && \ + php artisan key:generate && \ + echo "Uygulama anahtarı oluşturuldu" && \ + php artisan config:cache && \ + echo "Konfigürasyon önbelleğe alındı" && \ + php artisan route:cache && \ + echo "Rotalar önbelleğe alındı" && \ + php artisan view:cache && \ + echo "Görünümler önbelleğe alındı" && \ + php artisan storage:link && \ + echo "Storage sembolik bağlantısı oluşturuldu" && \ + php artisan scribe:generate && \ + echo "API dokümantasyonu oluşturuldu" && \ + echo "Laravel uygulaması başarıyla başlatıldı." + + +# Apache veya Nginx kullanılacaksa, burada ayarları yapabiliriz (Opsiyonel) + +# Container başlangıcında çalışacak script +COPY docker-entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/docker-entrypoint.sh + +ENTRYPOINT ["docker-entrypoint.sh"]