From 98d8cd5753429c0a72b61502b9ff46b36f1f165d Mon Sep 17 00:00:00 2001 From: Oleksii Skorobogatko Date: Fri, 6 Sep 2024 18:18:44 +0300 Subject: [PATCH 01/10] #1 docker database (including test) --- .env | 11 ++++++++++- .env.test | 3 ++- compose.override.yaml | 8 -------- compose.yaml | 20 ++++++++++++++------ docker/database/init.sql | 5 +++++ 5 files changed, 31 insertions(+), 16 deletions(-) delete mode 100644 compose.override.yaml create mode 100644 docker/database/init.sql diff --git a/.env b/.env index 3f69f84..9c685c2 100644 --- a/.env +++ b/.env @@ -19,6 +19,14 @@ APP_ENV=dev APP_SECRET=b31393636737e68e5f85ac979f37e3da ###< symfony/framework-bundle ### +### docker env +MYSQL_ROOT_PASSWORD=secret +MYSQL_DATABASE=mirspay +MYSQL_USER=mirspay +MYSQL_PASSWORD=password +MYSQL_HOST=127.0.0.1 +### + ###> doctrine/doctrine-bundle ### # Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url # IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml @@ -26,7 +34,8 @@ APP_SECRET=b31393636737e68e5f85ac979f37e3da # DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" # DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4" # DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4" -DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8" +# DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8" +DATABASE_URL="mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@${MYSQL_HOST}:3306/${MYSQL_DATABASE}?serverVersion=8.0.33&charset=utf8mb4" ###< doctrine/doctrine-bundle ### # LiqPay gateway parameters. diff --git a/.env.test b/.env.test index e45f144..49512d3 100644 --- a/.env.test +++ b/.env.test @@ -4,4 +4,5 @@ APP_SECRET='$ecretf0rt3st' SYMFONY_DEPRECATIONS_HELPER=999999 PANTHER_APP_ENV=panther PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots -DATABASE_URL="mysql://admin:admin@127.0.0.1:3306/mirspay?serverVersion=5.7.41&charset=utf8mb4" + +DATABASE_URL="mysql://mirspay:password@127.0.0.1:3306/mirspay?serverVersion=8.0.33&charset=utf8mb4" diff --git a/compose.override.yaml b/compose.override.yaml deleted file mode 100644 index f2247d5..0000000 --- a/compose.override.yaml +++ /dev/null @@ -1,8 +0,0 @@ -version: '3' - -services: -###> doctrine/doctrine-bundle ### - database: - ports: - - "5432" -###< doctrine/doctrine-bundle ### diff --git a/compose.yaml b/compose.yaml index 1abf6c6..ac702e9 100644 --- a/compose.yaml +++ b/compose.yaml @@ -3,19 +3,27 @@ version: '3' services: ###> doctrine/doctrine-bundle ### database: - image: postgres:${POSTGRES_VERSION:-16}-alpine + image: 'mysql:8.0' environment: - POSTGRES_DB: ${POSTGRES_DB:-app} - # You should definitely change the password in production - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!ChangeMe!} - POSTGRES_USER: ${POSTGRES_USER:-app} + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} + MYSQL_DATABASE: ${MYSQL_DATABASE} + MYSQL_USER: ${MYSQL_USER} + MYSQL_PASSWORD: ${MYSQL_PASSWORD} + ports: + - '3306:3306' volumes: - - database_data:/var/lib/postgresql/data:rw + - ./docker/database/init.sql:/docker-entrypoint-initdb.d/init.sql # You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data! # - ./docker/db/data:/var/lib/postgresql/data:rw + networks: + - mirspay ###< doctrine/doctrine-bundle ### volumes: ###> doctrine/doctrine-bundle ### database_data: ###< doctrine/doctrine-bundle ### + +networks: + mirspay: + driver: bridge diff --git a/docker/database/init.sql b/docker/database/init.sql new file mode 100644 index 0000000..5e7d0e8 --- /dev/null +++ b/docker/database/init.sql @@ -0,0 +1,5 @@ +--- test database +--- .env.test + +CREATE DATABASE `mirspay_test`; +GRANT ALL ON mirspay_test.* TO 'mirspay'@'%'; From 8b9b4cbb68f7effb983cb98a4fbe78d1fdbf4e93 Mon Sep 17 00:00:00 2001 From: Oleksii Skorobogatko Date: Sat, 7 Sep 2024 13:00:33 +0300 Subject: [PATCH 02/10] #1 app (php) docker --- compose.yaml | 9 +++++++++ docker/php/Dockerfile | 15 +++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 docker/php/Dockerfile diff --git a/compose.yaml b/compose.yaml index ac702e9..15a7017 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,6 +1,15 @@ version: '3' services: + app: + build: + context: ./docker/php + volumes: + - .:/var/www + depends_on: + - database + networks: + - mirspay ###> doctrine/doctrine-bundle ### database: image: 'mysql:8.0' diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile new file mode 100644 index 0000000..cb277c1 --- /dev/null +++ b/docker/php/Dockerfile @@ -0,0 +1,15 @@ +FROM php:8.3-fpm + +RUN apt-get update && apt-get install -y --no-install-recommends \ + unzip \ + && rm -rf /var/lib/apt/lists/* + +RUN docker-php-ext-install pdo_mysql opcache bcmath + +# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser +ENV COMPOSER_ALLOW_SUPERUSER=1 + +COPY --from=composer /usr/bin/composer /usr/local/bin/composer + +COPY . /var/www +WORKDIR /var/www From 469ee2baecc2dcdf556e6978d0861a11a465d4bd Mon Sep 17 00:00:00 2001 From: Oleksii Skorobogatko Date: Sat, 7 Sep 2024 13:01:00 +0300 Subject: [PATCH 03/10] #1 set database host in docker network --- .env | 2 +- .env.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 9c685c2..cc44fe9 100644 --- a/.env +++ b/.env @@ -24,7 +24,7 @@ MYSQL_ROOT_PASSWORD=secret MYSQL_DATABASE=mirspay MYSQL_USER=mirspay MYSQL_PASSWORD=password -MYSQL_HOST=127.0.0.1 +MYSQL_HOST=database ### ###> doctrine/doctrine-bundle ### diff --git a/.env.test b/.env.test index 49512d3..c4d5caf 100644 --- a/.env.test +++ b/.env.test @@ -5,4 +5,4 @@ SYMFONY_DEPRECATIONS_HELPER=999999 PANTHER_APP_ENV=panther PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots -DATABASE_URL="mysql://mirspay:password@127.0.0.1:3306/mirspay?serverVersion=8.0.33&charset=utf8mb4" +DATABASE_URL="mysql://mirspay:password@database:3306/mirspay?serverVersion=8.0.33&charset=utf8mb4" From b4074b0b5b84dbd2815146069acf4ea38ad84a13 Mon Sep 17 00:00:00 2001 From: Oleksii Skorobogatko Date: Sat, 7 Sep 2024 18:10:56 +0300 Subject: [PATCH 04/10] #1 nginx service --- compose.yaml | 11 +++++++++++ docker/nginx/conf.d/default.conf | 31 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 docker/nginx/conf.d/default.conf diff --git a/compose.yaml b/compose.yaml index 15a7017..c8eb85b 100644 --- a/compose.yaml +++ b/compose.yaml @@ -10,6 +10,17 @@ services: - database networks: - mirspay + nginx: + image: nginx:latest + depends_on: + - app + volumes: + - .:/var/www + - ./docker/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf + ports: + - '80:80' + networks: + - mirspay ###> doctrine/doctrine-bundle ### database: image: 'mysql:8.0' diff --git a/docker/nginx/conf.d/default.conf b/docker/nginx/conf.d/default.conf new file mode 100644 index 0000000..f9c8959 --- /dev/null +++ b/docker/nginx/conf.d/default.conf @@ -0,0 +1,31 @@ +upstream app-upstream { + server app:9000; +} + +server { + listen 80 default_server; + listen [::]:80 default_server ipv6only=on; + + server_name localhost; + root /var/www/public; + index index.php index.html index.htm; + + location / { + try_files $uri $uri/ /index.php$is_args$args; + } + + location ~ \.php$ { + try_files $uri /index.php =404; + fastcgi_pass app-upstream; + fastcgi_index index.php; + fastcgi_buffers 16 16k; + fastcgi_buffer_size 32k; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_read_timeout 600; + include fastcgi_params; + } + + location ~ /\.ht { + deny all; + } +} From 0075799a8273af49e7f9a84ac190496ecbac38f6 Mon Sep 17 00:00:00 2001 From: Oleksii Skorobogatko Date: Sat, 7 Sep 2024 18:11:10 +0300 Subject: [PATCH 05/10] #1 docker up and running doc --- README.md | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 82f766d..d0eb07b 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,24 @@ via various gateways. Please, take a look at the picture below to get an idea ho * MySQL ## Install -_TBD: make docker installation_ +### Docker +Close the repository: +```shell +git clone https://github.com/skoro/mirspay.git +``` + +Build and up the image: +```shell +docker compose build +docker compose run --rm app composer install +docker compose up -d +docker compose exec app php bin/console doctrine:migrations:migrate +``` + +### From source code + +Assume PHP, [Symfony CLI](https://symfony.com/download) and MySQL locally installed. 1. Clone the repository: ```shell git clone https://github.com/skoro/mirspay.git @@ -26,16 +42,27 @@ _TBD: make docker installation_ ```shell composer install ``` -3. Edit the `.env` file and fill in the necessary variables and payment gateway credentials: +3. Create `.env.local` file and fill in the database dsn: ```dotenv - LIQPAY_PUBLIC_KEY= - LIQPAY_PRIVATE_KEY= + DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4" + ``` +4. Apply migrations: + ```shell + symfony console doctrine:migrations:migrate ``` -4. Start the server. +5. Start the server. ```shell symfony serve -d ``` +### Payment Gateways configuration + +1. LiqPay public and private keys: + ```dotenv + LIQPAY_PUBLIC_KEY= + LIQPAY_PRIVATE_KEY= + ``` + ## API documentation Two end-points are available for getting the API documentation: - `/api/doc` swagger ui. From 316d32adeb0d850c93760e5e5c1c0d838312fb22 Mon Sep 17 00:00:00 2001 From: Oleksii Skorobogatko Date: Sat, 7 Sep 2024 18:11:25 +0300 Subject: [PATCH 06/10] #1 fix test database create --- docker/database/init.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/database/init.sql b/docker/database/init.sql index 5e7d0e8..624c07e 100644 --- a/docker/database/init.sql +++ b/docker/database/init.sql @@ -1,5 +1,5 @@ ---- test database ---- .env.test +-- test database +-- .env.test CREATE DATABASE `mirspay_test`; GRANT ALL ON mirspay_test.* TO 'mirspay'@'%'; From 53b189782bf1f2b65f573343f825f3ced8f9890a Mon Sep 17 00:00:00 2001 From: Oleksii Skorobogatko Date: Sat, 7 Sep 2024 18:14:42 +0300 Subject: [PATCH 07/10] #1 source code readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d0eb07b..eac19f2 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ docker compose exec app php bin/console doctrine:migrations:migrate ### From source code -Assume PHP, [Symfony CLI](https://symfony.com/download) and MySQL locally installed. +Assume PHP, [Symfony CLI](https://symfony.com/download) and MySQL are locally installed. 1. Clone the repository: ```shell git clone https://github.com/skoro/mirspay.git From 6abd9324b819efa6deb1c99a509e0f8877bbf018 Mon Sep 17 00:00:00 2001 From: Oleksii Skorobogatko Date: Sat, 7 Sep 2024 18:15:43 +0300 Subject: [PATCH 08/10] #1 renamed to avoid confusing with composer --- compose.yaml => docker-compose.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename compose.yaml => docker-compose.yaml (100%) diff --git a/compose.yaml b/docker-compose.yaml similarity index 100% rename from compose.yaml rename to docker-compose.yaml From 35f315d45482d076812f710578c66948500d8148 Mon Sep 17 00:00:00 2001 From: Oleksii Skorobogatko Date: Sat, 7 Sep 2024 18:43:08 +0300 Subject: [PATCH 09/10] #1 php xdebug and config --- docker-compose.yaml | 1 + docker/php/Dockerfile | 4 +++- docker/php/xdebug.ini | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 docker/php/xdebug.ini diff --git a/docker-compose.yaml b/docker-compose.yaml index c8eb85b..68c8745 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -5,6 +5,7 @@ services: build: context: ./docker/php volumes: + - ./docker/php/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini - .:/var/www depends_on: - database diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index cb277c1..946d512 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -4,7 +4,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ unzip \ && rm -rf /var/lib/apt/lists/* -RUN docker-php-ext-install pdo_mysql opcache bcmath +RUN pecl install xdebug-3.3.2 \ + && docker-php-ext-enable xdebug \ + && docker-php-ext-install pdo_mysql opcache bcmath # https://getcomposer.org/doc/03-cli.md#composer-allow-superuser ENV COMPOSER_ALLOW_SUPERUSER=1 diff --git a/docker/php/xdebug.ini b/docker/php/xdebug.ini new file mode 100644 index 0000000..d3b509d --- /dev/null +++ b/docker/php/xdebug.ini @@ -0,0 +1,4 @@ +zend_extension=xdebug +xdebug.mode=debug +xdebug.start_with_request=yes +xdebug.client_host=host.docker.internal From 51eb057eb95ecb145449ddaab64886fd3842d94b Mon Sep 17 00:00:00 2001 From: Oleksii Skorobogatko Date: Sat, 7 Sep 2024 18:47:12 +0300 Subject: [PATCH 10/10] #1 comment out to avoid warning from docker --- docker-compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 68c8745..9355d84 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,4 +1,4 @@ -version: '3' +#version: '3' services: app: