def main(): logging_setup.DefineCommandLineArgs(parser) args = parser.parse_args() logging_setup.Init(args=args) if not args.name or not args.tarball: raise Exception('--name and --tarball are required arguments.') retry_factory = retry.Factory() retry_factory = retry_factory.WithSourceTransportCallable(httplib2.Http) transport = transport_pool.Http(retry_factory.Build, size=_THREADS) # This library can support push-by-digest, but the likelihood of a user # correctly providing us with the digest without using this library # directly is essentially nil. name = Tag(args.name, args.stamp_info_file) # Resolve the appropriate credential to use based on the standard Docker # client logic. creds = docker_creds.DefaultKeychain.Resolve(name) with docker_session.Push(name, creds, transport, threads=_THREADS) as session: logging.info('Reading v2.2 image from tarball %r', args.tarball) with v2_2_image.FromTarball(args.tarball) as v2_2_img: logging.info('Starting upload ...') if args.oci: with oci_compat.OCIFromV22(v2_2_img) as oci_img: session.upload(oci_img) digest = oci_img.digest() else: session.upload(v2_2_img) digest = v2_2_img.digest() print('{name} was published with digest: {digest}'.format( name=name, digest=digest))
def main(): logging_setup.DefineCommandLineArgs(parser) args = parser.parse_args() logging_setup.Init(args=args) if not args.name: raise Exception('--name is a required arguments.') # This library can support push-by-digest, but the likelihood of a user # correctly providing us with the digest without using this library # directly is essentially nil. name = Tag(args.name, args.stamp_info_file) if not args.config and (args.layer or args.digest): raise Exception( 'Using --layer or --digest requires --config to be specified.') if not args.config and not args.tarball: raise Exception('Either --config or --tarball must be specified.') # If config is specified, use that. Otherwise, fallback on reading # the config from the tarball. config = args.config if args.config: logging.info('Reading config from %r', args.config) with open(args.config, 'r') as reader: config = reader.read() elif args.tarball: logging.info('Reading config from tarball %r', args.tarball) with v2_2_image.FromTarball(args.tarball) as base: config = base.config_file() if len(args.digest or []) != len(args.layer or []): raise Exception('--digest and --layer must have matching lengths.') transport = transport_pool.Http(httplib2.Http, size=_THREADS) # Resolve the appropriate credential to use based on the standard Docker # client logic. creds = docker_creds.DefaultKeychain.Resolve(name) with docker_session.Push(name, creds, transport, threads=_THREADS) as session: logging.info('Loading v2.2 image from disk ...') with v2_2_image.FromDisk(config, zip(args.digest or [], args.layer or []), legacy_base=args.tarball) as v2_2_img: logging.info('Starting upload ...') if args.oci: with oci_compat.OCIFromV22(v2_2_img) as oci_img: session.upload(oci_img) digest = oci_img.digest() else: session.upload(v2_2_img) digest = v2_2_img.digest() print('{name} was published with digest: {digest}'.format( name=name, digest=digest))
def main(): logging_setup.DefineCommandLineArgs(parser) args = parser.parse_args() logging_setup.Init(args=args) if not args.config and (args.layer or args.digest): logging.fatal( 'Using --layer or --digest requires --config to be specified.') sys.exit(1) if not args.config and not args.tarball: logging.fatal('Either --config or --tarball must be specified.') sys.exit(1) # If config is specified, use that. Otherwise, fallback on reading # the config from the tarball. config = args.config manifest = args.manifest if args.config: logging.info('Reading config from %r', args.config) with open(args.config, 'r') as reader: config = reader.read() elif args.tarball: logging.info('Reading config from tarball %r', args.tarball) with v2_2_image.FromTarball(args.tarball) as base: config = base.config_file() if args.manifest: with open(args.manifest, 'r') as reader: manifest = reader.read() if len(args.digest or []) != len(args.layer or []): logging.fatal('--digest and --layer must have matching lengths.') sys.exit(1) logging.info('Loading v2.2 image from disk ...') with v2_2_image.FromDisk(config, list(zip(args.digest or [], args.layer or [])), legacy_base=args.tarball, foreign_layers_manifest=manifest) as v2_2_img: try: if args.oci: with oci_compat.OCIFromV22(v2_2_img) as oci_img: digest = oci_img.digest() else: digest = v2_2_img.digest() with open(args.output_digest, 'w+') as digest_file: digest_file.write(digest) # pylint: disable=broad-except except Exception as e: logging.fatal('Error getting digest: %s', e) sys.exit(1)
def main(): logging_setup.DefineCommandLineArgs(parser) args = parser.parse_args() logging_setup.Init(args=args) if not args.name: logging.fatal('--name is a required arguments.') sys.exit(1) # This library can support push-by-digest, but the likelihood of a user # correctly providing us with the digest without using this library # directly is essentially nil. name = Tag(args.name, args.stamp_info_file) if not args.config and (args.layer or args.digest): logging.fatal( 'Using --layer or --digest requires --config to be specified.') sys.exit(1) if not args.config and not args.tarball: logging.fatal('Either --config or --tarball must be specified.') sys.exit(1) if not args.protocol: logging.fatal('--protocol is a required argument') sys.exit(1) # If config is specified, use that. Otherwise, fallback on reading # the config from the tarball. config = args.config manifest = args.manifest protocol = args.protocol if protocol != 'http' and protocol != 'https': logging.fatal('Protocol should be http or https') if args.config: logging.info('Reading config from %r', args.config) with open(args.config, 'r') as reader: config = reader.read() elif args.tarball: logging.info('Reading config from tarball %r', args.tarball) with v2_2_image.FromTarball(args.tarball) as base: config = base.config_file() if args.manifest: with open(args.manifest, 'r') as reader: manifest = reader.read() if len(args.digest or []) != len(args.layer or []): logging.fatal('--digest and --layer must have matching lengths.') sys.exit(1) retry_factory = retry.Factory() retry_factory = retry_factory.WithSourceTransportCallable(httplib2.Http) transport = transport_pool.Http(retry_factory.Build, size=_THREADS) logging.info('Loading v2.2 image from disk ...') with v2_2_image.FromDisk(config, list(zip(args.digest or [], args.layer or [])), legacy_base=args.tarball, foreign_layers_manifest=manifest) as v2_2_img: # Resolve the appropriate credential to use based on the standard Docker # client logic. try: creds = docker_creds.DefaultKeychain.Resolve(name) # pylint: disable=broad-except except Exception as e: logging.fatal('Error resolving credentials for %s: %s', name, e) sys.exit(1) try: with docker_session.Push(protocol, name, creds, transport, threads=_THREADS) as session: logging.info('Starting upload ...') if args.oci: with oci_compat.OCIFromV22(v2_2_img) as oci_img: session.upload(oci_img) digest = oci_img.digest() else: session.upload(v2_2_img) digest = v2_2_img.digest() print(('{name} was published with digest: {digest}'.format( name=name, digest=digest))) # pylint: disable=broad-except except Exception as e: logging.fatal('Error publishing %s: %s', name, e) sys.exit(1)