2016-02-20 14:57:26 +02:00
|
|
|
from flask import Flask
|
|
|
|
from flask_sqlalchemy import SQLAlchemy
|
2016-03-19 21:37:48 +02:00
|
|
|
from flask_bootstrap import Bootstrap
|
|
|
|
from flask.ext import login as flask_login
|
2016-02-20 14:57:26 +02:00
|
|
|
|
2016-02-20 21:11:59 +02:00
|
|
|
import os
|
2016-04-20 22:37:17 +02:00
|
|
|
import docker
|
2016-02-20 14:57:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Create application
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
2016-02-20 21:11:59 +02:00
|
|
|
default_config = {
|
2016-03-20 16:36:56 +02:00
|
|
|
'SQLALCHEMY_DATABASE_URI': 'sqlite:////data/freeposte.db',
|
2016-02-20 21:11:59 +02:00
|
|
|
'SQLALCHEMY_TRACK_MODIFICATIONS': False,
|
2016-04-20 22:37:17 +02:00
|
|
|
'SECRET_KEY': 'changeMe',
|
|
|
|
'DOCKER_SOCKET': 'unix:///var/run/docker.sock',
|
2016-02-24 08:44:49 +02:00
|
|
|
'DEBUG': False
|
2016-02-20 21:11:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Load configuration from the environment if available
|
|
|
|
for key, value in default_config.items():
|
|
|
|
app.config[key] = os.environ.get(key, value)
|
|
|
|
|
2016-03-20 16:36:56 +02:00
|
|
|
# Setup components
|
2016-03-19 21:37:48 +02:00
|
|
|
Bootstrap(app)
|
2016-02-20 14:57:26 +02:00
|
|
|
db = SQLAlchemy(app)
|
2016-03-19 21:37:48 +02:00
|
|
|
login_manager = flask_login.LoginManager()
|
|
|
|
login_manager.init_app(app)
|
|
|
|
|
2016-04-20 22:37:17 +02:00
|
|
|
# Connect to the Docker socket
|
|
|
|
dockercli = docker.Client(base_url=app.config['DOCKER_SOCKET'])
|
|
|
|
|
2016-03-20 16:36:56 +02:00
|
|
|
# Finally setup the blueprint
|
|
|
|
from freeposte import admin
|
|
|
|
app.register_blueprint(admin.app, url_prefix='/admin')
|