Implement basic image push

Pushes all images built with build-image. This requires a --prefix
option to be specified since that is the user (or organization) to
which we push and helps to identify the local images.

Change-Id: I13eee575c329deb58285f9cc913be298b43bb438
This commit is contained in:
David Shrewsbury 2018-08-16 14:41:36 -04:00
parent 221674d1b9
commit a1cc08f014
3 changed files with 34 additions and 0 deletions

View File

@ -115,6 +115,16 @@ def main():
" http://dl-cdn.alpinelinux.org/alpine"),
)
cmd_push = subparsers.add_parser(
"push-images", help="push project container images to a repository"
)
cmd_push.set_defaults(func=container_images.push)
cmd_push.add_argument(
"--prefix",
help="Organization prefix container images will be published to",
required=True
)
args = parser.parse_args()
setup_logging(args.log_config, args.debug)

View File

@ -314,3 +314,22 @@ def build(args):
) as cont:
cont.run(
"chown -R {uid} /root/.cache/pip".format(uid=os.getuid()))
def push(args):
'''Push any built images to the registry.
The images built by pbrx's build-image command should already be named
with a prefix (the repository name to push to). It is expected that
we are already logged in to the registry as the user that owns the
repository.
'''
info = ProjectInfo()
unprefixed_image_names = info.scripts.copy()
unprefixed_image_names.add(info.base_container)
for image in unprefixed_image_names:
image = "/".join([args.prefix, image])
log.info("Pushing {image}".format(image=image))
sh.docker.push(image)

View File

@ -0,0 +1,5 @@
---
features:
- |
Added new push-images command to push any images built by the build-images
command.