Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error due to default value of manifest_config #112

Open
linshokaku opened this issue Oct 26, 2023 · 1 comment
Open

Error due to default value of manifest_config #112

linshokaku opened this issue Oct 26, 2023 · 1 comment

Comments

@linshokaku
Copy link
Contributor

If manifest_config is not specified when pushing by oras-py, the implementation currently treats manifest_config as a completely empty string.

oras-py/oras/oci.py

Lines 130 to 136 in 02c5bda

if not path or not os.path.exists(path):
path = os.devnull
conf = {
"mediaType": media_type or oras.defaults.unknown_config_media_type,
"size": 0,
"digest": oras.defaults.blank_hash,
}

I was using google artifact registry and confirmed that push fails if manifest_config is an empty string.

The current workaround (or maybe this is the right way) is to create a file with only "{}" and read that file to successfully execute the push.

If manifest_config was not specified, why not change it so that the contents of manifest_config are treated as "{}"?

code

import oras.client
import oras.logger
from pathlib import Path
from tempfile import TemporaryDirectory
import os
import json

oras.logger.setup_logger(debug=True, quiet=False)

pwd = Path(__file__).parent.resolve()

client = oras.client.OrasClient()
client.login(username="oauth2accesstoken", password="password")

with TemporaryDirectory() as tmp:
    config_path = os.path.join(tmp, "config.json")
    with open(config_path, "w") as f:
        json.dump({}, f)
    res = client.push(files=[str(pwd / "hoge.txt")], target="asia-northeast1-docker.pkg.dev/example-repository/tmp/oras-test:v2", manifest_config=config_path)
print("sucess push with config file")

res = client.push(files=[str(pwd / "hoge.txt")], target="asia-northeast1-docker.pkg.dev/example-repository/tmp/oras-test:v2")
print("success push")

log

Preparing layer {'mediaType': 'application/vnd.oci.image.layer.v1.tar', 'size': 13, 'digest': 'sha256:8f8ad85c91228f6b241b95ecca626a4e9701d7c072ca0c6c001677d797a4af02', 'annotations': {'org.opencontainers.image.title': 'hoge.txt'}}
Service: asia-northeast1-docker.pkg.dev
Scope: repository:example-repository/tmp/oras-test:pull,push
Preparing config {'mediaType': 'application/vnd.unknown.config.v1+json', 'size': 2, 'digest': 'sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a'}
Service: asia-northeast1-docker.pkg.dev
Scope: repository:example-repository/tmp/oras-test:pull,push
Service: asia-northeast1-docker.pkg.dev
Scope: repository:example-repository/tmp/oras-test:pull,push
Successfully pushed asia-northeast1-docker.pkg.dev/example-repository/tmp/oras-test:v2
sucess push with config file
Preparing layer {'mediaType': 'application/vnd.oci.image.layer.v1.tar', 'size': 13, 'digest': 'sha256:8f8ad85c91228f6b241b95ecca626a4e9701d7c072ca0c6c001677d797a4af02', 'annotations': {'org.opencontainers.image.title': 'hoge.txt'}}
Service: asia-northeast1-docker.pkg.dev
Scope: repository:example-repository/tmp/oras-test:pull,push
Preparing config {'mediaType': 'application/vnd.unknown.config.v1+json', 'size': 0, 'digest': 'sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'}
Service: asia-northeast1-docker.pkg.dev
Scope: repository:example-repository/tmp/oras-test:pull,push
Service: asia-northeast1-docker.pkg.dev
Scope: repository:example-repository/tmp/oras-test:pull,push
Trying with provided Basic Authorization...
failed to read config blob: sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Traceback (most recent call last):
  File "/Users/linsho/repos/oras-py/tmp/./tmp_log.py", line 22, in <module>
    res = client.push(files=[str(pwd / "hoge.txt")], target="asia-northeast1-docker.pkg.dev/example-repository/tmp/oras-test:v2")
  File "/Users/linsho/repos/oras-py/tmp/venv/lib/python3.10/site-packages/oras/client.py", line 132, in push
    return self.remote.push(*args, **kwargs)
  File "/Users/linsho/repos/oras-py/tmp/venv/lib/python3.10/site-packages/oras/provider.py", line 755, in push
    self._check_200_response(self.upload_manifest(manifest, container))
  File "/Users/linsho/repos/oras-py/tmp/venv/lib/python3.10/site-packages/oras/provider.py", line 593, in _check_200_response
    raise ValueError(f"Issue with {response.request.url}: {response.reason}")
ValueError: Issue with https://asia-northeast1-docker.pkg.dev/v2/example-repository/tmp/oras-test/manifests/v2: Not Found

environment

attrs==23.1.0
certifi==2023.7.22
charset-normalizer==3.3.1
idna==3.4
jsonschema==4.19.1
jsonschema-specifications==2023.7.1
oras==0.1.25
referencing==0.30.2
requests==2.31.0
rpds-py==0.10.6
urllib3==2.0.7
@vsoch
Copy link
Contributor

vsoch commented Oct 26, 2023

That would be a good solution. Would you care to open a PR to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants