GithubHelp home page GithubHelp logo

python-microservices / microservices-scaffold Goto Github PK

View Code? Open in Web Editor NEW
167.0 12.0 45.0 966 KB

Barebone Python Microservices with Flask

Home Page: https://python-microservices.github.io/scaffold/

License: GNU General Public License v3.0

Python 90.07% Dockerfile 6.49% Makefile 3.44%
python3 microservices microservice-example barebones-python-microservices microservices-scaffold python-microservices pyms python flask hacktoberfest

microservices-scaffold's People

Contributors

alexppg avatar astagi avatar avara1986 avatar eftakhairul avatar felipem775 avatar jmrivas86 avatar michaelloewenstein avatar mohansha avatar purwowd avatar pyup-bot avatar rapejim avatar vmjelicic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

microservices-scaffold's Issues

Migrate tests.sh to Makefile

Migrate tests.sh

#!/bin/sh
coverage erase
tox
coverage combine
coverage report -m
coverage html
pylint project/* > pylintReport.txt

to a Makefile, in example:

linter:
    pylint project/* > pylintReport.txt
test: 
    export CONFIGMAP_FILE=tests/config-tests.yml
    pytest
coverage: 
    coverage erase
    pytest ...
    coverage combine

Docker image failed to run gunicorn.errors.HaltServer

Hi,

I'm trying to run your app in a docker container given your instructions, but it fails at run step.

The full run log is as below, you can see the error in the last line as well.

[2020-08-10 15:04:34 +0000] [1] [INFO] Starting gunicorn 19.7.1
[2020-08-10 15:04:34 +0000] [1] [INFO] Listening at: http://0.0.0.0:5000 (1)
[2020-08-10 15:04:34 +0000] [1] [INFO] Using worker: sync
[2020-08-10 15:04:34 +0000] [8] [INFO] Booting worker with pid: 8
[2020-08-10 15:04:34 +0000] [9] [INFO] Booting worker with pid: 9
[2020-08-10 15:04:34 +0000] [10] [INFO] Booting worker with pid: 10
[2020-08-10 15:04:34 +0000] [18] [INFO] Booting worker with pid: 18
[2020-08-10 15:04:34 +0000] [27] [INFO] Booting worker with pid: 27
[2020-08-10 15:04:34 +0000] [31] [INFO] Booting worker with pid: 31
[2020-08-10 15:04:34 +0000] [33] [INFO] Booting worker with pid: 33
[2020-08-10 15:04:34 +0000] [38] [INFO] Booting worker with pid: 38
ERROR:connexion.apis.abstract:Failed to add operation for POST /template/actors
[2020-08-10 15:04:38 +0000] [8] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 209, in add_paths
    self.add_operation(path, method)
  File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 173, in add_operation
    pass_context_arg_name=self.pass_context_arg_name
  File "/usr/local/lib/python3.6/site-packages/connexion/operations/__init__.py", line 8, in make_operation
    return spec.operation_cls.from_spec(spec, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/connexion/operations/swagger2.py", line 137, in from_spec
    **kwargs
  File "/usr/local/lib/python3.6/site-packages/connexion/operations/swagger2.py", line 96, in __init__
    pass_context_arg_name=pass_context_arg_name
  File "/usr/local/lib/python3.6/site-packages/connexion/operations/abstract.py", line 96, in __init__
    self._resolution = resolver.resolve(self)
  File "/usr/local/lib/python3.6/site-packages/connexion/resolver.py", line 40, in resolve
    return Resolution(self.resolve_function_from_operation_id(operation_id), operation_id)
  File "/usr/local/lib/python3.6/site-packages/connexion/resolver.py", line 64, in resolve_function_from_operation_id
    raise ResolverError(msg, sys.exc_info())
connexion.exceptions.ResolverError: <ResolverError: Cannot resolve operationId "project.actors.post"! Import error was "No module named 'project.actors'">

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 126, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.6/site-packages/gunicorn/util.py", line 352, in import_app
    __import__(module)
  File "/microservice/manage.py", line 6, in <module>
    app = create_app()
  File "/microservice/project/app.py", line 82, in create_app
    return ms.create_app()
  File "/usr/local/lib/python3.6/site-packages/pyms/flask/app/create_app.py", line 214, in create_app
    self.application = self.init_app()
  File "/usr/local/lib/python3.6/site-packages/pyms/flask/app/create_app.py", line 179, in init_app
    application = self.swagger.init_app(config=self.config.to_flask(), path=self.path)
  File "/usr/local/lib/python3.6/site-packages/pyms/flask/services/swagger.py", line 76, in init_app
    app.add_api(**params)
  File "/usr/local/lib/python3.6/site-packages/connexion/apps/flask_app.py", line 57, in add_api
    api = super(FlaskApp, self).add_api(specification, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/connexion/apps/abstract.py", line 156, in add_api
    options=api_options.as_dict())
  File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 111, in __init__
    self.add_paths()
  File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 216, in add_paths
    self._handle_add_operation_error(path, method, err.exc_info)
  File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 231, in _handle_add_operation_error
    raise value.with_traceback(traceback)
  File "/usr/local/lib/python3.6/site-packages/connexion/resolver.py", line 61, in resolve_function_from_operation_id
    return self.function_resolver(operation_id)
  File "/usr/local/lib/python3.6/site-packages/connexion/utils.py", line 123, in get_function_from_name
    raise last_import_error
  File "/usr/local/lib/python3.6/site-packages/connexion/utils.py", line 111, in get_function_from_name
    module = importlib.import_module(module_name)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'project.actors'
[2020-08-10 15:04:38 +0000] [8] [INFO] Worker exiting (pid: 8)
ERROR:connexion.apis.abstract:Failed to add operation for POST /template/actors
[2020-08-10 15:04:38 +0000] [9] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 209, in add_paths
    self.add_operation(path, method)
  File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 173, in add_operation
    pass_context_arg_name=self.pass_context_arg_name
  File "/usr/local/lib/python3.6/site-packages/connexion/operations/__init__.py", line 8, in make_operation
    return spec.operation_cls.from_spec(spec, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/connexion/operations/swagger2.py", line 137, in from_spec
    **kwargs
  File "/usr/local/lib/python3.6/site-packages/connexion/operations/swagger2.py", line 96, in __init__
    pass_context_arg_name=pass_context_arg_name
  File "/usr/local/lib/python3.6/site-packages/connexion/operations/abstract.py", line 96, in __init__
    self._resolution = resolver.resolve(self)
  File "/usr/local/lib/python3.6/site-packages/connexion/resolver.py", line 40, in resolve
    return Resolution(self.resolve_function_from_operation_id(operation_id), operation_id)
  File "/usr/local/lib/python3.6/site-packages/connexion/resolver.py", line 64, in resolve_function_from_operation_id
    raise ResolverError(msg, sys.exc_info())
connexion.exceptions.ResolverError: <ResolverError: Cannot resolve operationId "project.actors.post"! Import error was "No module named 'project.actors'">

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 126, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.6/site-packages/gunicorn/util.py", line 352, in import_app
    __import__(module)
  File "/microservice/manage.py", line 6, in <module>
    app = create_app()
  File "/microservice/project/app.py", line 82, in create_app
    return ms.create_app()
  File "/usr/local/lib/python3.6/site-packages/pyms/flask/app/create_app.py", line 214, in create_app
    self.application = self.init_app()
  File "/usr/local/lib/python3.6/site-packages/pyms/flask/app/create_app.py", line 179, in init_app
    application = self.swagger.init_app(config=self.config.to_flask(), path=self.path)
  File "/usr/local/lib/python3.6/site-packages/pyms/flask/services/swagger.py", line 76, in init_app
    app.add_api(**params)
  File "/usr/local/lib/python3.6/site-packages/connexion/apps/flask_app.py", line 57, in add_api
    api = super(FlaskApp, self).add_api(specification, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/connexion/apps/abstract.py", line 156, in add_api
    options=api_options.as_dict())
  File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 111, in __init__
    self.add_paths()
  File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 216, in add_paths
    self._handle_add_operation_error(path, method, err.exc_info)
  File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 231, in _handle_add_operation_error
    raise value.with_traceback(traceback)
  File "/usr/local/lib/python3.6/site-packages/connexion/resolver.py", line 61, in resolve_function_from_operation_id
    return self.function_resolver(operation_id)
  File "/usr/local/lib/python3.6/site-packages/connexion/utils.py", line 123, in get_function_from_name
    raise last_import_error
  File "/usr/local/lib/python3.6/site-packages/connexion/utils.py", line 111, in get_function_from_name
    module = importlib.import_module(module_name)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'project.actors'
[2020-08-10 15:04:38 +0000] [9] [INFO] Worker exiting (pid: 9)
ERROR:connexion.apis.abstract:Failed to add operation for POST /template/actors
[2020-08-10 15:04:38 +0000] [10] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 209, in add_paths
    self.add_operation(path, method)
  File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 173, in add_operation
    pass_context_arg_name=self.pass_context_arg_name
  File "/usr/local/lib/python3.6/site-packages/connexion/operations/__init__.py", line 8, in make_operation
    return spec.operation_cls.from_spec(spec, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/connexion/operations/swagger2.py", line 137, in from_spec
    **kwargs
  File "/usr/local/lib/python3.6/site-packages/connexion/operations/swagger2.py", line 96, in __init__
    pass_context_arg_name=pass_context_arg_name
  File "/usr/local/lib/python3.6/site-packages/connexion/operations/abstract.py", line 96, in __init__
    self._resolution = resolver.resolve(self)
  File "/usr/local/lib/python3.6/site-packages/connexion/resolver.py", line 40, in resolve
    return Resolution(self.resolve_function_from_operation_id(operation_id), operation_id)
  File "/usr/local/lib/python3.6/site-packages/connexion/resolver.py", line 64, in resolve_function_from_operation_id
    raise ResolverError(msg, sys.exc_info())
connexion.exceptions.ResolverError: <ResolverError: Cannot resolve operationId "project.actors.post"! Import error was "No module named 'project.actors'">

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 126, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.6/site-packages/gunicorn/util.py", line 352, in import_app
    __import__(module)
  File "/microservice/manage.py", line 6, in <module>
    app = create_app()
  File "/microservice/project/app.py", line 82, in create_app
    return ms.create_app()
  File "/usr/local/lib/python3.6/site-packages/pyms/flask/app/create_app.py", line 214, in create_app
    self.application = self.init_app()
  File "/usr/local/lib/python3.6/site-packages/pyms/flask/app/create_app.py", line 179, in init_app
    application = self.swagger.init_app(config=self.config.to_flask(), path=self.path)
  File "/usr/local/lib/python3.6/site-packages/pyms/flask/services/swagger.py", line 76, in init_app
    app.add_api(**params)
  File "/usr/local/lib/python3.6/site-packages/connexion/apps/flask_app.py", line 57, in add_api
    api = super(FlaskApp, self).add_api(specification, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/connexion/apps/abstract.py", line 156, in add_api
    options=api_options.as_dict())
  File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 111, in __init__
    self.add_paths()
  File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 216, in add_paths
    self._handle_add_operation_error(path, method, err.exc_info)
  File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 231, in _handle_add_operation_error
    raise value.with_traceback(traceback)
  File "/usr/local/lib/python3.6/site-packages/connexion/resolver.py", line 61, in resolve_function_from_operation_id
    return self.function_resolver(operation_id)
  File "/usr/local/lib/python3.6/site-packages/connexion/utils.py", line 123, in get_function_from_name
    raise last_import_error
  File "/usr/local/lib/python3.6/site-packages/connexion/utils.py", line 111, in get_function_from_name
    module = importlib.import_module(module_name)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'project.actors'
[2020-08-10 15:04:38 +0000] [10] [INFO] Worker exiting (pid: 10)
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 209, in run
    self.sleep()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 359, in sleep
    ready = select.select([self.PIPE[0]], [], [], 1.0)
  File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 244, in handle_chld
    self.reap_workers()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 524, in reap_workers
    raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/gunicorn", line 8, in <module>
    sys.exit(run())
  File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
    WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/app/base.py", line 203, in run
    super(Application, self).run()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/app/base.py", line 72, in run
    Arbiter(self).run()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 231, in run
    self.halt(reason=inst.reason, exit_status=inst.exit_status)
  File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 344, in halt
    self.stop()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 393, in stop
    time.sleep(0.1)
  File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 244, in handle_chld
    self.reap_workers()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 524, in reap_workers
    raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

Python and pip updated. Appreciate your help.

Wrong DB connection string in docker config

Describe the bug
There is a wrong DB connection string in the docker config resulting in an empty model (e.g [])

To Reproduce
Steps to reproduce the behavior:

  1. Run the app using docker
  2. Go to http://127.0.0.1:5000/films
  3. Expected output is a json containing a list of films but the list is empty.

Expected behavior
Expected output is a json containing a list of films but the list is empty.

Desktop (please complete the following information):

  • OS: macOS
  • Browser: Chrome
  • Version: NA

Screen Shot 2020-10-02 at 18 36 45

Increment type hints and add mypy

Add more Python type hints and add mypy valitations. This validation could be a step in GH actions or tox

You can learn more about type hints in this link

Mypy has a command line checker:

mypy pyms

Ideally, mypy must return 0 errors, but could be a hard work because pyms create dynamic attributes.

Support Black

  • Check black Formatter
  • Add the config in setup.cfg, see this link
  • Update documentation (CONTRIBUTIND and Docs) with "how to use black"
  • Use pre-commit, hooks... or the method that you want to run automatically Black

Docker image not building

Describe the bug
Docker image keeps failing to build

To Reproduce
Steps to reproduce the behavior:

  1. Download or clone project
  2. In the root directory of the project (where the Dockerfile is located), run docker build . or docker build ./ to build a docker image
  3. It throws an error when it gets to the the step RUN cd /tmp && pipenv install --system: An error occurred while installing cryptography==3.4.7; python_version >= '3.6'...

Expected behavior
Docker image should build without any errors

Screenshots
Screenshot 2021-07-22 at 23 02 23

Desktop (please complete the following information):

  • OS: MAC OS, Catalina, 10.15

Additional context
None.

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.