From 8154d66daf0c12b1894165b1f1f18902bc8bb248 Mon Sep 17 00:00:00 2001
From: "Alex. Plokhikh" <a.plohih@iqdev.digital>
Date: Fri, 26 Apr 2024 17:09:17 +0500
Subject: [PATCH] STA-931|update docker configuration

---
 .env.example                       |  0
 app/.gitignore                     |  1 +
 docker-compose.yml                 | 46 ++++++++++++++++++++++++++++++
 docker/App.Dockerfile              | 15 ++++++++++
 docker/App.Dockerfile.dockerignore |  0
 nginx/default.conf                 | 25 ++++++++++++++++
 6 files changed, 87 insertions(+)
 create mode 100644 .env.example
 create mode 100644 docker-compose.yml
 create mode 100644 docker/App.Dockerfile
 create mode 100644 docker/App.Dockerfile.dockerignore
 create mode 100644 nginx/default.conf

diff --git a/.env.example b/.env.example
new file mode 100644
index 0000000..e69de29
diff --git a/app/.gitignore b/app/.gitignore
index a1ade67..50be080 100644
--- a/app/.gitignore
+++ b/app/.gitignore
@@ -8,6 +8,7 @@
 /public/bundles/
 /var/
 /vendor/
+composer.lock
 ###< symfony/framework-bundle ###
 
 ###> phpunit/phpunit ###
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..f4f1144
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,46 @@
+version: '3.1'
+
+services:
+  db:
+    image: postgres:16.2
+    container_name: ${APP_NAME}-db
+    environment:
+      POSTGRES_PASSWORD: ${DB_PASSWORD}
+      POSTGRES_USER: ${DB_USER}
+      POSTGRES_DB: ${DB_NAME}
+    networks:
+      - app
+    ports:
+      - '5432:5432'
+
+  nginx:
+    image: nginx:stable-alpine
+    container_name: ${APP_NAME}-nginx
+    ports:
+      - '80:80'
+    volumes:
+      - ./app:/var/www/project
+      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
+    networks:
+      - app
+    links:
+      - app
+    depends_on:
+      - app
+
+  app:
+    build:
+      context: .
+      dockerfile: docker/App.Dockerfile
+    ports:
+      - '9000:9000'
+    volumes:
+      - ./app:/var/www/project
+    networks:
+      - app
+    depends_on:
+      - db
+
+networks:
+  app:
+    driver: bridge
\ No newline at end of file
diff --git a/docker/App.Dockerfile b/docker/App.Dockerfile
new file mode 100644
index 0000000..76b3fbc
--- /dev/null
+++ b/docker/App.Dockerfile
@@ -0,0 +1,15 @@
+FROM php:fpm-alpine
+
+WORKDIR app
+
+COPY app .
+
+RUN apk update && \
+    apk add libpq-dev && \
+    docker-php-ext-install pdo pdo_pgsql pgsql
+
+ENV COMPOSER_ALLOW_SUPERUSER=1
+RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
+RUN composer install
+
+CMD ["php-fpm"]
\ No newline at end of file
diff --git a/docker/App.Dockerfile.dockerignore b/docker/App.Dockerfile.dockerignore
new file mode 100644
index 0000000..e69de29
diff --git a/nginx/default.conf b/nginx/default.conf
new file mode 100644
index 0000000..4145474
--- /dev/null
+++ b/nginx/default.conf
@@ -0,0 +1,25 @@
+server {
+    listen 80;
+    index index.php;
+    server_name localhost;
+    root /var/www/project/public;
+    location / {
+        try_files $uri /index.php$is_args$args;
+    }
+location ~ ^/index\.php(/|$) {
+        fastcgi_pass php82-service:9000;
+        fastcgi_split_path_info ^(.+\.php)(/.*)$;
+        include fastcgi_params;
+        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
+        fastcgi_param DOCUMENT_ROOT $realpath_root;
+        fastcgi_buffer_size 128k;
+        fastcgi_buffers 4 256k;
+        fastcgi_busy_buffers_size 256k;
+        internal;
+    }
+location ~ \.php$ {
+        return 404;
+    }
+error_log /var/log/nginx/project_error.log;
+    access_log /var/log/nginx/project_access.log;
+}
\ No newline at end of file
-- 
GitLab