Git Product home page Git Product logo

minos-cli's People

Contributors

albamig avatar andrea-mucci avatar restyled-commits avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

xmonader genfild

minos-cli's Issues

Put the name in lowecase for deployment and docker build

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

Add command for QueryService Repository

The minos cli must have the following command

minos queryservice set repository

this command must ask:

  • which database? ( at the moment we support sqlalchemy as ORM, so we have to propose mysql/postgresql/sqlite )
  • database host
  • database port
  • database name

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

Delete `init` command

Since new command now creates microservices in the appropriate directory, init is no longer needed.

Trace the error en print on the command line

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

problem when i install another package like for example Locust

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.
  

Update `Dockerfile` to latest version

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"]

Create microservices' database dynamically

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.

Refactor command structure

Refactor command structure to a verb-based one.

Instead of minos project|microservice init use minos init project|microservice, etc.

Fix bug related with `isort` and `codecov`

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
...
`

reformat session instance in query service Repository

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.