Преглед на файлове

Deployment updates - Heroku, Docker, Gunicorn

Adi Chirilov преди 5 години
родител
ревизия
f9fc81d431
променени са 11 файла, в които са добавени 79 реда и са изтрити 48 реда
  1. 4 4
      Dockerfile
  2. 1 1
      Procfile
  3. 58 9
      README.md
  4. 5 1
      app/base/templates/login/login.html
  5. 2 2
      docker-compose.yml
  6. 2 2
      gunicorn-cfg.py
  7. 2 2
      nginx/appseed-app.conf
  8. 1 0
      requirements-pgsql.txt
  9. 0 1
      requirements.txt
  10. 4 1
      run.py
  11. 0 25
      wsgi.py

+ 4 - 4
Dockerfile

@@ -2,11 +2,11 @@ FROM python:3.6
 
 ENV FLASK_APP run.py
 
-COPY run.py gunicorn.py requirements-sqlite.txt config.py .env ./
+COPY run.py gunicorn-cfg.py requirements.txt config.py .env ./
 COPY app app
 COPY migrations migrations
 
-RUN pip install -r requirements-sqlite.txt
+RUN pip install -r requirements.txt
 
-EXPOSE 5000
-CMD ["gunicorn", "--config", "gunicorn.py", "run:app"]
+EXPOSE 5005
+CMD ["gunicorn", "--config", "gunicorn-cfg.py", "run:app"]

+ 1 - 1
Procfile

@@ -1 +1 @@
-web: gunicorn wsgi:app --log-file=-
+web: gunicorn run:app --log-file=- 

+ 58 - 9
README.md

@@ -52,13 +52,12 @@ $
 $ # Virtualenv modules installation (Windows based systems)
 $ # virtualenv --no-site-packages env
 $ # .\env\Scripts\activate
-$ 
-$ # Install modules
-$ # SQLIte version (no PostgreSQL)
-$ pip3 install -r requirements-sqlite.txt
-$ 
+$
+$ # Install modules - SQLite Database
+$ pip3 install -r requirements.txt
+$
 $ # OR with PostgreSQL connector
-$ pip install -r requirements.txt
+$ # pip install -r requirements-pgsql.txt
 $
 $ # Set the FLASK_APP environment variable
 $ (Unix/Mac) export FLASK_APP=run.py
@@ -80,9 +79,16 @@ $ # Access the dashboard in browser: http://127.0.0.1:5000/
 
 <br />
 
-## Docker execution
+## Deployment
 
-The application can be easily excuted in a docker container. The steps:
+The app is provided with a basic configuration to be executed in [Docker](https://www.docker.com/), [Gunicorn](https://gunicorn.org/), and [Waitress](https://docs.pylonsproject.org/projects/waitress/en/stable/).
+
+<br />
+
+### [Docker](https://www.docker.com/) execution
+---
+
+The application can be easily executed in a docker container. The steps:
 
 > Get the code
 
@@ -97,7 +103,50 @@ $ cd flask-material-dashboard
 $ sudo docker-compose pull && sudo docker-compose build && sudo docker-compose up -d
 ```
 
-Visit `http://localhost:5000` in your browser. The app should be up & running.
+Visit `http://localhost:5005` in your browser. The app should be up & running. 
+
+<br />
+
+### [Gunicorn](https://gunicorn.org/)
+---
+
+Gunicorn 'Green Unicorn' is a Python WSGI HTTP Server for UNIX.
+
+> Install using pip
+
+```bash
+$ pip install gunicorn
+```
+> Start the app using gunicorn binary
+
+```bash
+$ gunicorn --bind 0.0.0.0:8001 run:app
+Serving on http://localhost:8001
+```
+
+Visit `http://localhost:8001` in your browser. The app should be up & running.
+
+
+<br />
+
+### [Waitress](https://docs.pylonsproject.org/projects/waitress/en/stable/)
+---
+
+Waitress (Gunicorn equivalent for Windows) is meant to be a production-quality pure-Python WSGI server with very acceptable performance. It has no dependencies except ones that live in the Python standard library.
+
+> Install using pip
+
+```bash
+$ pip install waitress
+```
+> Start the app using [waitress-serve](https://docs.pylonsproject.org/projects/waitress/en/stable/runner.html)
+
+```bash
+$ waitress-serve --port=8001 run:app
+Serving on http://localhost:8001
+```
+
+Visit `http://localhost:8001` in your browser. The app should be up & running.
 
 <br />
 

+ 5 - 1
app/base/templates/login/login.html

@@ -22,7 +22,11 @@
                       {% if msg %}
                         <span class="text-danger">{{ msg | safe }}</span>
                       {% else %}
-                        Sign in to continue
+                      <span>
+                        Use default credentials: test / pass
+                        <br />
+                        OR <a href={{ url_for('base_blueprint.create_user') }} >create your own user</a>
+                      </span>
                       {% endif %}  
                   </h6>
                 </div>

+ 2 - 2
docker-compose.yml

@@ -5,7 +5,7 @@ services:
     env_file: .env
     build: .
     ports:
-      - "5000:5000"
+      - "5005:5005"
     networks:
       - db_network
       - web_network
@@ -13,7 +13,7 @@ services:
     restart: always
     image: "nginx:latest"
     ports:
-      - "80:80"
+      - "85:85"
     volumes:
       - ./nginx:/etc/nginx/conf.d
     networks:

+ 2 - 2
gunicorn.py → gunicorn-cfg.py

@@ -1,10 +1,10 @@
 # -*- encoding: utf-8 -*-
 """
-License: MIT
+License: Commercial
 Copyright (c) 2019 - present AppSeed.us
 """
 
-bind = '0.0.0.0:5000'
+bind = '0.0.0.0:5005'
 workers = 1
 accesslog = '-'
 loglevel = 'debug'

+ 2 - 2
nginx/appseed-app.conf

@@ -1,8 +1,8 @@
 server {
-    listen      80;
+    listen      85;
 
     location / {
-        proxy_pass http://localhost:5000/;
+        proxy_pass http://localhost:5005/;
         proxy_set_header Host $host;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     }

+ 1 - 0
requirements-sqlite.txt → requirements-pgsql.txt

@@ -4,3 +4,4 @@ flask_migrate
 flask_wtf
 flask_sqlalchemy
 gunicorn
+psycopg2

+ 0 - 1
requirements.txt

@@ -4,4 +4,3 @@ flask_migrate
 flask_wtf
 flask_sqlalchemy
 gunicorn
-psycopg2

+ 4 - 1
run.py

@@ -1,6 +1,6 @@
 # -*- encoding: utf-8 -*-
 """
-License: MIT
+License: Commercial
 Copyright (c) 2019 - present AppSeed.us
 """
 
@@ -20,3 +20,6 @@ except KeyError:
 
 app = create_app(config_mode) 
 Migrate(app, db)
+
+if __name__ == "__main__":
+    app.run()

+ 0 - 25
wsgi.py

@@ -1,25 +0,0 @@
-# -*- encoding: utf-8 -*-
-"""
-License: MIT
-Copyright (c) 2019 - present AppSeed.us
-"""
-
-from flask_migrate import Migrate
-from os import environ
-from sys import exit
-
-from config import config_dict
-from app import create_app, db
-
-get_config_mode = environ.get('APPSEED_CONFIG_MODE', 'Debug')
-
-try:
-    config_mode = config_dict[get_config_mode.capitalize()]
-except KeyError:
-    exit('Error: Invalid APPSEED_CONFIG_MODE environment variable entry.')
-
-if __name__ == "__main__":
-    app = create_app(config_mode) 
-    Migrate(app, db)
-    app.run()
-