def build_targets(args, defs, targets): if args.no_build: client = None else: client = get_client() if args.push_to_registry and args.registry_user: if not args.repository: raise errors.NoRegistryError( 'No registry specified to push images to.') registry = args.repository.split('/')[0] client.login(args.registry_user, password=args.registry_token, registry=registry, reauth=True) print("\nREGISTRY LOGIN SUCCESS:", registry) if args.build_arg: buildargs = _make_buildargs(args.build_arg) else: buildargs = None built, warnings = [], [] builders = [ defs.generate_build(t, generate_name(t, args.repository, args.tag), rebuilds=args.bust_cache, cache_repo=args.cache_repo, cache_tag=args.cache_tag, keepbuildtags=args.keep_build_tags, buildargs=buildargs) for t in targets ] for b in builders: b.build(client, nobuild=args.no_build, usecache=not args.no_cache, pull=args.pull) if not args.no_build: print(' docker-make built:', b.targetname) if args.print_dockerfiles or args.no_build: b.write_dockerfile(args.dockerfile_dir) built.append(b.targetname) if args.push_to_registry and not args.no_build: success, w = push(client, b.targetname) warnings.extend(w) if not success: built[-1] += ' -- PUSH FAILED' else: built[-1] += ' -- pushed to %s' % b.targetname.split('/')[0] return built, warnings
def build_targets(args, defs, targets): if args.no_build: client = None else: client = get_client() if args.push_to_registry and args.registry_user: if not args.repository: raise errors.NoRegistryError( "No registry specified to push images to.") registry = args.repository.split("/")[0] client.login( args.registry_user, password=args.registry_token, registry=registry, reauth=True, ) print("\nREGISTRY LOGIN SUCCESS:", registry) if args.build_arg: buildargs = _make_buildargs(args.build_arg) else: buildargs = None built, warnings = [], [] builders = [] cprint("\nRequested images: ", "blue", end="") print(", ".join("%s" % t for t in targets)) for t in targets: try: builder = defs.generate_build( t, generate_name(t, args.repository, args.tag), rebuilds=args.bust_cache, cache_repo=args.cache_repo, cache_tag=args.cache_tag, keepbuildtags=args.keep_build_tags, buildargs=buildargs, ) except errors.NoBaseError: if args.all: cprint("WARNING:", "red", end=" ") print( 'not building image "%s" because it does not have a base (FROM) image defined' % t) else: raise else: builders.append(builder) for b in builders: b.build(client, nobuild=args.no_build, usecache=not args.no_cache, pull=args.pull) if not args.no_build: print(" docker-make built:", b.targetname) if args.print_dockerfiles or args.no_build: b.write_dockerfile(args.dockerfile_dir) built.append(b.targetname) if args.push_to_registry and not args.no_build: # Build list of tags to push tags = [b.targetname] if b.aliases: tags.extend(b.aliases) for tag in tags: success, w = push(client, tag) warnings.extend(w) if not success: built[-1] += " -- PUSH FAILED" else: built[-1] += " -- pushed to %s" % tag.split('/')[0] return built, warnings