Skip to content
Merged
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
11 changes: 9 additions & 2 deletions src/cmd-remote-build-container
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ def build_container_image(labels, buildDir, containerfile, fromimage, cacheTTL,
runcmd(cmd)


def push_container_image(repo, tag):
def push_container_image(repo, tag, digestfile):
'''
Push image to registry
@param repo str registry repository
@param tag str image tag
'''
cmd = ["podman", "push", f"{repo}:{tag}"]
if digestfile is not None:
cmd.extend(["--digestfile", digestfile])
# Long running command. Send output to stdout for logging
runcmd(cmd)
# Quay seems to take some time to publish images in some occasions.
Expand Down Expand Up @@ -132,6 +134,8 @@ def main():
# Check for requisite env vars
if os.environ.get('CONTAINER_HOST') is None or os.environ.get('CONTAINER_SSHKEY') is None:
sys.exit('You must have CONTAINER_HOST and CONTAINER_SSHKEY environment variables setup')
if args.write_digest_to_file is not None and not args.push_to_registry:
sys.exit('argument --write-digest-to-file can only be used with --push-to-registry')
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I couldn't find an easy way to express this using more argparse-native APIs instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There this file will be? in the remote or in the host? Don't we need something like the pull_oci_archive_from_remote ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It will be on the host. It seems like podman is smart enough in this case to do the pushing on the remote, but the writing of this file on the host.


# Podman supports building from a specific commit
# (https://github.com/containers/buildah/issues/4148), but the way
Expand Down Expand Up @@ -193,7 +197,7 @@ def main():
# Push to the registry if needed, else save the image to a file
if args.push_to_registry:
logging.info("Pushing to remote registry")
push_container_image(args.repo, args.tag)
push_container_image(args.repo, args.tag, args.write_digest_to_file)
else:
logging.info("Archiving build container image from remote")
pull_oci_archive_from_remote(args.repo, args.tag, args.write_to_file)
Expand Down Expand Up @@ -265,6 +269,9 @@ Examples:
parser.add_argument(
'--tag', required=False,
help='Force image tag. The default is arch-commit')
parser.add_argument(
'--write-digest-to-file', required=False,
help='Write digest of pushed image to named file')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument(
'--push-to-registry', required=False, action='store_true',
Expand Down
Loading