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

Allow uploading when config_manifest is not specified in the google artifact registry #115

Merged
merged 5 commits into from
Nov 16, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add cleanup process for temporary files created
Signed-off-by: Linsho Kaku <linsho@preferred.jp>
linshokaku committed Nov 16, 2023

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 6af1a04ffd20d8f24e93a429fad02e583a91caaa
21 changes: 15 additions & 6 deletions oras/provider.py
Original file line number Diff line number Diff line change
@@ -5,9 +5,11 @@
import copy
import os
import urllib
from contextlib import contextmanager, nullcontext
from dataclasses import asdict, dataclass
from http.cookiejar import DefaultCookiePolicy
from typing import Callable, List, Optional, Tuple, Union
from tempfile import TemporaryDirectory
from typing import Callable, Generator, List, Optional, Tuple, Union

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


@contextmanager
def temporary_empty_config() -> Generator[str, None, None]:
with TemporaryDirectory() as tmpdir:
config_file = oras.utils.get_tmpfile(tmpdir=tmpdir, suffix=".json")
oras.utils.write_file(config_file, "{}")
yield config_file


@dataclass
class Subject:
mediaType: str
@@ -747,11 +757,10 @@ def push(self, *args, **kwargs) -> requests.Response:

# Config is just another layer blob!
logger.debug(f"Preparing config {conf}")
if config_file is None:
config_file = oras.utils.get_tmpfile(suffix=".json")
with open(config_file, "w") as f:
f.write("{}")
response = self.upload_blob(config_file, container, conf)
with temporary_empty_config() if config_file is None else nullcontext(
config_file
) as config_file:
response = self.upload_blob(config_file, container, conf)

self._check_200_response(response)