Skip to content

Commit

Permalink
#4: use user input
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincinator committed Jul 29, 2024
1 parent ece3a50 commit 8925ef8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 6 additions & 7 deletions src/gloci/commands/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 7 additions & 7 deletions src/gloci/oras/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8925ef8

Please sign in to comment.