in tools/ci_build/get_docker_image.py [0:0]
def main():
args = parse_args()
# log.debug("Dockerfile: {}, context: {}, docker build args: '{}'".format(
# args.dockerfile, args.context, args.docker_build_args))
use_container_registry = args.container_registry is not None
# if not use_container_registry:
# log.info("No container registry will be used")
print("args.docker_build_args: ", args.docker_build_args)
print("args.container_registry: ", args.container_registry if args.container_registry is not None else "None")
print("args.container_registry: ", args.container_registry)
print("args.context: ", args.context)
tag = generate_tag(args.dockerfile, args.context, args.docker_build_args)
full_image_name = \
"{}.azurecr.io/{}:{}".format(args.container_registry, args.repository, tag) \
if use_container_registry else \
"{}:{}".format(args.repository, tag)
# log.info("Image: {}".format(full_image_name))
if use_container_registry and container_registry_has_image(full_image_name, args.docker_path):
# log.info("Pulling image...")
run(args.docker_path, "pull", full_image_name)
else:
# log.info("Building image...")
run(args.docker_path, "build",
"--pull",
*shlex.split(args.docker_build_args),
*shlex.split(args.docker_build_args_not_affecting_image_content),
"--tag", full_image_name,
"--file", args.dockerfile,
args.context)
if use_container_registry:
# avoid pushing if an identically tagged image has been pushed since the last check
# there is still a race condition, but this reduces the chance of a redundant push
if not container_registry_has_image(full_image_name, args.docker_path):
# log.info("Pushing image...")
run(args.docker_path, "push", full_image_name)
# else:
# log.info("Image now found, skipping push")
# tag so we can refer to the image by repository name
run(args.docker_path, "tag", full_image_name, args.repository)
return 0