Skip to content

Commit

Permalink
Merge pull request #43 from minos-framework/0.1.x
Browse files Browse the repository at this point in the history
v0.1.2
  • Loading branch information
albamig authored Mar 16, 2022
2 parents 4659f9c + 9df958a commit f6edc79
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 38 deletions.
8 changes: 8 additions & 0 deletions microservice/language/python/init/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ def build_deploy_playbook(path: Path) -> str:
def build_docker_compose(path: Path, microservice_name: str) -> str:
"""Build Docker Compose file content."""

db_creation_path = path.parent / "external/postgres/10-create-database.sql"
if not db_creation_path.exists():
raise ValueError("external/postgres/10-create-database.sql script must exist")

with db_creation_path.open("a") as db_creation_file:
db_creation_file.write(f"\nCREATE DATABASE {microservice_name}_db;")
db_creation_file.write(f"\nCREATE DATABASE {microservice_name}_query_db;")

if not path.exists():
raise ValueError("A base Compose file must exist.")

Expand Down
1 change: 1 addition & 0 deletions microservice/language/python/init/config.yml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ service:
transaction_repository: minos.aggregate.PostgreSqlTransactionRepository
event_repository: minos.aggregate.PostgreSqlEventRepository
snapshot_repository: minos.aggregate.PostgreSqlSnapshotRepository
{{ name }}_repository: src.{{ aggregate }}QueryServiceRepository
saga_manager: minos.saga.SagaManager
discovery: minos.networks.DiscoveryConnector
services:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ class {{ aggregate }}QueryServiceRepository(MinosSetup):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.engine = create_engine("postgresql+psycopg2://postgres:@localhost:5432/{{ name }}_query_db".format(**kwargs))
self.session = sessionmaker(bind=self.engine)
self.session = sessionmaker(bind=self.engine)()

async def _setup(self) -> None:
Base.metadata.create_all(self.engine)

@classmethod
def _from_config(cls, *args, config: MinosConfig, **kwargs) -> {{ aggregate }}QueryRepository:
def _from_config(cls, *args, config: MinosConfig, **kwargs):
return cls(*args, **(config.query_repository._asdict()) | kwargs)

@property
def session(self):
return self.session
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ from minos.networks import (
class {{ aggregate }}QueryService(QueryService):
"""{{ aggregate }}QueryService class."""

repository: {{ aggregate }}QueryServiceRepository = Provide["{{ name }}_repository"]

@enroute.rest.query("/{{ aggregate.lower() }}s", "GET")
async def get_{{ aggregate.lower() }}(self, request: Request) -> Response:
"""Get a {{ aggregate }} instance.
Expand Down
60 changes: 55 additions & 5 deletions microservice/language/python/init/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from pathlib import (
Path,
)
from uuid import (
UUID,
)

from minos.aggregate import (
InMemoryEventRepository,
Expand All @@ -13,23 +16,70 @@
)
from minos.common import (
DependencyInjector,
Lock,
MinosConfig,
MinosPool,
MinosSetup,
)
from minos.networks import (
InMemoryBrokerPublisher,
InMemoryBrokerSubscriberBuilder,
from minos.saga import (
SagaContext,
SagaStatus,
)


class _FakeBroker(MinosSetup):
"""For testing purposes."""

async def send(self, *args, **kwargs) -> None:
"""For testing purposes."""


class _FakeSagaManager(MinosSetup):
"""For testing purposes."""

async def run(self, *args, **kwargs) -> UUID:
"""For testing purposes."""


class _FakeSagaExecution:
def __init__(self, context: SagaContext, status: SagaStatus = SagaStatus.Finished):
self.context = context
self.status = status


class FakeLock(Lock):
"""For testing purposes."""

def __init__(self, key=None, *args, **kwargs):
if key is None:
key = "fake"
super().__init__(key, *args, **kwargs)

async def __aexit__(self, exc_type, exc_val, exc_tb):
return


class FakeLockPool(MinosPool):
"""For testing purposes."""

async def _create_instance(self):
return FakeLock()

async def _destroy_instance(self, instance) -> None:
"""For testing purposes."""


def build_dependency_injector() -> DependencyInjector:
"""For testing purposes"""

return DependencyInjector(
build_config(),
broker_publisher=InMemoryBrokerPublisher,
saga_manager=_FakeSagaManager,
broker_publisher=_FakeBroker,
lock_pool=FakeLockPool,
transaction_repository=InMemoryTransactionRepository,
event_repository=InMemoryEventRepository,
snapshot_snapshot=InMemorySnapshotRepository,
snapshot_repository=InMemorySnapshotRepository,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ minos-microservice-cqrs = "^0.5.0"
minos-broker-kafka = "^0.5.0"
minos-discovery-minos = "^0.5.0"
typer = "^0.3.2"
SQLAlchemy = "^1.4.32"
SQLAlchemy = "^1.4.0"

[tool.poetry.dev-dependencies]
black = "^19.10b"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- Create microservices databases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM postgres
COPY create-multiple-postgresql-databases.sh /docker-entrypoint-initdb.d/
FROM postgres:14.2
COPY 10-create-database.sql /docker-entrypoint-initdb.d/10-create-database.sql

This file was deleted.

6 changes: 4 additions & 2 deletions project/database/redis/deploy/docker-compose/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ def build_docker_compose(path: Path) -> str:
data = yaml.safe_load(file)

container = {
"image": "docker.io/bitnami/redis:6.2",
"user": "root",
"restart": "always",
"image": "redis:latest",
"volumes": ["redis:/data",],
"environment": {"ALLOW_EMPTY_PASSWORD": "yes", "REDIS_DISABLE_COMMANDS": "FLUSHDB,FLUSHALL"},
"volumes": ["redis:/bitnami/redis/data",],
}

data["services"]["redis"] = container
Expand Down

0 comments on commit f6edc79

Please sign in to comment.