Git Product home page Git Product logo

flask-microservice's Introduction

Python Flask Microservice

Python Versions

This image comes in two varieties depending on what Python version you require.

  • 2.7, 2, latest
  • 3.6, 3

Rapid Development

docker run -d -v /path/to/project:/app -p 80:80 relvacode/flask-microservice

All dependencies will be installed on start-up and uWSGI will automatically reload the Python application after a change is detected (20 second interval).

ONBUIILD

Use this in your Dockerfile:

FROM relvacode/flask-microservice

When your image is built it will add the build context to /app and install any apt and pip dependencies during build time. This is the recommended method for production deployments.

Stack Overview

  • Ubuntu 18.04
  • Python
  • NGINX
    • Proxy the Python application on /api
    • Serve static files from /app/static
  • uWSGI
    • Serves Python application in /app/app/api.py

Default Packages

Python Packages

  • flask
  • flask-restful
  • uwsgi

Ubuntu Packages

  • nginx
  • python-pip
  • python-setuptools

Application Folder Structure

The home directory where applications are served is /app. Under this directory your application should have this folder structure

  • /app
    • app/ - This is where your Python code goes
      • api.py - Your main flask application file
    • static/ - Your static content such as .html, .js, .css files
    • requirements.apt - apt requirements, separated by newline
    • requirements.pip - pip requirements, separated by newline

Environment Variables

UWSGI_ENTRYPOINT

This sets what Python file/module in /app/app to serve using uWSGI. Do not include the file extension. Defaults to api which equates to /app/app/api.py

UWSGI_APPLICATION

This sets what variable inside UWSGI_ENTRYPOINT points to the the uWSGI (Flask) application. Defaults to app.

UWSGI_CHDIR

Change to this directory before loading the Python application. Defaults to /app/app.

Flask

To enable error logging of application errors to the container log you should add the PROPAGATE_EXCEPTIONS parameter to the Flask configuration.

from flask import Flask
app = Flask(__name__)
app.config['PROPAGATE_EXCEPTIONS'] = True

flask-microservice's People

Contributors

jkingsburyilmn avatar relvacode avatar

Watchers

 avatar  avatar  avatar

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.