Skip to content

Commit bc7c958

Browse files
committed
Merge branch 'master' into develop
2 parents ed7b5d7 + 72d58fe commit bc7c958

31 files changed

+128
-258
lines changed

.coveragerc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[run]
22
include=
33
*project/*
4-
*pyms/*
54
omit =
65
venv/*

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ sudo: false
33
cache: false
44
python:
55
- '3.6'
6-
6+
addons:
7+
apt:
8+
sources:
9+
- deadsnakes
10+
packages:
11+
- python3.5
12+
- python3.5-dev
713
install:
814
- pip install -rrequirements-tests.txt
915

AUTHORS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Alberto Vara <[email protected]>
2+
Hugo Camino <[email protected]>
3+
José Manuel <[email protected]>

Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
FROM python:3.6.4-alpine3.7
22

3-
RUN apk add --update curl gcc g++ git libffi-dev openssl-dev python3-dev \
3+
RUN apk add --update curl gcc g++ git libffi-dev openssl-dev python3-dev build-base linux-headers \
44
&& rm -rf /var/cache/apk/*
55
RUN ln -s /usr/include/locale.h /usr/include/xlocale.h
66

77
ENV PYTHONUNBUFFERED=1 ENVIRONMENT=pre APP_HOME=/microservice/
8-
RUN mkdir $APP_HOME && adduser -S -D -H python
8+
ENV DATABASE_DIR=database
9+
ENV CONFIGMAP_FILE="$APP_HOME"config-docker.yml
910

11+
RUN mkdir $APP_HOME && adduser -S -D -H python
1012
RUN chown -R python $APP_HOME
1113
WORKDIR $APP_HOME
14+
1215
ADD requirement*.txt $APP_HOME
16+
RUN pip install --upgrade pip
1317
RUN pip install -r requirements-docker.txt
18+
1419
ADD . $APP_HOME
20+
RUN mkdir $DATABASE_DIR
21+
RUN chmod 777 $DATABASE_DIR
1522

1623
EXPOSE 5000
1724
USER python

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Barebones Python Microservices
44
[![Build Status](https://travis-ci.org/python-microservices/microservices-scaffold.svg?branch=master)](https://travis-ci.org/python-microservices/microservices-scaffold)
55
[![Coverage Status](https://coveralls.io/repos/github/python-microservices/microservices-scaffold/badge.svg?branch=master)](https://coveralls.io/github/python-microservices/microservices-scaffold?branch=master)
66
[![Requirements Status](https://requires.io/github/python-microservices/microservices-scaffold/requirements.svg?branch=master)](https://requires.io/github/python-microservices/microservices-scaffold/requirements/?branch=master)
7+
[![Updates](https://pyup.io/repos/github/python-microservices/microservices-scaffold/shield.svg)](https://pyup.io/repos/github/python-microservices/microservices-scaffold/)
8+
[![Python 3](https://pyup.io/repos/github/python-microservices/microservices-scaffold/python-3-shield.svg)](https://pyup.io/repos/github/python-microservices/microservices-scaffold/)
79

810

911

config-docker.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ms:
2+
DEBUG: false
3+
TESTING: false
4+
APP_NAME: Template
5+
APPLICATION_ROOT : /template
6+
SQLALCHEMY_TRACK_MODIFICATIONS: true
7+
SECRET_KEY: "gjr39dkjn344_!67#"
8+
DATABASE: db.sqlite3
9+
SQLALCHEMY_DATABASE_URI: sqlite:////microservice/database/db.sqlite3

config.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ms:
2+
DEBUG: false
3+
TESTING: false
4+
APP_NAME: Template
5+
APPLICATION_ROOT : /template
6+
SQLALCHEMY_TRACK_MODIFICATIONS: true
7+
SECRET_KEY: "gjr39dkjn344_!67#"
8+
DATABASE: db.sqlite3
9+
SQLALCHEMY_DATABASE_URI: sqlite:////microservice/database/db.sqlite3

manage.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,9 @@
33

44
from project import create_app
55

6-
app, db = create_app()
6+
app = create_app()
77

88
manager = Manager(app)
99

10-
11-
@manager.command
12-
def create_db():
13-
"""Creates the db tables."""
14-
db.create_all()
15-
16-
17-
@manager.command
18-
def drop_db():
19-
"""Drops the db tables."""
20-
db.drop_all()
21-
22-
2310
if __name__ == '__main__':
2411
manager.run()

project/__init__.py

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,23 @@
1-
# encoding: utf-8
1+
from pyms.flask.app import Microservice
22

3-
import logging
4-
import os
5-
6-
import connexion
7-
from flask_injector import FlaskInjector
8-
from injector import Injector
9-
10-
from project.config import CONFIG
11-
from pyms.healthcheck import healthcheck_blueprint
12-
from pyms.logger import CustomJsonFormatter
13-
from pyms.models import db
14-
from pyms.tracer.main import TracerModule
3+
from project.models.init_db import db
154

165
__author__ = "Alberto Vara"
176
__email__ = "[email protected]"
18-
__version__ = "0.2"
7+
__version__ = "0.3.1"
198

20-
logger = logging.getLogger('jaeger_tracing')
21-
logger.setLevel(logging.DEBUG)
229

23-
ENVIRONMENT = os.environ.get("ENVIRONMENT", "default")
10+
class MyMicroservice(Microservice):
11+
def init_libs(self, app):
12+
db.init_app(app)
13+
with app.test_request_context():
14+
db.create_all()
2415

2516

2617
def create_app():
2718
"""Initialize the Flask app, register blueprints and intialize all libraries like Swagger, database, the trace system...
2819
return the app and the database objects.
2920
:return:
3021
"""
31-
environment = os.environ.get("ENVIRONMENT", "default")
32-
33-
app = connexion.App(__name__, specification_dir='./swagger/')
34-
# app.app.json_encoder = encoder.JSONEncoder
35-
36-
app.add_api('swagger.yaml',
37-
arguments={'title': 'Swagger Example Project'},
38-
base_path=CONFIG[environment].APPLICATION_ROOT)
39-
40-
application = app.app
41-
application.config.from_object(CONFIG[environment])
42-
db.init_app(application)
43-
44-
# Initialize Blueprints
45-
application.register_blueprint(healthcheck_blueprint)
46-
47-
# Inject Modules
48-
if not application.config["TESTING"] and not application.config["DEBUG"]:
49-
log_handler = logging.StreamHandler()
50-
formatter = CustomJsonFormatter('(timestamp) (level) (name) (module) (funcName) (lineno) (message)')
51-
formatter.add_service_name(application.config["APP_NAME"])
52-
tracer = TracerModule(application)
53-
injector = Injector([tracer])
54-
FlaskInjector(app=application, injector=injector)
55-
formatter.add_trace_span(tracer.tracer)
56-
log_handler.setFormatter(formatter)
57-
application.logger.addHandler(log_handler)
58-
application.logger.setLevel(logging.INFO)
59-
60-
with application.test_request_context():
61-
db.create_all()
62-
63-
return application, db
22+
ms = MyMicroservice(service="ms", path=__file__)
23+
return ms.create_app()

project/config.py

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)