Skip to content

Commit

Permalink
Merge pull request #11 from skoro/1-docker-compose
Browse files Browse the repository at this point in the history
Docker integration
  • Loading branch information
skoro authored Sep 9, 2024
2 parents 0e38bbc + 51eb057 commit 7c1b0a0
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 36 deletions.
11 changes: 10 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@ 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
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=8.0.32&charset=utf8mb4"
# DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
DATABASE_URL="postgresql://app:[email protected]:5432/app?serverVersion=16&charset=utf8"
# DATABASE_URL="postgresql://app:[email protected]: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.
Expand Down
3 changes: 2 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]:3306/mirspay?serverVersion=5.7.41&charset=utf8mb4"

DATABASE_URL="mysql://mirspay:password@database:3306/mirspay?serverVersion=8.0.33&charset=utf8mb4"
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:[email protected]: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.
Expand Down
8 changes: 0 additions & 8 deletions compose.override.yaml

This file was deleted.

21 changes: 0 additions & 21 deletions compose.yaml

This file was deleted.

50 changes: 50 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions docker/database/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- test database
-- .env.test

CREATE DATABASE `mirspay_test`;
GRANT ALL ON mirspay_test.* TO 'mirspay'@'%';
31 changes: 31 additions & 0 deletions docker/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
17 changes: 17 additions & 0 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions docker/php/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
zend_extension=xdebug
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=host.docker.internal

0 comments on commit 7c1b0a0

Please sign in to comment.