Harvest commands from the Docker json information and add to the database.
This commit is contained in:
parent
5918082e6d
commit
e23c750bfb
6 changed files with 38 additions and 8 deletions
|
@ -167,6 +167,7 @@ class Image(BaseModel):
|
|||
checksum = CharField(null=True)
|
||||
created = DateTimeField(null=True)
|
||||
comment = TextField(null=True)
|
||||
command = TextField(null=True)
|
||||
repository = ForeignKeyField(Repository)
|
||||
image_size = BigIntegerField(null=True)
|
||||
|
||||
|
|
|
@ -727,7 +727,7 @@ def set_image_size(docker_image_id, namespace_name, repository_name, image_size)
|
|||
|
||||
|
||||
def set_image_metadata(docker_image_id, namespace_name, repository_name,
|
||||
created_date_str, comment, parent=None):
|
||||
created_date_str, comment, command, parent=None):
|
||||
joined = Image.select().join(Repository)
|
||||
image_list = list(joined.where(Repository.name == repository_name,
|
||||
Repository.namespace == namespace_name,
|
||||
|
@ -739,6 +739,7 @@ def set_image_metadata(docker_image_id, namespace_name, repository_name,
|
|||
fetched = image_list[0]
|
||||
fetched.created = dateutil.parser.parse(created_date_str)
|
||||
fetched.comment = comment
|
||||
fetched.command = command
|
||||
|
||||
if parent:
|
||||
fetched.ancestors = '%s%s/' % (parent.ancestors, parent.id)
|
||||
|
|
|
@ -334,8 +334,10 @@ def put_image_json(namespace, repository, image_id):
|
|||
else:
|
||||
parent_obj = None
|
||||
|
||||
command_list = data.get('container_config', {}).get('Cmd', None)
|
||||
command = json.dumps(command_list) if command_list else None
|
||||
model.set_image_metadata(image_id, namespace, repository,
|
||||
data.get('created'), data.get('comment'),
|
||||
data.get('created'), data.get('comment'), command,
|
||||
parent_obj)
|
||||
store.put_content(mark_path, 'true')
|
||||
store.put_content(json_path, request.data)
|
||||
|
|
18
initdb.py
18
initdb.py
|
@ -1,12 +1,9 @@
|
|||
import logging
|
||||
import string
|
||||
import shutil
|
||||
import os
|
||||
import json
|
||||
import hashlib
|
||||
import random
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from flask import url_for
|
||||
from peewee import SqliteDatabase, create_model_tables, drop_model_tables
|
||||
|
||||
from data.database import *
|
||||
|
@ -19,6 +16,12 @@ store = app.config['STORAGE']
|
|||
|
||||
SAMPLE_DIFFS = ['test/data/sample/diffs/diffs%s.json' % i
|
||||
for i in range(1, 10)]
|
||||
SAMPLE_CMDS = [['/bin/bash'],
|
||||
["/bin/sh", "-c",
|
||||
"echo \"PasswordAuthentication no\" >> /etc/ssh/sshd_config"],
|
||||
["/bin/sh", "-c",
|
||||
"sed -i 's/#\\(force_color_prompt\\)/\\1/' /etc/skel/.bashrc"],
|
||||
None]
|
||||
|
||||
REFERENCE_DATE = datetime(2013, 6, 23)
|
||||
TEST_STRIPE_ID = 'cus_2tmnh3PkXQS8NG'
|
||||
|
@ -52,11 +55,14 @@ def __create_subtree(repo, structure, parent):
|
|||
model.set_image_checksum(docker_image_id, repo, checksum)
|
||||
|
||||
creation_time = REFERENCE_DATE + timedelta(days=image_num)
|
||||
command_list = SAMPLE_CMDS[image_num % len(SAMPLE_CMDS)]
|
||||
command = json.dumps(command_list) if command_list else None
|
||||
new_image = model.set_image_metadata(docker_image_id, repo.namespace,
|
||||
repo.name, str(creation_time),
|
||||
'no comment', parent)
|
||||
'no comment', command, parent)
|
||||
|
||||
model.set_image_size(docker_image_id, repo.namespace, repo.name, random.randrange(1, 1024 * 1024 * 1024))
|
||||
model.set_image_size(docker_image_id, repo.namespace, repo.name,
|
||||
random.randrange(1, 1024 * 1024 * 1024))
|
||||
|
||||
# Populate the diff file
|
||||
diff_path = store.image_file_diffs_path(repo.namespace, repo.name,
|
||||
|
|
Binary file not shown.
20
tools/backfill_commands.py
Normal file
20
tools/backfill_commands.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from data.database import Image
|
||||
from app import app
|
||||
import json
|
||||
|
||||
|
||||
store = app.config['STORAGE']
|
||||
|
||||
|
||||
for image in Image.select():
|
||||
if image.command == None:
|
||||
image_json_path = store.image_json_path(image.repository.namespace,
|
||||
image.repository.name,
|
||||
image.docker_image_id)
|
||||
if store.exists(image_json_path):
|
||||
data = json.loads(store.get_content(image_json_path))
|
||||
command_list = data.get('container_config', {}).get('Cmd', None)
|
||||
command = json.dumps(command_list) if command_list else None
|
||||
print 'Setting command to: %s' % command
|
||||
image.command = command
|
||||
image.save()
|
Reference in a new issue