Skip to content

Commit b6196ca

Browse files
authored
Allow uploading when config_manifest is not specified in the google artifact registry (#115)
* Allow uploading when is not specified in the google artifact registry Signed-off-by: Linsho Kaku <linsho@preferred.jp>
1 parent 02c5bda commit b6196ca

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
1414
The versions coincide with releases on pip. Only major versions will be released as tags on Github.
1515

1616
## [0.0.x](https://github.com/oras-project/oras-py/tree/main) (0.0.x)
17+
- To make it available for more OCI registries, the value of config used when `manifest_config` is not specified in `client.push()` has been changed from a pure empty string to `{}` (0.1.26)
1718
- refactor tests using fixtures and rework pre-commit configuration (0.1.25)
1819
- eliminate the additional subdirectory creation while pulling an image to a custom output directory (0.1.24)
1920
- updating the exclude string in the pyproject.toml file to match the [data type black expects](https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-format)

oras/defaults.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@ class registry:
4141

4242
# what you get for a blank digest, so we don't need to save and recalculate
4343
blank_hash = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
44+
45+
# what you get for a blank config digest, so we don't need to save and recalculate
46+
blank_config_hash = (
47+
"sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a"
48+
)

oras/oci.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def NewLayer(
117117

118118
def ManifestConfig(
119119
path: Optional[str] = None, media_type: Optional[str] = None
120-
) -> Tuple[Dict[str, object], str]:
120+
) -> Tuple[Dict[str, object], Optional[str]]:
121121
"""
122122
Write an empty config, if one is not provided
123123
@@ -128,11 +128,11 @@ def ManifestConfig(
128128
"""
129129
# Create an empty config if we don't have one
130130
if not path or not os.path.exists(path):
131-
path = os.devnull
131+
path = None
132132
conf = {
133133
"mediaType": media_type or oras.defaults.unknown_config_media_type,
134-
"size": 0,
135-
"digest": oras.defaults.blank_hash,
134+
"size": 2,
135+
"digest": oras.defaults.blank_config_hash,
136136
}
137137

138138
else:

oras/provider.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import copy
66
import os
77
import urllib
8+
from contextlib import contextmanager, nullcontext
89
from dataclasses import asdict, dataclass
910
from http.cookiejar import DefaultCookiePolicy
10-
from typing import Callable, List, Optional, Tuple, Union
11+
from tempfile import TemporaryDirectory
12+
from typing import Callable, Generator, List, Optional, Tuple, Union
1113

1214
import jsonschema
1315
import requests
@@ -25,6 +27,14 @@
2527
container_type = Union[str, oras.container.Container]
2628

2729

30+
@contextmanager
31+
def temporary_empty_config() -> Generator[str, None, None]:
32+
with TemporaryDirectory() as tmpdir:
33+
config_file = oras.utils.get_tmpfile(tmpdir=tmpdir, suffix=".json")
34+
oras.utils.write_file(config_file, "{}")
35+
yield config_file
36+
37+
2838
@dataclass
2939
class Subject:
3040
mediaType: str
@@ -747,7 +757,11 @@ def push(self, *args, **kwargs) -> requests.Response:
747757

748758
# Config is just another layer blob!
749759
logger.debug(f"Preparing config {conf}")
750-
response = self.upload_blob(config_file, container, conf)
760+
with temporary_empty_config() if config_file is None else nullcontext(
761+
config_file
762+
) as config_file:
763+
response = self.upload_blob(config_file, container, conf)
764+
751765
self._check_200_response(response)
752766

753767
# Final upload of the manifest

oras/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__copyright__ = "Copyright The ORAS Authors."
33
__license__ = "Apache-2.0"
44

5-
__version__ = "0.1.25"
5+
__version__ = "0.1.26"
66
AUTHOR = "Vanessa Sochat"
77
EMAIL = "vsoch@users.noreply.github.com"
88
NAME = "oras"

0 commit comments

Comments
 (0)