exclude sizes and hash from image definition, typo fixes

This commit is contained in:
Disassembler 2020-02-19 23:11:53 +01:00
parent e32a76e174
commit 8a39528773
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499
8 changed files with 27 additions and 32 deletions

View File

@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import argparse
import os
import sys
from spoc import repo_local
@ -21,12 +22,12 @@ def get_image_name(file_path):
return line.split()[1]
return None
def listing(repo_type):
if repo_type == 'installed':
def listing(list_type):
if list_type == 'installed':
images = repo_local.get_images()
elif repo_type == 'online':
elif list_type == 'online':
images = repo_online.get_images()
elif repo_type == 'published':
elif list_type == 'published':
images = repo_publish.get_images()
for image in images:
print(image)
@ -78,7 +79,7 @@ def build(filename, force, do_publish):
image_name = get_image_name(filename)
if force or image_name not in repo_local.get_images():
image = Image(image_name, False)
print(f'Building image {image_name} from file {filename}')
print(f'Building image {image_name} from file {os.path.abspath(filename)}')
image.delete()
image.create(ImageBuilder(), filename)
print(f'Image {image_name} built successfully')
@ -95,8 +96,8 @@ def publish(image_name, force):
image = Image(image_name)
print(f'Publishing image {image_name}')
image.unpublish()
image.publish()
print(f'Image {image_name} compressed from {readable_size(image.size)} to {readable_size(image.dlsize)} and published successfully')
size, dlsize = image.publish()
print(f'Image {image_name} compressed from {readable_size(size)} to {readable_size(dlsize)} and published successfully')
else:
print(f'Image {image_name} already published, skipping publish task')
@ -126,7 +127,7 @@ parser_build = subparsers.add_parser('build')
parser_build.set_defaults(action=build)
parser_build.add_argument('-f', '--force', action='store_true', help='Force rebuild already existing image')
parser_build.add_argument('-p', '--publish', action='store_true', help='Publish the image after successful build')
parser_build.add_argument('file')
parser_build.add_argument('filename')
parser_publish = subparsers.add_parser('publish')
parser_publish.set_defaults(action=publish)
@ -148,7 +149,7 @@ elif args.action is delete:
elif args.action is clean:
clean()
elif args.action is build:
build(args.file, args.force, args.publish)
build(args.filename, args.force, args.publish)
elif args.action is publish:
publish(args.image, args.force)
elif args.action is unpublish:

View File

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
import time
from concurrent.futures import ThreadPoolExecutor
from math import floor

View File

@ -7,7 +7,6 @@ import shlex
import shutil
import subprocess
import time
from concurrent.futures import ThreadPoolExecutor
from . import network

View File

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
import fcntl
from contextlib import contextmanager
def locked_ex(lock_file):

View File

@ -11,7 +11,7 @@ from . import repo_online
from . import repo_publish
from .config import LAYERS_DIR, PUB_LAYERS_DIR, ONLINE_LAYERS_URL, TMP_LAYERS_DIR
DEFINITION_MEMBERS = {'layers', 'env', 'uid', 'gid', 'cmd', 'cwd', 'ready', 'halt', 'size', 'dlsize', 'hash'}
DEFINITION_MEMBERS = {'layers', 'env', 'uid', 'gid', 'cmd', 'cwd', 'ready', 'halt'}
class Image:
def __init__(self, name, load_from_repo=True):
@ -25,9 +25,6 @@ class Image:
self.cwd = None
self.ready = None
self.halt = None
self.size = None
self.dlsize = None
self.hash = None
if load_from_repo:
self.set_definition(repo_local.get_image(name))
@ -65,10 +62,12 @@ class Image:
archive_path = os.path.join(PUB_LAYERS_DIR, f'{self.name}.tar.xz')
with tarfile.open(archive_path, 'w:xz') as tar:
tar.add(self.layer_path, self.name, filter=files.add_file)
self.size = files.size
self.dlsize = os.path.getsize(archive_path)
self.hash = repo_publish.sign_file(archive_path).hex()
repo_publish.register_image(self.name, self.get_definition())
definition = self.get_definition()
definition['size'] = files.size
definition['dlsize'] = os.path.getsize(archive_path)
definition['hash'] = repo_publish.sign_file(archive_path).hex()
repo_publish.register_image(self.name, definition)
return (definition['size'], definition['dlsize'])
def unpublish(self):
repo_publish.unregister_image(self.name)

View File

@ -79,12 +79,12 @@ def get_apps():
def get_app(app_name):
try:
return get_entry(TYPE_APP, image_name)
return get_entry(TYPE_APP, app_name)
except KeyError as e:
raise ImageNotFoundError(image_name) from e
raise ImageNotFoundError(app_name) from e
def register_app(app_name, definition):
add_entry(TYPE_APP, image_name, definition)
add_entry(TYPE_APP, app_name, definition)
def unregister_app(app_name):
delete_entry(TYPE_APP, image_name)
delete_entry(TYPE_APP, app_name)

View File

@ -8,7 +8,6 @@ import requests
import tarfile
import tempfile
import time
from cryptography.exceptions import InvalidSignature
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
@ -113,6 +112,6 @@ def get_apps():
def get_app(app_name):
try:
return get_entry(TYPE_APP, image_name)
return get_entry(TYPE_APP, app_name)
except KeyError as e:
raise ImageNotFoundError(image_name) from e
raise ImageNotFoundError(app_name) from e

View File

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
import json
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import ec, utils
@ -94,12 +93,12 @@ def get_apps():
def get_app(app_name):
try:
return get_entry(TYPE_APP, image_name)
return get_entry(TYPE_APP, app_name)
except KeyError as e:
raise ImageNotFoundError(image_name) from e
raise ImageNotFoundError(app_name) from e
def register_app(app_name, definition):
add_entry(TYPE_APP, image_name, definition)
add_entry(TYPE_APP, app_name, definition)
def unregister_app(app_name):
delete_entry(TYPE_APP, image_name)
delete_entry(TYPE_APP, app_name)