This commit is contained in:
Joseph Schorr 2013-10-01 00:41:52 -04:00
commit b7d43e1593
10 changed files with 184 additions and 115 deletions

View file

@ -36,3 +36,5 @@ container_commands:
option_settings:
"aws:elasticbeanstalk:container:python:staticfiles":
"/static": "static/"
"aws:elasticbeanstalk:application:environment":
"STACK": "prod"

8
app.py
View file

@ -1,13 +1,17 @@
import logging
import os
from flask import Flask
from flask.ext.principal import Principal
from flask.ext.login import LoginManager
from flask.ext.mail import Mail
from config import ProductionConfig
from config import ProductionConfig, DebugConfig
app = Flask(__name__)
app.config.from_object(ProductionConfig())
is_prod = os.environ.get('STACK', '').strip().lower().startswith('prod')
config_object = ProductionConfig() if is_prod else DebugConfig()
app.config.from_object(config_object)
logger = logging.getLogger(__name__)

View file

@ -11,9 +11,7 @@ import endpoints.registry
# Remove this for prod config
application.debug = True
if __name__ == '__main__':
FORMAT = '%(asctime)-15s - %(levelname)s - %(pathname)s - ' + \
'%(funcName)s - %(message)s'
logging.basicConfig(format=FORMAT, level=logging.DEBUG)
logging.basicConfig(**application.config['LOGGING_CONFIG'])
if __name__ == '__main__':
application.run(port=5001, debug=True)

View file

@ -1,3 +1,13 @@
import logging
import sys
from peewee import MySQLDatabase, SqliteDatabase
LOG_FORMAT = '%(asctime)-15s - %(levelname)s - %(pathname)s - ' + \
'%(funcName)s - %(message)s'
class FlaskConfig(object):
SECRET_KEY = '1cb18882-6d12-440d-a4cc-b7430fb5f884'
@ -13,5 +23,49 @@ class MailConfig(object):
TESTING = False
class ProductionConfig(FlaskConfig, MailConfig):
class SQLiteDB(object):
DB_NAME = 'test.db'
DB_CONNECTION_ARGS = {
'threadlocals': True
}
DB_DRIVER = SqliteDatabase
class RDSMySQL(object):
DB_NAME = 'quay'
DB_CONNECTION_ARGS = {
'host': 'fluxmonkeylogin.cb0vumcygprn.us-east-1.rds.amazonaws.com',
'user': 'fluxmonkey',
'passwd': '8eifM#uoZ85xqC^',
'threadlocals': True,
}
DB_DRIVER = MySQLDatabase
class S3Storage(object):
AWS_ACCESS_KEY = 'AKIAJWZWUIS24TWSMWRA'
AWS_SECRET_KEY = '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'
REGISTRY_S3_BUCKET = 'quay-registry'
STORAGE_KIND = 's3'
class LocalStorage(object):
STORAGE_KIND = 'local'
LOCAL_STORAGE_DIR = '/tmp/registry'
class DebugConfig(FlaskConfig, MailConfig, LocalStorage, SQLiteDB):
REGISTRY_SERVER = 'localhost:5000'
LOGGING_CONFIG = {
'level': logging.DEBUG,
'format': LOG_FORMAT
}
class ProductionConfig(FlaskConfig, MailConfig, S3Storage, RDSMySQL):
REGISTRY_SERVER = 'quay.io'
LOGGING_CONFIG = {
'stream': sys.stderr,
'level': logging.DEBUG,
'format': LOG_FORMAT,
}

View file

@ -1,12 +1,15 @@
import string
from random import SystemRandom
from random import SystemRandom
from datetime import datetime
from peewee import *
from peewee import create_model_tables
from datetime import datetime
from app import app
db = SqliteDatabase('test.db', threadlocals=True)
db = app.config['DB_DRIVER'](app.config['DB_NAME'],
**app.config['DB_CONNECTION_ARGS'])
class BaseModel(Model):
@ -29,7 +32,7 @@ class Repository(BaseModel):
namespace = CharField()
name = CharField()
visibility = ForeignKeyField(Visibility)
description = CharField(null=True)
description = TextField(null=True)
class Meta:
database = db
@ -86,11 +89,11 @@ class Image(BaseModel):
image_id = CharField()
checksum = CharField(null=True)
created = DateTimeField(null=True)
comment = CharField(null=True)
comment = TextField(null=True)
repository = ForeignKeyField(Repository)
# '/' separated list of ancestory ids, e.g. /1/2/6/7/10/
ancestors = CharField(index=True, default='/', max_length=65535)
ancestors = CharField(index=True, default='/', max_length=64535)
class Meta:
database = db

View file

@ -112,9 +112,7 @@ def get_visible_repositories(username=None):
def get_matching_repositories(repo_term, username=None):
visible = get_visible_repositories(username)
search_clauses = (Repository.name ** ('%' + repo_term + '%') |
Repository.namespace ** ('%' + repo_term + '%') |
Repository.description ** ('%' + repo_term + '%'))
Repository.namespace ** ('%' + repo_term + '%'))
final = visible.where(search_clauses).limit(10)
return list(final)

View file

@ -6,3 +6,4 @@ Flask-Login
Flask-Mail
python-dateutil
boto
pymysql

View file

@ -4,11 +4,11 @@ Flask-Mail==0.9.0
Flask-Principal==0.4.0
Jinja2==2.7.1
MarkupSafe==0.18
PyMySQL==0.5
Werkzeug==0.9.4
argparse==1.2.1
blinker==1.3
boto==2.13.3
distribute==0.6.34
itsdangerous==0.23
peewee==2.1.4
py-bcrypt==0.4

View file

@ -1,9 +1,13 @@
import logging
import contextlib
import tempfile
from app import app
__all__ = ['load']
logger = logging.getLogger(__name__)
class Storage(object):
@ -128,15 +132,19 @@ def load(kind=None):
global _storage
# TODO hard code to local for now
kind = 'local'
kind = app.config['STORAGE_KIND']
# if not kind:
# kind = cfg.storage.lower()
if kind in _storage:
return _storage[kind]
if kind == 's3':
store = S3Storage('/registry', 'access_key', 'secret_key', 'bucket')
logger.debug('Using s3 storage.')
store = S3Storage('', app.config['AWS_ACCESS_KEY'],
app.config['AWS_SECRET_KEY'],
app.config['REGISTRY_S3_BUCKET'])
elif kind == 'local':
store = LocalStorage('/tmp/registry')
logger.debug('Using local storage.')
store = LocalStorage(app.config['LOCAL_STORAGE_DIR'])
else:
raise ValueError('Not supported storage \'{0}\''.format(kind))
_storage[kind] = store

View file

@ -3,6 +3,7 @@ LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonHome /opt/python/run/venv
WSGISocketPrefix run/wsgi
WSGIRestrictEmbedded On
WSGIPassAuthorization On
<VirtualHost *:80>