forked from alectrocute/flaskSaaS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docker deployment with Nginx+Gunicorn example. manage.py script. Mult…
…iple config files. More Flask extensions.
- Loading branch information
1 parent
65ea777
commit 80c124c
Showing
29 changed files
with
398 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.db | ||
*.log | ||
*.pyc | ||
.git/ | ||
config.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.pyc | ||
*.db | ||
*webassets* | ||
*.log | ||
*.pyc | ||
config.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[FORMAT] | ||
max-line-length=100 | ||
indent-string=' ' | ||
|
||
[REPORTS] | ||
files-output=no | ||
reports=yes | ||
evaluation=10 - ((float(5 * error + warning + refactor + convention) / statement) * 10) | ||
|
||
[TYPECHECK] | ||
ignored-modules=flask_sqlalchemy | ||
ignored-classes=SQLObject,SQLAlchemy,Base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
FROM phusion/baseimage:0.9.19 | ||
|
||
# Use baseimage-docker's init system. | ||
CMD ["/sbin/my_init"] | ||
|
||
ENV TERM=xterm-256color | ||
|
||
# Set the locale | ||
RUN locale-gen en_US.UTF-8 | ||
ENV LANG en_US.UTF-8 | ||
ENV LANGUAGE en_US:en | ||
ENV LC_ALL en_US.UTF-8 | ||
|
||
# Install necessary packages | ||
RUN apt-get update && apt-get install -y \ | ||
build-essential \ | ||
python3-pip | ||
|
||
# Install Python requirements | ||
RUN mkdir -p /usr/src/app | ||
COPY requirements.txt /usr/src/app/ | ||
RUN pip3 install --upgrade pip | ||
RUN pip3 install -r /usr/src/app/requirements.txt | ||
|
||
# Copy the files from the host to the container | ||
COPY . /usr/src/app | ||
WORKDIR /usr/src/app | ||
RUN chmod 777 -R * | ||
|
||
# Clean up | ||
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Makefile | ||
|
||
## Configuration | ||
|
||
BUILD_TIME := $(shell date +%FT%T%z) | ||
PROJECT := $(shell basename $(PWD)) | ||
|
||
|
||
## Install dependencies | ||
.PHONY: install | ||
install: | ||
pip install -r requirements.txt | ||
|
||
## Setup developpement environment | ||
.PHONY: dev | ||
dev: | ||
cd app && ln -sf config_dev.py config.py | ||
|
||
## Setup production environment | ||
.PHONY: prod | ||
prod: | ||
cd app && ln -sf config_prod.py config.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os.path as op | ||
|
||
from flask import request, Response | ||
from werkzeug.exceptions import HTTPException | ||
from flask_admin import Admin | ||
from flask.ext.admin.contrib.sqla import ModelView | ||
from flask.ext.admin.contrib.fileadmin import FileAdmin | ||
|
||
from app import app, db | ||
from app.models import User | ||
|
||
|
||
admin = Admin(app, name='Admin', template_mode='bootstrap3') | ||
|
||
class ModelView(ModelView): | ||
|
||
def is_accessible(self): | ||
auth = request.authorization or request.environ.get('REMOTE_USER') # workaround for Apache | ||
if not auth or (auth.username, auth.password) != app.config['ADMIN_CREDENTIALS']: | ||
raise HTTPException('', Response('You have to an administrator.', 401, | ||
{'WWW-Authenticate': 'Basic realm="Login Required"'} | ||
)) | ||
return True | ||
|
||
# Users | ||
admin.add_view(ModelView(User, db.session)) | ||
|
||
# Static files | ||
path = op.join(op.dirname(__file__), 'static') | ||
admin.add_view(FileAdmin(path, '/static/', name='Static')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
# DEBUG has to be to False in a production enrironment for security reasons | ||
DEBUG = True | ||
TIMEZONE = 'Europe/Paris' | ||
|
||
# Secret key for generating tokens | ||
SECRET_KEY = 'houdini' | ||
|
||
# Admin credentials | ||
ADMIN_CREDENTIALS = ('admin', 'pa$$word') | ||
|
||
# Database choice | ||
SQLALCHEMY_DATABASE_URI = 'sqlite:///app.db' | ||
SQLALCHEMY_TRACK_MODIFICATIONS = True | ||
|
||
# Configuration of a Gmail account for sending mails | ||
MAIL_SERVER = 'smtp.googlemail.com' | ||
MAIL_PORT = 465 | ||
|
@@ -15,5 +18,6 @@ | |
MAIL_USERNAME = 'flask.boilerplate' | ||
MAIL_PASSWORD = 'flaskboilerplate123' | ||
ADMINS = ['[email protected]'] | ||
|
||
# Number of times a password is hashed | ||
BCRYPT_LOG_ROUNDS = 12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import logging | ||
|
||
from app.config_common import * | ||
|
||
|
||
# DEBUG can only be set to True in a development environment for security reasons | ||
DEBUG = True | ||
|
||
# Secret key for generating tokens | ||
SECRET_KEY = 'houdini' | ||
|
||
# Admin credentials | ||
ADMIN_CREDENTIALS = ('admin', 'pa$$word') | ||
|
||
# Database choice | ||
SQLALCHEMY_DATABASE_URI = 'sqlite:///app.db' | ||
SQLALCHEMY_TRACK_MODIFICATIONS = True | ||
|
||
# Configuration of a Gmail account for sending mails | ||
MAIL_SERVER = 'smtp.googlemail.com' | ||
MAIL_PORT = 465 | ||
MAIL_USE_TLS = False | ||
MAIL_USE_SSL = True | ||
MAIL_USERNAME = 'flask.boilerplate' | ||
MAIL_PASSWORD = 'flaskboilerplate123' | ||
ADMINS = ['[email protected]'] | ||
|
||
# Number of times a password is hashed | ||
BCRYPT_LOG_ROUNDS = 12 | ||
|
||
LOG_LEVEL = logging.DEBUG | ||
LOG_FILENAME = 'activity.log' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import logging | ||
|
||
from app.config_common import * | ||
|
||
|
||
# DEBUG has to be to False in a production environment for security reasons | ||
DEBUG = False | ||
|
||
# Secret key for generating tokens | ||
SECRET_KEY = 'houdini' | ||
|
||
# Admin credentials | ||
ADMIN_CREDENTIALS = ('admin', 'pa$$word') | ||
|
||
# Database choice | ||
SQLALCHEMY_DATABASE_URI = 'sqlite:///app.db' | ||
SQLALCHEMY_TRACK_MODIFICATIONS = True | ||
|
||
# Configuration of a Gmail account for sending mails | ||
MAIL_SERVER = 'smtp.googlemail.com' | ||
MAIL_PORT = 465 | ||
MAIL_USE_TLS = False | ||
MAIL_USE_SSL = True | ||
MAIL_USERNAME = 'flask.boilerplate' | ||
MAIL_PASSWORD = 'flaskboilerplate123' | ||
ADMINS = ['[email protected]'] | ||
|
||
# Number of times a password is hashed | ||
BCRYPT_LOG_ROUNDS = 12 | ||
|
||
LOG_LEVEL = logging.INFO | ||
LOG_FILENAME = 'activity.log' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.