Skip to content
Draft
Changes from all commits
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
20 changes: 14 additions & 6 deletions src/together/lib/cli/api/beta/jig/jig.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,10 @@ def build(self, tag: str = "latest", warmup: bool = False, docker_args: str | No
if warmup:
_build_warm_image(image)

def push(self, tag: str = "latest") -> None:
def push(self, tag: str = "latest", source_image: str | None = None) -> None:
if source_image and not tag:
last = source_image.rsplit("/", 1)[-1]
tag = last.rsplit(":", 1)[1] if ":" in last else "latest"
image = self.image(tag)
host = self.registry().split("/")[0]
login_cmd = ["docker", "login", host, "--username", "user", "--password-stdin"]
Expand All @@ -676,8 +679,12 @@ def push(self, tag: str = "latest") -> None:

console.print(f"Pushing {image}")
self._metadata_path(tag).unlink(missing_ok=True)
if source_image:
if subprocess.run(["docker", "tag", source_image, image]).returncode != 0:
raise JigError(f"Failed to retag {source_image}")
ok = subprocess.run(["docker", "push", image]).returncode == 0
Comment on lines +682 to +685

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you test if this works properly with zstd compressed images? docker push might recompress the image as gzip before push

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
Tbh, I haven't tested this at all. I wanted to make sure if we're all ok with the UX

# Skip buildx for warmup-baked images: a buildx rebuild would drop the warmup layer.
if _image_is_warmed(image) or os.getenv("JIG_DISABLE_BUILDX"):
elif _image_is_warmed(image) or os.getenv("JIG_DISABLE_BUILDX"):
ok = subprocess.run(["docker", "push", image]).returncode == 0
else:
builder = _ensure_zstd_builder()
Expand Down Expand Up @@ -1182,9 +1189,9 @@ def build(jig: Jig, tag: str, warmup: bool, docker_args: str | None) -> None:
jig.build(tag, warmup, docker_args)


def push(jig: Jig, tag: str) -> None:
def push(jig: Jig, tag: str, source_image: str | None = None) -> None:
"""Push image to registry"""
jig.push(tag)
jig.push(tag, source_image)


def deploy(
Expand Down Expand Up @@ -1451,13 +1458,14 @@ def build_cli(


def push_cli(
tag: Annotated[str, Parameter(help="Image tag")] = "latest",
tag: Annotated[Optional[str], Parameter(help="Image tag (defaults to 'latest', or source image's tag when --image is used)")] = None,
image: Annotated[Optional[str], Parameter(name="--image", help="Existing local image to retag and push")] = None,
*,
config: CLIConfigParameter,
toml_config: TomlConfigParameter = None,
) -> None:
"""Push image to registry."""
_run_jig_cmd(config, toml_config, lambda jig: push(jig, tag))
_run_jig_cmd(config, toml_config, lambda jig: push(jig, tag or ("" if image else "latest"), image))


def deploy_cli(
Expand Down
Loading