diff --git a/.env b/.env index 3f69f84..cc44fe9 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=database +### + ###> 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..c4d5caf 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@database:3306/mirspay?serverVersion=8.0.33&charset=utf8mb4" diff --git a/README.md b/README.md index 82f766d..eac19f2 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 are 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. 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 deleted file mode 100644 index 1abf6c6..0000000 --- a/compose.yaml +++ /dev/null @@ -1,21 +0,0 @@ -version: '3' - -services: -###> doctrine/doctrine-bundle ### - database: - image: postgres:${POSTGRES_VERSION:-16}-alpine - environment: - POSTGRES_DB: ${POSTGRES_DB:-app} - # You should definitely change the password in production - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!ChangeMe!} - POSTGRES_USER: ${POSTGRES_USER:-app} - volumes: - - database_data:/var/lib/postgresql/data:rw - # 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 -###< doctrine/doctrine-bundle ### - -volumes: -###> doctrine/doctrine-bundle ### - database_data: -###< doctrine/doctrine-bundle ### diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..9355d84 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,50 @@ +#version: '3' + +services: + app: + 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 + 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' + environment: + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} + MYSQL_DATABASE: ${MYSQL_DATABASE} + MYSQL_USER: ${MYSQL_USER} + MYSQL_PASSWORD: ${MYSQL_PASSWORD} + ports: + - '3306:3306' + volumes: + - ./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..624c07e --- /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'@'%'; 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; + } +} diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile new file mode 100644 index 0000000..946d512 --- /dev/null +++ b/docker/php/Dockerfile @@ -0,0 +1,17 @@ +FROM php:8.3-fpm + +RUN apt-get update && apt-get install -y --no-install-recommends \ + unzip \ + && rm -rf /var/lib/apt/lists/* + +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 + +COPY --from=composer /usr/bin/composer /usr/local/bin/composer + +COPY . /var/www +WORKDIR /var/www 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