Coder Social home page Coder Social logo

darian-heede / webapp-template-python Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 521 KB

Webapp template using docker-compose with python flask, nginx and mongoDB

License: ISC License

Dockerfile 3.19% Python 26.61% CSS 29.72% HTML 34.40% Shell 3.07% JavaScript 3.02%

webapp-template-python's Introduction

webapp-template-python

Webapp template using docker-compose with python flask, nginx and mongoDB.

Use case

This docker-compose project can be used as a template for different web applications. The services included are an nginx webserver, a mongo database and an python/Flask template app, which can be built upon. The implemented use of gunicorn make the webapp non-blocking.

Prerequisites

Simple exemplary flask webapp is included

Main webapp is located at app/app.py with html files located at app/templates and resources located in app/static. The app shows a simple page that adds a tile with access information on every refresh. This information is saved in and queried from the included mongoDB.

Preparing app for containerization

The app/requirements.txt file containing all necessary python packages is mounted by volume and run on entry.

Creating an app based on this template

An app can be built by using the generated python/Flask foundation. By using docker-compose with mongoDB and nginx, the app will have an integrated database it can call upon as well as a complete webserver proxy to host the app.

The template is fairly flexible and may be adjusted to the needs required by the app.

App debugging

Keep the mongoDB data within the container by commenting out a line within the docker-compose.yml that mounts a volume containing the data:

volumes:
  - ./mongodb/database/data:/data/db

This prevents testing data from being written to disk, including configurations such as user permissions that may change and lead to unexpected behaviour while developing.

The app is run in debug mode, which means that any change is instantly integrated without needing to reboot the app. The debug handle and other app related variables are set within app/.env.

When run locally the mongoDB can be accessed by using compass and the user information provided within mongodb/.env or mongodb/.init.js.

Omit --detach option when building the containers.

The template is set up as to reach the app at localhost.

nginx configuration

nginx configurations can be done using the nginx/nginx.conf-file. SSL certificates are expected per default and can be added into nginx/ssl. Generate self signed RSA certificates for testing purposes using openSSL:

sudo mkdir nginx/ssl
cd nginx/ssl

# Generate key pair
sudo openssl req -new -x509 -nodes -newkey rsa:4096 -keyout server.key -out server.crt

# Set correct key permissions
sudo chmod 400 server.key
sudo chmod 444 server.crt

Building the docker container

docker-compose up --build --detach

Stop and remove docker-compose containers

sudo docker-compose stop app nginx mongodb
sudo docker-compose rm app nginx mongodb

webapp-template-python's People

Contributors

darian-heede 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.