diff --git a/backend/Dockerfile b/backend/Dockerfile index e58f4534..4c047139 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,6 +1,21 @@ -FROM docker.arvancloud.ir/php:8.5-fpm-alpine3.23 +FROM docker.arvancloud.ir/composer:latest AS builder + +WORKDIR /app + +COPY composer.json composer.lock ./ + +RUN composer install \ + --no-dev \ + --no-scripts \ + --no-autoloader \ + --prefer-dist + +COPY . . + +RUN composer dump-autoload --optimize --classmap-authoritative + +FROM php:8.5.3-fpm-alpine3.23 AS application -# Install common PHP extension dependencies RUN apk update && apk add --no-cache \ bash \ curl \ @@ -16,19 +31,11 @@ RUN apk update && apk add --no-cache \ && docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \ && docker-php-ext-install pdo_pgsql pdo_mysql gd zip -# Set the working directory WORKDIR /var/www/payment -COPY . . -RUN chmod -R 777 /var/www/payment/storage /var/www/payment/bootstrap/cache +COPY --from=builder /app /var/www/payment -# Install Composer -COPY --from=composer:latest /usr/bin/composer /usr/bin/composer -ENV COMPOSER_ALLOW_SUPERUSER=1 +RUN chown -R www-data:www-data /var/www/payment \ + && chmod -R 665 storage bootstrap/cache -# Default command -CMD composer install ;\ - php artisan key:generate ;\ - php artisan migrate ;\ - php artisan db:seed ;\ - php-fpm +CMD ["php-fpm"] diff --git a/backend/Dockerfile.production b/backend/Dockerfile.production deleted file mode 100644 index bfc9a2fe..00000000 --- a/backend/Dockerfile.production +++ /dev/null @@ -1,41 +0,0 @@ -FROM docker.arvancloud.ir/composer:latest AS builder - -WORKDIR /app - -COPY composer.json composer.lock ./ - -RUN composer install \ - --no-dev \ - --no-scripts \ - --no-autoloader \ - --prefer-dist - -COPY . . - -RUN composer dump-autoload --optimize --classmap-authoritative - -FROM docker.arvancloud.ir/php:8.5-fpm-alpine3.23 AS application - -RUN apk update && apk add --no-cache \ - bash \ - curl \ - libpng \ - libpng-dev \ - libjpeg-turbo-dev \ - freetype-dev \ - libwebp-dev \ - libxml2-dev \ - unzip \ - libzip-dev \ - libpq-dev \ - && docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \ - && docker-php-ext-install pdo_pgsql pdo_mysql gd zip - -WORKDIR /var/www/payment - -COPY --from=builder /app /var/www/payment - -RUN chown -R www-data:www-data /var/www/payment \ - && chmod -R 775 storage bootstrap/cache - -CMD ["php-fpm"] diff --git a/docker-compose.production.yml b/docker-compose.production.yml deleted file mode 100644 index a37a07f1..00000000 --- a/docker-compose.production.yml +++ /dev/null @@ -1,73 +0,0 @@ -services: - nginx: - image: docker.arvancloud.ir/nginx:stable-alpine3.23-perl - container_name: nginx - restart: unless-stopped - ports: - - "80:80" - volumes: - - ./nginx/payment.conf:/etc/nginx/conf.d/default.conf - - ${BACKEND_PATH}:/var/www/${PROJECT_NAME} - networks: - - payment - - redis: - image: docker.arvancloud.ir/redis:8.6.0-alpine3.23 - container_name: redis - restart: unless-stopped - tty: true - networks: - - payment - - postgres: - image: docker.arvancloud.ir/postgres:18.3-alpine3.23 - container_name: pgsql - restart: unless-stopped - ports: - - "8091:5432" - environment: - POSTGRES_DB: ${POSTGRES_DB} - POSTGRES_USER: ${POSTGRES_USER} - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} - volumes: - - payment-db:/var/lib/postgresql/data - networks: - - payment - healthcheck: - test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] - interval: 30s - timeout: 10s - retries: 3 - - backend: - build: - context: ${BACKEND_PATH} - dockerfile: Dockerfile.production - container_name: laravel - tty: true - restart: unless-stopped - ports: - - "80:80" - volumes: - - ${BACKEND_PATH}:/var/www/${PROJECT_NAME} - depends_on: - - postgres - networks: - - payment - logging: - driver: "syslog" - options: - syslog-address: "tcp://host.docker.internal:514" - tag: "laravel-backend" - syslog-facility: "daemon" - max-size: "10m" - mem_limit: 512M - cpus: 1 - -volumes: - payment-db: - driver: local - -networks: - payment: - driver: bridge \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index ba90b320..3feb97d6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ services: container_name: nginx restart: unless-stopped ports: - - "80:80" + - "8000:80" volumes: - ./nginx/payment.conf:/etc/nginx/conf.d/default.conf - ${BACKEND_PATH}:/var/www/${PROJECT_NAME} @@ -20,7 +20,7 @@ services: - payment postgres: - image: docker.arvancloud.ir/postgres:18.3-alpine3.23 + image: postgres:18.2-alpine3.23 container_name: pgsql restart: unless-stopped ports: @@ -29,6 +29,11 @@ services: POSTGRES_DB: ${POSTGRES_DB} POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + healthcheck: + test: [ "CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}" ] + interval: 30s + timeout: 10s + retries: 3 volumes: - payment-db:/var/lib/postgresql/data networks: @@ -49,6 +54,15 @@ services: - postgres networks: - payment +# logging: +# driver: "syslog" +# options: +# syslog-address: "tcp://host.docker.internal:514" +# tag: "laravel-backend" +# syslog-facility: "daemon" +# max-size: "10m" +# mem_limit: 512M +# cpus: 1 volumes: payment-db: