minos-framework / minos-cli Goto Github PK
View Code? Open in Web Editor NEW๐น๏ธ The command-line interface of the Minos Framework
Home Page: http://www.minos.run
License: MIT License
๐น๏ธ The command-line interface of the Minos Framework
Home Page: http://www.minos.run
License: MIT License
Currently, we create the database each microservice needs within the docker-compose.yml
.
This approach has some problems, specially in production deployment: whenever a new microservice needs to get deployed, the docker-compose.yml
must be modified and the database container has to be restarted.
I think we should create the databases in microservices' startup.
the repository in query service now is:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.engine = create_engine("postgresql+psycopg2://postgres:@localhost:5432/produc_query_db".format(**kwargs))
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) -> ProducQueryRepository:
return cls(*args, **(config.query_repository._asdict()) | kwargs)
@property
def session(self):
return self.session
and must be
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.engine = create_engine("postgresql+psycopg2://{user}:{password}@{host}:{port}/{database}".format(**kwargs))
Session = sessionmaker(bind=self.engine)
self.session = Session()
async def _setup(self) -> None:
Base.metadata.create_all(self.engine)
@classmethod
def _from_config(cls, *args, config: MinosConfig, **kwargs):
return cls(*args, **(config.repository._asdict() | {"database": ""}) | kwargs)
Why?
because sqlalchemy use the instance of Session and not the session object given by the sesssionmaker
as well, as @albamig proposed, we have to remove the getter for session.
the README have the following information
minos set apigateway minos
this command must be changed to
minos set api-gateway minos
As explained at Textualize/rich#1758, currently there are a bug on the rich
library that does not allow to provide the choices
argument when return_type
is not str
minos --version
this command must return the installed minos cli version
Refactor command structure to a verb-based one.
Instead of minos project|microservice init
use minos init project|microservice
, etc.
Link to the repository: https://github.com/willmcgugan/rich
If the name of the project have Uppercase like, for example ProductCatalog
during the minos deploy microservice ProductCatalog
command execution, the CLI and Ansible return an error, because docker does not accept the Uppercase
The name of the Docker Build, POD, Service etc must be
microservice-productcatalog
Since new
command now creates microservices in the appropriate directory, init
is no longer needed.
When a command is used outside a minos project folder, the cli will return an error like that
Traceback (most recent call last):
File "/Users/andreamucci/.pyenv/versions/3.9.4/bin/minos", line 8, in <module>
sys.exit(main())
File "/Users/andreamucci/.pyenv/versions/3.9.4/lib/python3.9/site-packages/minos/cli/api/__init__.py", line 31, in main
app()
File "/Users/andreamucci/.pyenv/versions/3.9.4/lib/python3.9/site-packages/typer/main.py", line 214, in __call__
return get_command(self)(*args, **kwargs)
File "/Users/andreamucci/.local/lib/python3.9/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/Users/andreamucci/.local/lib/python3.9/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Users/andreamucci/.local/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/andreamucci/.local/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/andreamucci/.local/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/andreamucci/.local/lib/python3.9/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/andreamucci/.pyenv/versions/3.9.4/lib/python3.9/site-packages/typer/main.py", line 500, in wrapper
return callback(**use_params) # type: ignore
File "/Users/andreamucci/.pyenv/versions/3.9.4/lib/python3.9/site-packages/minos/cli/api/deploy.py", line 27, in deploy_microservice
deployer.deploy()
File "/Users/andreamucci/.pyenv/versions/3.9.4/lib/python3.9/site-packages/minos/cli/deploying/microservice.py", line 37, in deploy
subprocess.run("ansible-playbook playbooks/deploy.yaml", shell=True, cwd=str(self.target_directory))
File "/Users/andreamucci/.pyenv/versions/3.9.4/lib/python3.9/site-packages/minos/cli/deploying/microservice.py", line 30, in target_directory
return get_microservice_target_directory(self.path, self._name)
File "/Users/andreamucci/.pyenv/versions/3.9.4/lib/python3.9/site-packages/minos/cli/pathlib.py", line 38, in get_microservice_target_directory
raise ValueError(f"Unable to find the target directory for {name} from {path} origin.")
ValueError: Unable to find the target directory for product from /Users/andreamucci/PycharmProjects/EcommerceExample origin.
the cli must capture the Exception and print an error message
The minos cli must have the following command
minos queryservice set repository
this command must ask:
the cli would create the following files
queries/models.py
from sqlalchemy.orm import declarative_base
Base = declarative_base()
queries/repository.py
from minos.common import MinosSetup, MinosConfig
from sqlalchemy import create_engine
from src.queries.models import Base
class QueryServiceRepository(MinosSetup):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.engine = create_engine({{ THE URL DATABASE }})
async def _setup(self) -> None:
Base.metadata.create_all(self.engine)
@classmethod
def _from_config(cls, *args, config: MinosConfig, **kwargs) -> ProductQueryRepository:
return cls(*args, **(config.query_repository._asdict()) | kwargs)
the CLI must update the config.yml as well
...
query:
database: database_choosen_by_the_dev_db
user: postgres
password: ""
host: localhost
port: 5432
And must modify the plkaybooks/create-databse.yaml adding the following information
- name: Create Query Database
import_playbook: ../../../external/postgres/playbooks/create-database.yaml
vars:
db_name: database_choosen_by_the_dev_db
As codecov
does not recognises local directories properly, it's needed to add the known_first_party
field to the setup.cfg
. Concretely:
[isort]
known_first_party = src,tests
...
`
Here is the updated Dockerfile
:
FROM ghcr.io/clariteia/minos:0.1.5 as development
COPY ./pyproject.toml ./poetry.lock ./
RUN poetry install --no-root
COPY . .
CMD ["poetry", "run", "microservice", "start"]
FROM development as build
RUN poetry export --without-hashes > req.txt && pip wheel -r req.txt --wheel-dir ./dist
RUN poetry build --format wheel
FROM python:3.9-slim as production
COPY --from=build /microservice/dist/ ./dist
RUN pip install --no-deps ./dist/*
COPY ./config.yml ./config.yml
ENTRYPOINT ["microservice"]
CMD ["start"]
Hi have add locust from:
poetry add locust
and i will get the following error
Because no versions of flask match >2.0.0,<2.0.1 || >2.0.1,<2.0.2 || >2.0.2
and flask (2.0.0) depends on Jinja2 (>=3.0), flask (>=2.0.0,<2.0.1 || >2.0.1,<2.0.2 || >2.0.2) requires Jinja2 (>=3.0).
And because flask (2.0.1) depends on Jinja2 (>=3.0)
and flask (2.0.2) depends on Jinja2 (>=3.0), flask (>=2.0.0) requires Jinja2 (>=3.0).
Because no versions of locust match >2.7.3,<3.0.0
and locust (2.7.3) depends on flask (>=2.0.0), locust (>=2.7.3,<3.0.0) requires flask (>=2.0.0).
Thus, locust (>=2.7.3,<3.0.0) requires Jinja2 (>=3.0).
And because copier (5.1.0) depends on jinja2 (>=2.11.2,<3.0.0)
and no versions of copier match >5.1.0,<6.0.0, locust (>=2.7.3,<3.0.0) is incompatible with copier (>=5.1.0,<6.0.0).
And because minos-cli (0.1.1) depends on copier (>=5.1.0,<6.0.0)
and no versions of minos-cli match >0.1.1,<0.2.0, locust (>=2.7.3,<3.0.0) is incompatible with minos-cli (>=0.1.1,<0.2.0).
So, because ecommerceexample depends on both minos-cli (^0.1.1) and locust (^2.7.3), version solving failed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.