Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Database
# Database Configuration
POSTGRES_USER=app
POSTGRES_PASSWORD=se3ret
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_PASSWORD=strongpassword

# Database Names
USER_DB_NAME=user_service
ORDER_DB_NAME=order_service
NOTIFICATION_DB_NAME=notification_service

# Host Ports for Database Access
USER_DB_PORT=5433
ORDER_DB_PORT=5434
NOTIFICATION_DB_PORT=5435

# Application Secrets
APP_SECRET=your_microservices_secret_here
66 changes: 54 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
container_name: gateway
volumes:
- ./gateway/nginx.conf:/etc/nginx/conf.d/default.conf:ro
- ./services:/var/www/html # чтобы nginx имел доступ ко всем сервисам
- ./services:/var/www/html
ports:
- "8080:80"
depends_on:
Expand All @@ -15,50 +15,92 @@ services:
user-service:
build: ./services/user-service
container_name: user-service
env_file:
- .env
- ./services/user-service/.env
volumes:
- ./services/user-service:/var/www/html
environment:
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/user_service
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@user-db:5432/${USER_DB_NAME}?serverVersion=15&charset=utf8
depends_on:
- postgres
- user-db
expose:
- "9000"

order-service:
build: ./services/order-service
container_name: order-service
env_file:
- .env
- ./services/user-service/.env
volumes:
- ./services/order-service:/var/www/html
environment:
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/order_service
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@order-db:5432/${ORDER_DB_NAME}?serverVersion=15&charset=utf8
depends_on:
- postgres
- order-db
expose:
- "9000"

notification-service:
build: ./services/notification-service
container_name: notification-service
env_file:
- .env
- ./services/user-service/.env
volumes:
- ./services/notification-service:/var/www/html
environment:
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/notification_service
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@notification-db:5432/${NOTIFICATION_DB_NAME}?serverVersion=15&charset=utf8
depends_on:
- postgres
- notification-db
expose:
- "9000"

postgres:
# Databases
user-db:
image: postgres:15
container_name: postgres
container_name: user-db
env_file: .env
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${USER_DB_NAME}
volumes:
- pgdata:/var/lib/postgresql/data
- user_data:/var/lib/postgresql/data
- ./postgres-init:/docker-entrypoint-initdb.d:ro
ports:
- "5432:5432"
- "${USER_DB_PORT}:5432"

order-db:
image: postgres:15
container_name: order-db
env_file: .env
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${ORDER_DB_NAME}
volumes:
- order_data:/var/lib/postgresql/data
- ./postgres-init:/docker-entrypoint-initdb.d:ro
ports:
- "${ORDER_DB_PORT}:5432"

notification-db:
image: postgres:15
container_name: notification-db
env_file: .env
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${NOTIFICATION_DB_NAME}
volumes:
- notification_data:/var/lib/postgresql/data
- ./postgres-init:/docker-entrypoint-initdb.d:ro
ports:
- "${NOTIFICATION_DB_PORT}:5432"

volumes:
pgdata:
user_data:
order_data:
notification_data:
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ logs:
clean:
@echo "🧹 Cleaning up..."
docker-compose down -v
rm -f services/*/.env
rm -r services/*/var/
@rm -f services/*/.env
@rm -rf services/*/var/ 2>/dev/null || true

## Reset everything and start fresh
reset: clean setup start
Expand Down
4 changes: 0 additions & 4 deletions postgres-init/01-create-dbs.sql

This file was deleted.

9 changes: 6 additions & 3 deletions services/notification-service/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
APP_ENV=dev
APP_SECRET=change_this_to_a_random_value
DATABASE_URL=postgresql://app:password@postgres:5432/order_service
DEFAULT_URI=http://localhost:8080

# Symfony ожидает DATABASE_URL, но в Docker мы её передаём динамически
#Symfony will automatically pick up DATABASE_URL from the container's environment variables.
DATABASE_URL="instal_in_container"
DEFAULT_URI="instal_in_container"

3 changes: 1 addition & 2 deletions services/notification-service/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"symfony/flex": "^2.8.2",
"symfony/framework-bundle": "7.3.*",
"symfony/runtime": "7.3.*",
"symfony/yaml": "7.3.*",
"microservices/shared-contracts": "1.*"
"symfony/yaml": "7.3.*"
},
"require-dev": {
"phpunit/phpunit": "^11.5.42",
Expand Down
9 changes: 6 additions & 3 deletions services/order-service/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
APP_ENV=dev
APP_SECRET=change_this_to_a_random_value
DATABASE_URL=postgresql://app:password@postgres:5432/order_service
DEFAULT_URI=http://localhost:8080

# Symfony ожидает DATABASE_URL, но в Docker мы её передаём динамически
#Symfony will automatically pick up DATABASE_URL from the container's environment variables.
DATABASE_URL="instal_in_container"
DEFAULT_URI="instal_in_container"

8 changes: 6 additions & 2 deletions services/order-service/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/dbal": "^3",
"doctrine/doctrine-bundle": "^2.18",
"doctrine/doctrine-migrations-bundle": "^3.5",
"doctrine/orm": "^3.5",
"microservices/shared-contracts": "1.*",
"symfony/console": "7.3.*",
"symfony/dotenv": "7.3.*",
"symfony/flex": "^2.8.2",
"symfony/framework-bundle": "7.3.*",
"symfony/runtime": "7.3.*",
"symfony/yaml": "7.3.*",
"microservices/shared-contracts": "1.*"
"symfony/yaml": "7.3.*"
},
"require-dev": {
"phpunit/phpunit": "^11.5.42",
Expand Down
2 changes: 2 additions & 0 deletions services/order-service/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
];
54 changes: 54 additions & 0 deletions services/order-service/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'

# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '16'

profiling_collect_backtrace: '%kernel.debug%'
use_savepoints: true
orm:
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true
report_fields_where_declared: true
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
identity_generation_preferences:
Doctrine\DBAL\Platforms\PostgreSQLPlatform: identity
auto_mapping: true
mappings:
App:
type: attribute
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
controller_resolver:
auto_mapping: false

when@test:
doctrine:
dbal:
# "TEST_TOKEN" is typically set by ParaTest
dbname_suffix: '_test%env(default::TEST_TOKEN)%'

when@prod:
doctrine:
orm:
auto_generate_proxy_classes: false
proxy_dir: '%kernel.build_dir%/doctrine/orm/Proxies'
query_cache_driver:
type: pool
pool: doctrine.system_cache_pool
result_cache_driver:
type: pool
pool: doctrine.result_cache_pool

framework:
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.app
doctrine.system_cache_pool:
adapter: cache.system
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
doctrine_migrations:
migrations_paths:
# namespace is arbitrary but should be different from App\Migrations
# as migrations classes should NOT be autoloaded
'DoctrineMigrations': '%kernel.project_dir%/migrations'
enable_profiler: false
Empty file.
Empty file.
Empty file.
36 changes: 36 additions & 0 deletions services/order-service/symfony.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
{
"doctrine/deprecations": {
"version": "1.1",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "1.0",
"ref": "87424683adc81d7dc305eefec1fced883084aab9"
}
},
"doctrine/doctrine-bundle": {
"version": "2.18",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "2.13",
"ref": "620b57f496f2e599a6015a9fa222c2ee0a32adcb"
},
"files": [
"config/packages/doctrine.yaml",
"src/Entity/.gitignore",
"src/Repository/.gitignore"
]
},
"doctrine/doctrine-migrations-bundle": {
"version": "3.5",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "3.1",
"ref": "1d01ec03c6ecbd67c3375c5478c9a423ae5d6a33"
},
"files": [
"config/packages/doctrine_migrations.yaml",
"migrations/.gitignore"
]
},
"phpstan/phpstan": {
"version": "2.1",
"recipe": {
Expand Down
11 changes: 8 additions & 3 deletions services/user-service/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

# .env
APP_ENV=dev
APP_SECRET=change_this_to_a_random_value
DATABASE_URL=postgresql://app:password@postgres:5432/order_service
DEFAULT_URI=http://localhost:8080

# Symfony ожидает DATABASE_URL, но в Docker мы её передаём динамически
#Symfony will automatically pick up DATABASE_URL from the container's environment variables.
DATABASE_URL="instal_in_container"
DEFAULT_URI="instal_in_container"

9 changes: 7 additions & 2 deletions services/user-service/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/dbal": "^3",
"doctrine/doctrine-bundle": "^2.18",
"doctrine/doctrine-migrations-bundle": "^3.5",
"doctrine/orm": "^3.5",
"microservices/shared-contracts": "1.*",
"symfony/console": "7.3.*",
"symfony/dotenv": "7.3.*",
"symfony/flex": "^2.8.2",
"symfony/framework-bundle": "7.3.*",
"symfony/runtime": "7.3.*",
"symfony/yaml": "7.3.*",
"microservices/shared-contracts": "1.*"
"symfony/security-bundle": "7.3.*",
"symfony/yaml": "7.3.*"
},
"require-dev": {
"phpunit/phpunit": "^11.5.42",
Expand Down
3 changes: 3 additions & 0 deletions services/user-service/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
];
Loading