Esempio n. 1
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade

    print 'Running deployment tasks...'

    # Migrate database to latest revision
    print 'Migrating database to latest revison...',
    upgrade()
    print 'done'

    print 'Checking for user roles...',
    Role.insert_roles()
    print 'done'

    print 'Checking for Publisher images...'
    Publisher.set_images()
    print 'done'

    if app.config.get('APP_ENV') in ('prod', 'stag'):
        print 'Uploading Static assets to S3...'
        import flask_s3
        flask_s3.create_all(app)
        print 'done'
    else:
        print 'NOT uploading assets to S3, on dev...'
Esempio n. 2
0
def update_zappa(args):
    # Upload the static files to S3
    print('uploading static files to S3...')
    s3.init_app(app)
    app.config['FLASKS3_BUCKET_NAME'] = 'zappa-veganolia'
    flask_s3.create_all(app)
    os.system('zappa update {0}'.format(args.name))
Esempio n. 3
0
def aws_s3(app):
    try:
        s3.init_app(app)
        flask_s3.create_all(app, put_bucket_acl=False)
    except Exception as e:
        print('---> Something wrong with S3')
        print(e)
Esempio n. 4
0
def create_app():

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

    db.init_app(app)

    app.register_blueprint(mod_api_blueprint)
    app.register_blueprint(mod_site_blueprint)

    s3 = boto3.client(
        's3',
        region_name=app.config['AWS_REGION'],
        aws_access_key_id=app.config['AWS_ACCESS_KEY_ID'],
        config=Config(signature_version='s3v4'),
        aws_secret_access_key=app.config['AWS_SECRET_ACCESS_KEY'])
    app.config['S3'] = s3

    if app.config.get('TESTING') is False:
        flask_s3.create_all(app)

    Swagger(app)
    Markdown(app)
    Gravatar(app)
    return app
Esempio n. 5
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade

    print 'Running deployment tasks...'

    # Migrate database to latest revision
    print 'Migrating database to latest revison...',
    upgrade()
    print 'done'

    print 'Checking for user roles...',
    Role.insert_roles()
    print 'done'

    print 'Checking for Publisher images...'
    Publisher.set_images()
    print 'done'

    if app.config.get('APP_ENV') in ('prod', 'stag'):
        print 'Uploading Static assets to S3...'
        import flask_s3
        flask_s3.create_all(app)
        print 'done'
    else:
        print 'NOT uploading assets to S3, on dev...'
Esempio n. 6
0
    def test__custom_endpoint_is_passed_to_boto(self, mock_boto3):
        flask_s3.create_all(self.app)

        mock_boto3.client.assert_called_once_with("s3",
                        region_name='theregion',
                        aws_access_key_id='thekeyid',
                        aws_secret_access_key='thesecretkey',
                        endpoint_url='https://minio.local:9000/')
Esempio n. 7
0
def s3():
    """ Gather and upload static files to AWS S3"""
    app.config.update(
        FLASKS3_BUCKET_NAME='dev-cdn.wall.ninja',
        FLASKS3_FORCE_MIMETYPE=True,
        FLASKS3_USE_HTTPS=False,
    )

    flask_s3.create_all(app)
Esempio n. 8
0
def _assets2s3(project):
    import flask_s3
    module = import_module(project, True)

    header("Building assets files for project: %s ..." % project)
    print("")
    build_assets(project)

    print("Uploading assets files to S3 ...")
    flask_s3.create_all(module.app)
    print("")
Esempio n. 9
0
def assets2s3():
    """ Upload assets files to S3 """
    import flask_s3

    header("Assets2S3")
    print("")
    print("Building assets files..." )
    build_assets(asm_app)
    print("Uploading assets files to S3 ...")
    flask_s3.create_all(asm_app)
    print("")
Esempio n. 10
0
def _assets2s3(project):

    import flask_s3
    module = import_module(project, True)

    header("Building assets files for project: %s ..." % project)
    print("")
    build_assets(project)

    print("Uploading assets files to S3 ...")
    flask_s3.create_all(module.app)
    print("")
Esempio n. 11
0
def assets2s3(app):
    """ To upload static web assets files to S3"""

    import flask_s3
    module = get_app_serve_module(app)

    _title("Build and  Upload static assets files to S3 ...")
    click.echo("- App: %s " % app)
    click.echo("")

    _buildassets(app)
    flask_s3.create_all(module.app)
Esempio n. 12
0
def upload():
    """
    upload static files to s3

    Return:
        func: call the function if successful or the click help option if unsuccesful
    """
    print('Uploading static files to S3....')

    flask_s3.create_all(app)

    print('Uploaded static files to S3.....')
Esempio n. 13
0
def create_app():

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

    db.init_app(app)

    try:
        # Check connection using database url from config.
        engine = sqlalchemy.create_engine(
            app.config['SQLALCHEMY_DATABASE_URI'])
        engine.connect()
    except Exception as e:
        raise Exception(
            "Failed to connect to the database `%s`.\n"
            "Please set valid uri in the SQLALCHEMY_DATABASE_URI config variable.\n"
            "Original error was:\n"
            "  %s\n" % (app.config['SQLALCHEMY_DATABASE_URI'], str(e)))

    app.register_blueprint(package_blueprint)
    app.register_blueprint(auth_blueprint)
    app.register_blueprint(site_blueprint)
    app.register_blueprint(profile_blueprint)
    app.register_blueprint(search_blueprint)

    s3 = boto3.client(
        's3',
        region_name=app.config['AWS_REGION'],
        aws_access_key_id=app.config['AWS_ACCESS_KEY_ID'],
        config=Config(signature_version='s3v4'),
        aws_secret_access_key=app.config['AWS_SECRET_ACCESS_KEY'])
    app.config['S3'] = s3

    if app.config.get('TESTING') is False:
        flask_s3.create_all(app)

    CORS(app)
    Swagger(app)
    Markdown(app)
    Gravatar(app)

    @app.context_processor
    def populate_context_variable():
        return dict(s3_cdn=get_s3_cdn_prefix(),
                    auth0_client_id=app.config['AUTH0_CLIENT_ID'],
                    auth0_domain=app.config['AUTH0_DOMAIN'])

    return app
Esempio n. 14
0
def upload(env):
    """Uploads static assets to S3."""
    if not env:
        click.echo("Environment must be specified")
        click.Abort()

    with open("zappa_settings.json", "r") as f:
        settings = json.load(f)

    if not settings:
        click.echo("Settings not loaded")
        click.Abort()
        return

    try:
        s3_bucket = settings[env]["s3_bucket"]
        aws_region = settings[env]["aws_region"]
    except AttributeError:
        click.echo("Failed to get details from settings")
        click.Abort()
        return

    session = boto3.Session()
    credentials = session.get_credentials()
    current_credentials = credentials.get_frozen_credentials()

    app.config["FLASKS3_FORCE_MIMETYPE"] = True

    try:
        css_assets.build()

        flask_s3.create_all(
            app,
            user=current_credentials.access_key,
            password=current_credentials.secret_key,
            bucket_name=s3_bucket,
            location=aws_region,
            put_bucket_acl=False,
        )
        click.echo(
            f"Uploaded assets to Bucket https://{s3_bucket}.s3.{aws_region}.amazonaws.com"
        )
    except Exception as e:
        click.echo(f"Failed to upload assets: {e}")
Esempio n. 15
0
def deploy():
    """
    upload static files to s3

    Return:
        func: call the function if successful or the click help option if unsuccesful
    """
    print('Uploading static files to S3....')
    params = {
        'config': {
            'FLASKS3_BUCKET_NAME': 'zappa-ok587zsna',
        },
        'static_folder': './dist/static',
        'static_url_path': '/static'
    }
    app = MyStruct(**params)
    flask_s3.create_all(app)

    print('Uploaded static files to S3.....')
Esempio n. 16
0
"""Use this to upload static content to S3."""

import flask_s3
from search.factory import create_ui_web_app

app = create_ui_web_app()

flask_s3.create_all(app, filepath_filter_regex=r"(base|css|images|js|sass)")
Esempio n. 17
0
def upload_all():
    aws_key = 'AKIAIAPZX3KHMEIAJ74Q'
    aws_secret = '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'

    create_all(app, user=aws_key, password=aws_secret)
Esempio n. 18
0
#!/usr/bin/env python3

import os
import flask_s3

from app import create_app

FLASKS3_FORCE_MIMETYPE = True
app = create_app('production')
flask_s3.create_all(app, os.getenv('AWS_ACCESS_KEY_ID'),
                    os.getenv('AWS_SECRET_ACCESS_KEY'))
print("Uploaded.")
Esempio n. 19
0
def upload_assets():
    flask_s3.create_all(app)
Esempio n. 20
0
import os
import flask_s3
from app import app
flask_s3.create_all(app,
                    user=os.environ['AWS_ACCESS_KEY_ID'],
                    password=os.environ['AWS_SECRET_ACCESS_KEY'],
                    bucket_name=os.environ['S3_BUCKET'])
Esempio n. 21
0
 def test__bucket_acl_not_set(self, mock_boto3):
     flask_s3.create_all(self.app, put_bucket_acl=False)
     self.assertFalse(mock_boto3.client().put_bucket_acl.called,
                      "put_bucket_acl was called!")
Esempio n. 22
0
def upload_all():
    create_all(app, user='******', password='******')
Esempio n. 23
0
 def test__bucket_acl_not_set(self, mock_boto3):
     flask_s3.create_all(self.app, put_bucket_acl=False)
     self.assertFalse(mock_boto3.client().put_bucket_acl.called,
                      "put_bucket_acl was called!")
Esempio n. 24
0
import flask_s3
from application import application

flask_s3.create_all(application)
Esempio n. 25
0
def upload_static():
    create_all(app)
Esempio n. 26
0
def upload_static_to_s3():
    """Uploads static content to S3"""
    import flask_s3
    prod_app = create_app(os.getenv('FLASK_CONFIG') or 'default')
    flask_s3.create_all(prod_app)
Esempio n. 27
0
def s3upload():
    flask_s3.create_all(app)
Esempio n. 28
0
import flask_s3
import sys
import os
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + '/..')
from application import application
import config

application.config['AWS_ACCESS_KEY_ID'] = config.AWS_ACCESS_KEY_ID
application.config['AWS_SECRET_ACCESS_KEY'] = config.AWS_SECRET_ACCESS_KEY
application.config['S3_BUCKET_NAME'] = config.AWS_STORAGE_BUCKET_NAME
s3 = flask_s3.FlaskS3()
s3.init_app(application)
flask_s3.create_all(application)
Esempio n. 29
0
def s3(reset):
    flask_s3.create_all(app)
Esempio n. 30
0
def upload_static(zappa_settings):
    app.config['FLASKS3_BUCKET_NAME'] = zappa_settings.aws_environment_variables['FLASKS3_BUCKET_NAME']
    create_all(app)
Esempio n. 31
0
def upload_static(zappa_settings):
    from flask_s3 import create_all
    app.config['FLASKS3_BUCKET_NAME'] = zappa_settings.aws_environment_variables['FLASKS3_BUCKET_NAME']
    create_all(app)
Esempio n. 32
0
def publish():
    flask_s3.create_all(app)
Esempio n. 33
0
def upload_static_files() -> None:
    """Upload static files to S3."""
    app = create_web_app()
    with app.app_context():
        flask_s3.create_all(app)
Esempio n. 34
0
# -*- coding: utf-8 -*-

import os

from flask.ext.script import Manager
from flask.ext.migrate import Migrate, MigrateCommand

import flask_s3

from app import app, db


app.config.from_object(os.getenv('CONFIG'))

migrate = Migrate(app, db)
manager = Manager(app)

manager.add_command('db', MigrateCommand)

if __name__ == '__main__':
    if app.config['USE_S3']:
        flask_s3.create_all(app)

    manager.run()
Esempio n. 35
0
#!/usr/bin/env python3

import os
import flask_s3

from app import create_app

FLASKS3_FORCE_MIMETYPE = True
app = create_app('production')
flask_s3.create_all(
    app,
    os.getenv('AWS_ACCESS_KEY_ID'),
    os.getenv('AWS_SECRET_ACCESS_KEY')
)
print("Uploaded.")
Esempio n. 36
0
def upload():
    print ('starting file upload to Amazon S3')
    create_all(app)
    #TODO : erase old css files on s3
    print ('done with file upload')
Esempio n. 37
0
def upload_all():
    create_all(app, user='******', password='******')
Esempio n. 38
0
import json
import flask_s3
from food_coop import app

with open('aws_settings.json', 'r') as aws_settings_stream:
    aws_settings = json.loads(aws_settings_stream.read())
# Get Flask_S3 settings
for key, value in aws_settings.iteritems():
    app.config[key] = value

flask_s3.create_all(app)
Esempio n. 39
0
def upload_all():
    create_all(app, user='******', password='******')
Esempio n. 40
0
def publish():
    flask_s3.create_all(app)
Esempio n. 41
0
def main():
    """
    Main entry point for the application
    """

    # CLI arguments
    parser = argparse.ArgumentParser(description='AWS Web Server')
    parser.add_argument('port', metavar='Port', type=int, nargs='?', default=8080, help='port to run the application')
    parser.add_argument('--env', '-e', dest='environment', action='store', default='dev', help='type of environment')
    parser.add_argument('--tornado', '-t', dest='tornado', action='store_true', help='run the server as tornado wsgi')
    parser.add_argument('--ssl', '-s', dest='use_ssl', action='store_true', help='run server with ssl certs')
    parser.add_argument('--ssl-certfile', '-c', dest='ssl_certfile', action='store', default='server.crt', help='ssl certificate file')
    parser.add_argument('--ssl-keyfile', '-k', dest='ssl_keyfile', action='store', default='server.key', help='ssl key file')
    parser.add_argument('--upload-s3', '-s3', dest='upload_s3', action='store_true', help='deploy s3 assets to AWS')
    parser.add_argument('--create-tables', '-ct', dest='create_tables', action='store_true', help='creates dynamodb tables in AWS')
    args = parser.parse_args()

    # Configure logging
    log_level = logging.INFO if args.environment == 'prod' else logging.DEBUG
    logging.basicConfig(format='[%(levelname)s]: %(message)s', level=log_level)

    # Create the app
    logging.info('Creating application environment: %s' % args.environment)
    app = create_app(env=args.environment)

    # Start app in tornado wsgi container
    if args.tornado:

        if HAS_TORNADO:
            try:
                logging.info('Starting Tornado Server on port %d' % args.port)
                if args.use_ssl:
                    ssl_options = {
                        'certfile': os.path.join(args.ssl_certfile), 
                        'keyfile': os.path.join(args.ssl_keyfile)
                    }
                else:
                    ssl_options=None
                
                http_server = HTTPServer(WSGIContainer(app), ssl_options=ssl_options)
                http_server.listen(args.port)
                IOLoop.instance().start()
            except KeyboardInterrupt as e:
                logging.info('Stopping Tornado Server by Ctrl+C')
        else:
            logging.warning('Failed to start Tornado server. Tornado not installed')
    elif args.upload_s3:
        logging.info('Uploading to S3...')
        import flask_s3
        flask_s3.create_all(app)
        logging.info('Upload complete.')
    elif args.create_tables:
        logging.info('Creating Dynamodb Tables')
        from magic.models import create_tables
        create_tables()
        logging.info('Table creation complete')
    else:
        logging.info('Starting Flask Internal (dev) Server')
        app.run(port=args.port)
        logging.info('Stopping Flask Internal (dev) Server')

    logging.info('Shutting down...')
    return 0
Esempio n. 42
0
 def run(self):
     if self.app:
         regex = r'^js\/|^css\/|^imgs\/'
         flask_s3.create_all(self.app, filepath_filter_regex=regex)
def upload_static_assets(cli):
    """Helper function to upload the static assets to S3 in production mode."""
    import flask_s3
    flask_s3.create_all(app)