diff --git a/Makefile b/Makefile index 3e24665..09c6943 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ install_deps: ## Install dependencies. example: @echo "Push first image..." - $(PYTHON) -m gloci.cli image push --container localhost:8081/$(EXAMPLECONTAINERNAME):latest --info_yaml example-data/info.yaml + $(PYTHON) -m gloci.cli image push --container localhost:8081/$(EXAMPLECONTAINERNAME):latest --architecture arm64 --cname yolo-example_dev --info_yaml example-data/info.yaml # @echo "Attach some file to image..." # $(PYTHON) -m gloci.cli image attach --container localhost:8081/$(EXAMPLECONTAINERNAME):latest --file_path config.ini --media_type application/vnd.oci.image.layer.v1.tar @echo "Inspect final oci image" diff --git a/src/gloci/commands/image.py b/src/gloci/commands/image.py index e40ba41..ba20db6 100644 --- a/src/gloci/commands/image.py +++ b/src/gloci/commands/image.py @@ -17,21 +17,20 @@ def image(): @image.command() @click.option('--container', required=True, type=click.Path(), help='Container Name') +@click.option('--architecture', required=True, type=click.Path(), help='Target Image CPU Architecture') +@click.option('--cname', required=True, type=click.Path(), help='Canonical Name of Image') @click.option('--info_yaml', required=True, type=click.Path(), help='info.yaml file of the Garden Linux flavor. The info.yaml specifies the data (layers) to expect to ' 'be attached later.') -def push(container, info_yaml): +def push(container, architecture, cname, info_yaml): container = oras.container.Container(container) registry = GlociRegistry(container.registry) - # TODO: Get CPU Architecture - - # TODO: Get target GL Flavor - - # TODO: Create image manifest + # TODO: cname can be computed from info_yaml content, + # but for consistency we let the caller who knows the cname already provide the cname # Create and Push image manifest - registry.push_image_manifest(container, info_yaml) + registry.push_image_manifest(container, architecture, cname, info_yaml) @image.command() diff --git a/src/gloci/oras/registry.py b/src/gloci/oras/registry.py index 4e802cd..b6074f9 100644 --- a/src/gloci/oras/registry.py +++ b/src/gloci/oras/registry.py @@ -65,8 +65,10 @@ def get_uri_for_digest(uri, digest): return f"{base_uri}@{digest}" -def NewPlatform() -> dict: - return copy.deepcopy(EmptyPlatform) +def NewPlatform(architecture) -> dict: + platform = copy.deepcopy(EmptyPlatform) + platform['architecture'] = architecture + return platform def NewManifestMetadata() -> dict: @@ -188,13 +190,12 @@ def _get_index(self, container): return image_index - @ensure_container - def push_image_manifest(self, container, info_yaml): + def push_image_manifest(self, container, architecture, cname, info_yaml): """ creates and pushes an image manifest """ - logger.debug("start push image manifest") + logger.debug("start push image manifest") assert info_yaml is not None, "error: info_yaml is None" with open(info_yaml, 'r') as f: info_data = yaml.safe_load(f) @@ -295,8 +296,7 @@ def push_image_manifest(self, container, info_yaml): manifest_index_metadata['digest'] = f"sha256:{checksum_sha256}" manifest_index_metadata['size'] = 0 manifest_index_metadata['annotations'] = {} - # TODO: fill in Platform details based on input or defaults - manifest_index_metadata['platform'] = NewPlatform() + manifest_index_metadata['platform'] = NewPlatform(architecture) manifest_index_metadata['artifactType'] = "" image_index['manifests'].append(manifest_index_metadata)