Repository: Rmgs123/Symfony-Project
Pull request #1: Add Docker configuration
Author: login: Rmgs123
Created: 2025-03-06T11:26:12Z | Merged: 2025-03-28T05:28:29Z

**Technologies Used:**

_Docker & Docker Compose:_ For containerization and orchestration of services.
_PHP 8.2-fpm:_ Container for executing PHP code based on the official PHP image.
_Nginx:_ Web server that handles incoming HTTP requests and forwards them to PHP-FPM.
_PostgreSQL:_ Database service for the project.
_Symfony Framework & Doctrine ORM:_ The base Symfony project integrated with Doctrine ORM for database interactions.


**Project Structure Changes:**

_/symfony_project_

├── docker-compose.yml         # Describes the services: php, nginx, db, including a volume for persistent database storage.

├── Dockerfile-php          # Dockerfile for building the PHP container with necessary extensions and Composer.

├── docker
│   └── nginx
│       └── default.conf        # Nginx configuration file for routing requests to Symfony (root: /var/www/html/public).

├── .env                        # Environment file with DATABASE_URL set to connect to the 'db' container.

├── ... (other Symfony project files)


**Configuration Details:**

**php:**
Built using the Dockerfile-php file.
Mounts the project’s root directory to /var/www/html in the container.

**nginx:**
Uses the official Nginx image.
Exposes port 80 to the host.
Loads its configuration from docker/nginx/default.conf.
Depends on the php container.

**db:**
Uses the official PostgreSQL image.
_Environment variables:_
POSTGRES_USER=symfony
POSTGRES_PASSWORD=symfony
POSTGRES_DB=symfony
Exposes port 5432 to the host.
Uses a named volume db_data for data persistence.

**Dockerfile-php:**
Based on php:8.2-fpm to support modern PHP features.
Installs necessary system packages and PHP extensions (e.g., pdo, pdo_pgsql).
Installs Composer for dependency management.
Sets the working directory to /var/www/html.

**docker/nginx/default.conf:**
Configures Nginx to serve the Symfony application.
Sets the document root to /var/www/html/public.
Routes PHP requests to the php container on port 9000.


Diff:
diff --git a/.env b/.env
deleted file mode 100644
index e6cabe4..0000000
--- a/.env
+++ /dev/null
@@ -1,20 +0,0 @@
-# In all environments, the following files are loaded if they exist,
-# the latter taking precedence over the former:
-#
-#  * .env                contains default values for the environment variables needed by the app
-#  * .env.local          uncommitted file with local overrides
-#  * .env.$APP_ENV       committed environment-specific defaults
-#  * .env.$APP_ENV.local uncommitted environment-specific overrides
-#
-# Real environment variables win over .env files.
-#
-# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
-# https://symfony.com/doc/current/configuration/secrets.html
-#
-# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
-# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
-
-###> symfony/framework-bundle ###
-APP_ENV=dev
-APP_SECRET=
-###< symfony/framework-bundle ###
diff --git a/.env.dev b/.env.dev
deleted file mode 100644
index a47245f..0000000
--- a/.env.dev
+++ /dev/null
@@ -1,4 +0,0 @@
-
-###> symfony/framework-bundle ###
-APP_SECRET=bd8c8b853e075a7a5d2aa36f3496b97b
-###< symfony/framework-bundle ###
diff --git a/.env_example b/.env_example
new file mode 100644
index 0000000..a78fe18
--- /dev/null
+++ b/.env_example
@@ -0,0 +1,12 @@
+###> symfony/framework-bundle ###
+APP_ENV='change me'
+APP_SECRET='change me'
+###< symfony/framework-bundle ###
+
+DB_USER='change me'
+DB_PASSWORD='change me'
+DB_NAME='change me'
+DB_HOST='change me'
+DB_PORT='change me'
+
+DATABASE_URL="postgresql://${DB_USER}:${DB_PASSWORD}@db:5432/${DB_NAME}?serverVersion=15&charset=utf8"
diff --git a/.gitignore b/.gitignore
index a67f91e..88561b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,7 @@
-
 ###> symfony/framework-bundle ###
+.phpunit.result.cache
+.env.dev
+.env
 /.env.local
 /.env.local.php
 /.env.*.local
diff --git a/Dockerfile-php b/Dockerfile-php
new file mode 100644
index 0000000..a8c9430
--- /dev/null
+++ b/Dockerfile-php
@@ -0,0 +1,11 @@
+FROM php:8.2-fpm
+
+RUN apt-get update && apt-get install -y \
+    git \
+    unzip \
+    libpq-dev \
+    && docker-php-ext-install pdo pdo_pgsql
+
+WORKDIR /var/www/html
+
+CMD ["php-fpm"]
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..f887de9
--- /dev/null
+++ b/README.md
@@ -0,0 +1,69 @@
+# Symfony Project
+
+This project is a Symfony-based application containerized using Docker. It includes containers for PHP, Nginx, and PostgreSQL, ensuring a reproducible development environment for local development and deployment.
+
+## Prerequisites
+
+- **Git** – for version control.
+- **Docker & Docker Compose** – for containerization.
+- **PHP & Composer** – (optional, if you want to run Composer locally).
+- **Symfony CLI** – (optional, but recommended for Symfony project management).
+
+## Getting Started
+
+### 1. Clone the Repository
+
+Clone the repository from GitHub to your local machine:
+
+```bash
+git clone https://github.com/Rmgs123/Symfony-Project.git
+```
+
+### 2. Environment Setup
+
+Create your environment file:
+
+- Copy the sample environment file or create your own `.env` file in the root directory.
+- Edit the `.env` file to include your database and app settings. For example:
+
+```dotenv
+APP_ENV=dev
+APP_SECRET=your_app_secret_here
+DATABASE_URL="postgresql://symfony:symfony@db:5432/symfony?serverVersion=15&charset=utf8"
+```
+
+### 3. Install PHP Dependencies
+
+Install the necessary PHP dependencies using Composer:
+
+```bash
+composer install
+```
+
+### 4. Build and Run Containers
+
+This project uses Docker to create an isolated environment. The Docker configuration includes:
+
+- **docker-compose.yml:** Defines services for PHP, Nginx, and PostgreSQL.
+- **Dockerfile-php:** Builds the PHP container with necessary extensions and Composer.
+- **docker/nginx/default.conf:** Configures Nginx to serve the Symfony application.
+  
+**Build the Docker images with:**
+
+```bash
+docker-compose build
+```
+
+Then, start the containers in detached mode:
+
+```bash
+docker-compose up -d
+```
+
+### 5. Verify the Setup
+
+- **Web Server:**  
+  Open your browser and go to [http://localhost](http://localhost). You should see the Symfony welcome page or your application’s default route.
+  
+- **Database Connectivity:**  
+  Don't forget to verify that the PostgreSQL container is working.
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..62c3cfc
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,36 @@
+version: '3.8'
+
+services:
+  php:
+    build:
+      context: .
+      dockerfile: Dockerfile-php
+    container_name: php_container
+    volumes:
+      - ./:/var/www/html
+
+  nginx:
+    image: nginx:latest
+    container_name: nginx_container
+    ports:
+      - "80:80"
+    volumes:
+      - ./:/var/www/html
+      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
+    depends_on:
+      - php
+
+  db:
+    image: postgres:latest
+    container_name: db_container
+    environment:
+      - POSTGRES_USER=${DB_USER}
+      - POSTGRES_PASSWORD=${DB_PASSWORD}
+      - POSTGRES_DB=${DB_NAME}
+    ports:
+      - "${DB_PORT}:5432"
+    volumes:
+      - db_data:/var/lib/postgresql/data
+
+volumes:
+  db_data:
diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf
new file mode 100644
index 0000000..8282730
--- /dev/null
+++ b/docker/nginx/default.conf
@@ -0,0 +1,17 @@
+server {
+    listen 80;
+    server_name localhost;
+    root /var/www/html/public;
+
+    location / {
+        try_files $uri /index.php$is_args$args;
+    }
+
+    location ~ \.php$ {
+        fastcgi_pass php:9000;
+        fastcgi_split_path_info ^(.+\.php)(/.+)$;
+        include fastcgi_params;
+        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
+        fastcgi_param DOCUMENT_ROOT $realpath_root;
+    }
+}


Reviews:
user: login: feip-krk
state: COMMENTED
author_association: NONE
submitted_at: 2025-03-12T07:15:28Z
user: login: praisethedeviI
state: CHANGES_REQUESTED
author_association: COLLABORATOR
submitted_at: 2025-03-20T04:20:02Z

Review comments:
diff_hunk: @@ -18,3 +18,5 @@
 APP_ENV=dev
 APP_SECRET=
 ###< symfony/framework-bundle ###
+
+DATABASE_URL="postgresql://symfony:symfony@db:5432/symfony?serverVersion=15&charset=utf8"
path: .env
user: login: feip-krk
body: Эта ссылку лучше написать как шаблон, в ней есть данные для подключения к базе: название базы данных, логин, пароль - их не должно быть в репозитории, они локально в переменных

DATABASE_URL="postgresql://${DATABASE_USERNAME}:${DATABASE_PASSWORD} ...

Значения DATABASE_USERNAME , DATABASE_PASSWORD , DATABASE_DATABASE заполнять надо в локальном файле .env.local , а здесь только значения по умолчанию

created_at: 2025-03-07T02:17:37Z
author_association: NONE
diff_hunk: @@ -0,0 +1,15 @@
+FROM php:8.2-fpm
+
+RUN apt-get update && apt-get install -y \
+    git \
+    unzip \
+    libpq-dev \
+    && docker-php-ext-install pdo pdo_pgsql
+
+RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
+    && php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
+    && php -r "unlink('composer-setup.php');"
path: Dockerfile-php
user: login: feip-krk
body: Зачем тебе может пригодиться эта настройка?
created_at: 2025-03-07T02:23:59Z
author_association: NONE
diff_hunk: @@ -0,0 +1,12 @@
+###> symfony/framework-bundle ###
+APP_ENV=change me
+APP_SECRET=change me
+###< symfony/framework-bundle ###
+
+DB_USER=change me
+DB_PASSWORD=change me
+DB_NAME=change me
+DB_HOST=change me
+DB_PORT=change me
+
+DATABASE_URL="postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?serverVersion=15&charset=utf8"
path: .env_example
user: login: praisethedeviI
body: {DB_HOST}:${DB_PORT} -- это заменить на db_container:5432 (название контейнера и внутренний порт)
created_at: 2025-03-20T04:08:20Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,12 @@
+###> symfony/framework-bundle ###
+APP_ENV=change me
+APP_SECRET=change me
+###< symfony/framework-bundle ###
+
+DB_USER=change me
+DB_PASSWORD=change me
+DB_NAME=change me
+DB_HOST=change me
+DB_PORT=change me
path: .env_example
user: login: praisethedeviI
body: Если переменной ставится строка с пробелами, то надо ковычки ставить. Например DB_USER='change me'
created_at: 2025-03-20T04:11:25Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1 @@
+{"version":1,"defects":[],"times":{"App\\Tests\\Service\\BookingCsvServiceTest::testCreateBooking":0.017,"App\\Tests\\Service\\CottageCsvServiceTest::testGetAllCottagesEmptyIfNoFile":0.001}}
path: .phpunit.result.cache
user: login: praisethedeviI
body: Лишний файл, он должен быть в .gitignore
created_at: 2025-03-20T04:13:04Z
author_association: COLLABORATOR

PR comments:
user: login: feip-krk
created_at: 2025-03-07T02:21:57Z
body: Начинай коммиты в повелительном наклонении Add DATABASE_URL ...

https://cbea.ms/git-commit/

Текст коммита 

Added Docker configuration: docker-compose.yml, Dockerfile-php, docker/nginx/default.conf

слишком длинный, список файлов видно в самом коммите, не нужно его описывать, вместо этого можно перечислить какие контейнеры ты создаешь
author_association: NONE
user: login: Rmgs123
created_at: 2025-03-09T10:54:59Z
body: @feip-krk Понял, а можно теперь мерджить?
author_association: OWNER
user: login: feip-krk
created_at: 2025-03-12T07:21:47Z
body: > @feip-krk Понял, а можно теперь мерджить?

объедини плохие коммиты с хорошими и сделай force push , чтобы в основную ветку (develop/master/main) попали только красивые изменения

прошу прощения за долгий ответ, не обратила внимания, что комментарии были помечены как pending 
author_association: NONE
user: login: feip-krk
created_at: 2025-03-14T01:33:07Z
body: @Rmgs123 Сделай, пожалуйста правки в .env файле
author_association: NONE
user: login: Rmgs123
created_at: 2025-03-15T02:48:51Z
body: @feip-krk Сделал.
author_association: OWNER
user: login: Faner201
created_at: 2025-03-17T05:45:12Z
body: Ещё, я бы убрал .env вообще из системы, так как в этом файле лежит инфа которую не должен знать пользователь.
Завел бы .env.example и переменные, у которых нужно заменить значение написал бы: "change me"
author_association: NONE
user: login: Rmgs123
created_at: 2025-03-17T06:11:27Z
body: Сделал.

author_association: OWNER
user: login: Rmgs123
created_at: 2025-03-17T22:38:40Z
body: @feip-krk 
author_association: OWNER
user: login: Rmgs123
created_at: 2025-03-21T00:47:44Z
body: @praisethedeviI Исправил.
author_association: OWNER
user: login: Rmgs123
created_at: 2025-03-24T03:52:50Z
body: @feip-krk можно мерджить?
author_association: OWNER
user: login: feip-krk
created_at: 2025-03-27T01:47:19Z
body: Да, мержи! Хорошая работа, приношу извинения за задержку проверок
author_association: NONE