exclude sizes and hash from image definition, typo fixes
This commit is contained in:
parent
e32a76e174
commit
8a39528773
@ -2,6 +2,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from spoc import repo_local
|
from spoc import repo_local
|
||||||
@ -21,12 +22,12 @@ def get_image_name(file_path):
|
|||||||
return line.split()[1]
|
return line.split()[1]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def listing(repo_type):
|
def listing(list_type):
|
||||||
if repo_type == 'installed':
|
if list_type == 'installed':
|
||||||
images = repo_local.get_images()
|
images = repo_local.get_images()
|
||||||
elif repo_type == 'online':
|
elif list_type == 'online':
|
||||||
images = repo_online.get_images()
|
images = repo_online.get_images()
|
||||||
elif repo_type == 'published':
|
elif list_type == 'published':
|
||||||
images = repo_publish.get_images()
|
images = repo_publish.get_images()
|
||||||
for image in images:
|
for image in images:
|
||||||
print(image)
|
print(image)
|
||||||
@ -78,7 +79,7 @@ def build(filename, force, do_publish):
|
|||||||
image_name = get_image_name(filename)
|
image_name = get_image_name(filename)
|
||||||
if force or image_name not in repo_local.get_images():
|
if force or image_name not in repo_local.get_images():
|
||||||
image = Image(image_name, False)
|
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.delete()
|
||||||
image.create(ImageBuilder(), filename)
|
image.create(ImageBuilder(), filename)
|
||||||
print(f'Image {image_name} built successfully')
|
print(f'Image {image_name} built successfully')
|
||||||
@ -95,8 +96,8 @@ def publish(image_name, force):
|
|||||||
image = Image(image_name)
|
image = Image(image_name)
|
||||||
print(f'Publishing image {image_name}')
|
print(f'Publishing image {image_name}')
|
||||||
image.unpublish()
|
image.unpublish()
|
||||||
image.publish()
|
size, dlsize = image.publish()
|
||||||
print(f'Image {image_name} compressed from {readable_size(image.size)} to {readable_size(image.dlsize)} and published successfully')
|
print(f'Image {image_name} compressed from {readable_size(size)} to {readable_size(dlsize)} and published successfully')
|
||||||
else:
|
else:
|
||||||
print(f'Image {image_name} already published, skipping publish task')
|
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.set_defaults(action=build)
|
||||||
parser_build.add_argument('-f', '--force', action='store_true', help='Force rebuild already existing image')
|
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('-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 = subparsers.add_parser('publish')
|
||||||
parser_publish.set_defaults(action=publish)
|
parser_publish.set_defaults(action=publish)
|
||||||
@ -148,7 +149,7 @@ elif args.action is delete:
|
|||||||
elif args.action is clean:
|
elif args.action is clean:
|
||||||
clean()
|
clean()
|
||||||
elif args.action is build:
|
elif args.action is build:
|
||||||
build(args.file, args.force, args.publish)
|
build(args.filename, args.force, args.publish)
|
||||||
elif args.action is publish:
|
elif args.action is publish:
|
||||||
publish(args.image, args.force)
|
publish(args.image, args.force)
|
||||||
elif args.action is unpublish:
|
elif args.action is unpublish:
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from math import floor
|
from math import floor
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import shlex
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
from . import network
|
from . import network
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import fcntl
|
import fcntl
|
||||||
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
def locked_ex(lock_file):
|
def locked_ex(lock_file):
|
||||||
|
@ -11,7 +11,7 @@ from . import repo_online
|
|||||||
from . import repo_publish
|
from . import repo_publish
|
||||||
from .config import LAYERS_DIR, PUB_LAYERS_DIR, ONLINE_LAYERS_URL, TMP_LAYERS_DIR
|
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:
|
class Image:
|
||||||
def __init__(self, name, load_from_repo=True):
|
def __init__(self, name, load_from_repo=True):
|
||||||
@ -25,9 +25,6 @@ class Image:
|
|||||||
self.cwd = None
|
self.cwd = None
|
||||||
self.ready = None
|
self.ready = None
|
||||||
self.halt = None
|
self.halt = None
|
||||||
self.size = None
|
|
||||||
self.dlsize = None
|
|
||||||
self.hash = None
|
|
||||||
if load_from_repo:
|
if load_from_repo:
|
||||||
self.set_definition(repo_local.get_image(name))
|
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')
|
archive_path = os.path.join(PUB_LAYERS_DIR, f'{self.name}.tar.xz')
|
||||||
with tarfile.open(archive_path, 'w:xz') as tar:
|
with tarfile.open(archive_path, 'w:xz') as tar:
|
||||||
tar.add(self.layer_path, self.name, filter=files.add_file)
|
tar.add(self.layer_path, self.name, filter=files.add_file)
|
||||||
self.size = files.size
|
definition = self.get_definition()
|
||||||
self.dlsize = os.path.getsize(archive_path)
|
definition['size'] = files.size
|
||||||
self.hash = repo_publish.sign_file(archive_path).hex()
|
definition['dlsize'] = os.path.getsize(archive_path)
|
||||||
repo_publish.register_image(self.name, self.get_definition())
|
definition['hash'] = repo_publish.sign_file(archive_path).hex()
|
||||||
|
repo_publish.register_image(self.name, definition)
|
||||||
|
return (definition['size'], definition['dlsize'])
|
||||||
|
|
||||||
def unpublish(self):
|
def unpublish(self):
|
||||||
repo_publish.unregister_image(self.name)
|
repo_publish.unregister_image(self.name)
|
||||||
|
@ -79,12 +79,12 @@ def get_apps():
|
|||||||
|
|
||||||
def get_app(app_name):
|
def get_app(app_name):
|
||||||
try:
|
try:
|
||||||
return get_entry(TYPE_APP, image_name)
|
return get_entry(TYPE_APP, app_name)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
raise ImageNotFoundError(image_name) from e
|
raise ImageNotFoundError(app_name) from e
|
||||||
|
|
||||||
def register_app(app_name, definition):
|
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):
|
def unregister_app(app_name):
|
||||||
delete_entry(TYPE_APP, image_name)
|
delete_entry(TYPE_APP, app_name)
|
||||||
|
@ -8,7 +8,6 @@ import requests
|
|||||||
import tarfile
|
import tarfile
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from cryptography.exceptions import InvalidSignature
|
from cryptography.exceptions import InvalidSignature
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
from cryptography.hazmat.primitives import hashes
|
from cryptography.hazmat.primitives import hashes
|
||||||
@ -113,6 +112,6 @@ def get_apps():
|
|||||||
|
|
||||||
def get_app(app_name):
|
def get_app(app_name):
|
||||||
try:
|
try:
|
||||||
return get_entry(TYPE_APP, image_name)
|
return get_entry(TYPE_APP, app_name)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
raise ImageNotFoundError(image_name) from e
|
raise ImageNotFoundError(app_name) from e
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
from cryptography.hazmat.primitives import hashes
|
from cryptography.hazmat.primitives import hashes
|
||||||
from cryptography.hazmat.primitives.asymmetric import ec, utils
|
from cryptography.hazmat.primitives.asymmetric import ec, utils
|
||||||
@ -94,12 +93,12 @@ def get_apps():
|
|||||||
|
|
||||||
def get_app(app_name):
|
def get_app(app_name):
|
||||||
try:
|
try:
|
||||||
return get_entry(TYPE_APP, image_name)
|
return get_entry(TYPE_APP, app_name)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
raise ImageNotFoundError(image_name) from e
|
raise ImageNotFoundError(app_name) from e
|
||||||
|
|
||||||
def register_app(app_name, definition):
|
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):
|
def unregister_app(app_name):
|
||||||
delete_entry(TYPE_APP, image_name)
|
delete_entry(TYPE_APP, app_name)
|
||||||
|
Loading…
Reference in New Issue
Block a user