Another huge batch of registry v2 changes
Add patch support and resumeable sha Implement all actual registry methods Add a simple database generation option
This commit is contained in:
parent
5ba3521e67
commit
e1b3e9e6ae
29 changed files with 1095 additions and 430 deletions
27
initdb.py
27
initdb.py
|
@ -4,6 +4,7 @@ import hashlib
|
|||
import random
|
||||
import calendar
|
||||
import os
|
||||
import argparse
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from peewee import (SqliteDatabase, create_model_tables, drop_model_tables, savepoint_sqlite,
|
||||
|
@ -87,9 +88,16 @@ def __create_subtree(repo, structure, creator_username, parent, tag_map):
|
|||
creation_time = REFERENCE_DATE + timedelta(weeks=image_num) + timedelta(days=model_num)
|
||||
command_list = SAMPLE_CMDS[image_num % len(SAMPLE_CMDS)]
|
||||
command = json.dumps(command_list) if command_list else None
|
||||
|
||||
v1_metadata = {
|
||||
'id': docker_image_id,
|
||||
}
|
||||
if parent is not None:
|
||||
v1_metadata['parent'] = parent.docker_image_id
|
||||
|
||||
new_image = model.image.set_image_metadata(docker_image_id, repo.namespace_user.username,
|
||||
repo.name, str(creation_time), 'no comment', command,
|
||||
parent)
|
||||
v1_metadata, parent)
|
||||
|
||||
compressed_size = random.randrange(1, 1024 * 1024 * 1024)
|
||||
model.image.set_image_size(docker_image_id, repo.namespace_user.username, repo.name,
|
||||
|
@ -324,7 +332,7 @@ def wipe_database():
|
|||
drop_model_tables(all_models, fail_silently=True)
|
||||
|
||||
|
||||
def populate_database():
|
||||
def populate_database(minimal=False):
|
||||
logger.debug('Populating the DB with test data.')
|
||||
|
||||
new_user_1 = model.user.create_user('devtable', 'password', 'jschorr@devtable.com')
|
||||
|
@ -332,6 +340,10 @@ def populate_database():
|
|||
new_user_1.stripe_id = TEST_STRIPE_ID
|
||||
new_user_1.save()
|
||||
|
||||
if minimal:
|
||||
logger.debug('Skipping most db population because user requested mininal db')
|
||||
return
|
||||
|
||||
disabled_user = model.user.create_user('disabled', 'password', 'jschorr+disabled@devtable.com')
|
||||
disabled_user.verified = True
|
||||
disabled_user.enabled = False
|
||||
|
@ -380,7 +392,8 @@ def populate_database():
|
|||
'to_date': formatdate(calendar.timegm(to_date.utctimetuple())),
|
||||
'reason': 'database migration'
|
||||
}
|
||||
model.notification.create_notification('maintenance', new_user_1, metadata=notification_metadata)
|
||||
model.notification.create_notification('maintenance', new_user_1,
|
||||
metadata=notification_metadata)
|
||||
|
||||
|
||||
__generate_repository(new_user_4, 'randomrepo', 'Random repo repository.', False,
|
||||
|
@ -618,7 +631,12 @@ def populate_database():
|
|||
while repositoryactioncounter.count_repository_actions():
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='Initialize the test database.')
|
||||
parser.add_argument('--simple', action='store_true')
|
||||
args = parser.parse_args()
|
||||
|
||||
log_level = getattr(logging, app.config['LOGGING_LEVEL'])
|
||||
logging.basicConfig(level=log_level)
|
||||
|
||||
|
@ -627,5 +645,4 @@ if __name__ == '__main__':
|
|||
|
||||
initialize_database()
|
||||
|
||||
if app.config.get('POPULATE_DB_TEST_DATA', False):
|
||||
populate_database()
|
||||
populate_database(args.simple)
|
||||
|
|
Reference in a new issue