Beispiel #1
0
def create_app(config_class=None):
    app = Flask(__name__)
    app.config.from_object(config_class)

    init_logging()

    if os.getenv("FLASK_ENV") == "development":
        app = register_teardown_request(app)

    # Create the database if it does not exist yet. Roughly equal to
    # a "CREATE DATABASE IF NOT EXISTS <db_name>" call.
    if not database_exists(app.config["SQLALCHEMY_DATABASE_URI"]):
        create_database(app.config["SQLALCHEMY_DATABASE_URI"])

    db.init_app(app)
    # necessary for migration
    Migrate().init_app(app, db)

    with app.app_context():
        # Upgrade to the latest revision. This also takes care of
        # bringing an "empty" db (no tables) on par.
        upgrade()

    register_views(app)

    return app
Beispiel #2
0
def create_app(config_class=None):
    app = Flask(__name__)
    app.config.from_object(config_class)

    register_views(app)

    return app
Beispiel #3
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(CONFIG_CLASS)

    register_views(app)

    return app
Beispiel #4
0
def create_app(config_class=None):
    app = Flask(__name__)
    app.config.from_object(config_class)

    # Initialize the database and create the database file.
    db.init_app(app)
    with app.app_context():
        db.create_all()

    register_views(app)

    return app
Beispiel #5
0
def create_app(*config_cls):
    flask_app = Flask(__name__)
    register_views(flask_app)

    for config in config_cls:
        flask_app.config.from_object(config)

    connect(**flask_app.config['MONGODB_SETTINGS'])

    JWTManager().init_app(flask_app)
    CORS(flask_app)

    return flask_app
Beispiel #6
0
def create_app():

    logging.basicConfig(stream=sys.stdout, level=logging.INFO)

    app = Flask(__name__)
    app.config.from_object(CONFIG_CLASS)

    # read directory mount based config into Flask config
    try:
        with open("/config/config.json", 'r') as f:
            conf_data = json.load(f)
            app.config.update(conf_data)
    except Exception as e:
        logging.warning("Failed to load config.json")

    logging.info("Flask CONFIG: %s" % app.config)

    db.init_app(app)
    # db.create_all()

    # static file serving
    @app.route('/public/<path:path>')
    def send_files(path):
        return send_from_directory("../static", path)

    register_views(app, db)

    if "TELEMETRY_DISABLED" not in app.config:
        # create thread for analytics
        scheduler = BackgroundScheduler()

        # send a ping now
        analytics_ping(app)

        # and every 15 minutes
        scheduler.add_job(analytics_ping, 'interval', minutes=15, args=[app])
        scheduler.start()

    # Start threaded file_permission_watcher
    # TODO: reconsider file permission approach
    # Note: process is never cleaned up, this is permissible because it's only
    # executed inside a container.
    file_dir = os.path.dirname(os.path.realpath(__file__))
    permission_process = Popen([
        "python3",
        os.path.join(file_dir, "scripts/file_permission_watcher.py"),
        app.config["USER_DIR"]
    ])

    return app
def create_app(config_name=None):
    if config_name is None:
        config_name = os.getenv('FLASK_CONFIG', 'development')

    app = Flask(__name__)

    config_obj = config[config_name]
    app.config.from_object(config_obj)
    config_obj.init_app(app)

    register_extensions(app)
    register_views(app)
    register_commands(app)
    config_oauth(app)

    return app
Beispiel #8
0
def create_app(config_class=None, to_migrate_db=False):
    """Create the Flask app and return it.

    Args:
        to_migrate_db: If True, then only initialize the db.

    Returns:
        Flask.app
    """
    app = Flask(__name__)
    app.config.from_object(config_class)

    if not to_migrate_db:
        orchest_config = requests.get(
            f"http://{CONFIG_CLASS.ORCHEST_API_ADDRESS}/api/ctl/orchest-settings"
        ).json()
        app.config.update(orchest_config)

    init_logging()

    if os.getenv("FLASK_ENV") == "development":
        app = register_teardown_request(app)

    # Create the database if it does not exist yet. Roughly equal to
    # a "CREATE DATABASE IF NOT EXISTS <db_name>" call.
    if not database_exists(app.config["SQLALCHEMY_DATABASE_URI"]):
        create_database(app.config["SQLALCHEMY_DATABASE_URI"])

    db.init_app(app)
    # necessary for migration
    Migrate().init_app(app, db)

    # NOTE: In this case we want to return ASAP as otherwise the DB
    # might be called (inside this function) before it is migrated.
    if to_migrate_db:
        return app

    register_views(app)

    return app
Beispiel #9
0
def create_app(config='Base', instance=True):
    app = Flask(__name__, instance_relative_config=instance)

    # Base Configuration
    app.config.from_object('app.config.' + config)

    # Load the instance configuration if True
    app.config.from_pyfile('config.py', silent=True)

    # Load from env
    app.config.from_envvar('FLASKR_SETTINGS', silent=True)

    # CSRF
    csrf = CSRFProtect()
    csrf.init_app(app)

    db.init_app(app)
    user_datastore = get_datastore(db)
    app.security = Security(app, user_datastore)

    # Register views
    register_views(app)

    @app.before_first_request
    def init_db():
        try:
            get_users()
        except:
            from app.models import init_db
            init_db(user_datastore)

    @app.route('/', methods=['GET'])
    @login_required
    @roles_required('user')
    def index():
        return render_template('dashboard.html')

    return app
Beispiel #10
0
def create_app():

    logging.basicConfig(stream=sys.stdout, level=logging.INFO)

    app = Flask(__name__)
    app.config.from_object(CONFIG_CLASS)

    socketio = SocketIO(app, cors_allowed_origins="*")
    logging.getLogger("engineio").setLevel(logging.ERROR)

    # read directory mount based config into Flask config
    try:
        conf_data = get_user_conf()
        app.config.update(conf_data)
    except Exception as e:
        logging.warning("Failed to load config.json")

    logging.info("Flask CONFIG: %s" % app.config)

    db.init_app(app)

    # according to SQLAlchemy will only create tables if they do not exist
    with app.app_context():
        db.create_all()

        initialize_default_images(db)
        initialize_default_datasources(db, app)

        logging.info("Initializing kernels")
        populate_kernels(app, db)

    # static file serving
    @app.route("/public/<path:path>")
    def send_files(path):
        return send_from_directory("../static", path)

    register_views(app, db)
    register_build_views(app, db, socketio)
    register_socketio_broadcast(db, socketio)

    if ("TELEMETRY_DISABLED" not in app.config
            and os.environ.get("FLASK_ENV") != "development"):
        # create thread for analytics
        scheduler = BackgroundScheduler()

        # send a ping now
        analytics_ping(app)

        # and every 15 minutes
        scheduler.add_job(
            analytics_ping,
            "interval",
            minutes=app.config["TELEMETRY_INTERVAL"],
            args=[app],
        )
        scheduler.start()

    processes = []

    if process_start_gate():

        file_dir = os.path.dirname(os.path.realpath(__file__))

        # TODO: reconsider file permission approach
        # file_permission_watcher process
        permission_process = Popen(
            [
                "python3",
                "-m",
                "scripts.file_permission_watcher",
                app.config["USER_DIR"],
            ],
            cwd=os.path.join(file_dir, ".."),
            stderr=subprocess.STDOUT,
        )
        logging.info("Started file_permission_watcher.py")
        processes.append(permission_process)

        # docker_builder process
        docker_builder_process = Popen(
            ["python3", "-m", "scripts.docker_builder"],
            cwd=os.path.join(file_dir, ".."),
            stderr=subprocess.STDOUT,
        )
        logging.info("Started docker_builder.py")
        processes.append(docker_builder_process)

        # log_streamer process
        log_streamer_process = Popen(
            ["python3", "-m", "scripts.log_streamer"],
            cwd=os.path.join(file_dir, ".."),
            stderr=subprocess.STDOUT,
        )

        logging.info("Started log_streamer.py")
        processes.append(log_streamer_process)

    return app, socketio, processes
Beispiel #11
0
def create_app():

    logging.basicConfig(stream=sys.stdout, level=logging.INFO)

    app = Flask(__name__)
    app.config.from_object(CONFIG_CLASS)

    socketio = SocketIO(app, cors_allowed_origins="*")

    # read directory mount based config into Flask config
    try:
        conf_data = get_user_conf()
        app.config.update(conf_data)
    except Exception as e:
        logging.warning("Failed to load config.json")

    logging.info("Flask CONFIG: %s" % app.config)

    db.init_app(app)

    # according to SQLAlchemy will only create tables if they do not exist
    with app.app_context():
        db.create_all()

        initialize_default_images(db)

        logging.info("Initializing kernels")
        populate_kernels(app, db)

    # static file serving
    @app.route('/public/<path:path>')
    def send_files(path):
        return send_from_directory("../static", path)

    register_views(app, db)
    register_build_views(app, db, socketio)

    if "TELEMETRY_DISABLED" not in app.config:
        # create thread for analytics
        scheduler = BackgroundScheduler()

        # send a ping now
        analytics_ping(app)

        # and every 15 minutes
        scheduler.add_job(analytics_ping,
                          'interval',
                          minutes=app.config["TELEMETRY_INTERVAL"],
                          args=[app])
        scheduler.start()

    # Start threaded file_permission_watcher
    # TODO: reconsider file permission approach
    # Note: process is never cleaned up, this is permissible because it's only
    # executed inside a container.

    watcher_file = "/tmp/file_permission_watcher_active"

    # guarantee no two python file permission watchers are started
    if not os.path.isfile(watcher_file):
        with open(watcher_file, "w") as file:
            file.write("1")

        file_dir = os.path.dirname(os.path.realpath(__file__))
        permission_process = Popen([
            os.path.join(file_dir, "scripts", "file_permission_watcher.py"),
            app.config["USER_DIR"]
        ])

        logging.info("Started file_permission_watcher.py")

    return app, socketio