original_docstring: Tag and push a DockerContainer image to a repository
  
          Parameters
          ----------
          repo : DockerRepo, optional
              DockerRepo instance to which to push this image
  
          repo_uri : string, optional
              URI for the docker repository to which to push this instance
          
docstring: Tag and push a DockerContainer image to a repository
  Parameters
  
  repo : DockerRepo, optional
  DockerRepo instance to which to push this image
  
  repo_uri : string, optional
  URI for the docker repository to which to push this instance
docstring_tokens: Tag and push a DockerContainer image to a repository Parameters repo : DockerRepo optional DockerRepo instance to which to push this image repo_uri : string optional URI for the docker repository to which to push this instance
code: def push(self, repo=None, repo_uri=None):
          """Tag and push a DockerContainer image to a repository
  
          Parameters
          ----------
          repo : DockerRepo, optional
              DockerRepo instance to which to push this image
  
          repo_uri : string, optional
              URI for the docker repository to which to push this instance
          """
          if self.clobbered:
              raise ResourceClobberedException(
                  "This docker image has already been clobbered.", self.name
              )
  
          # User must supply either a repo object or the repo name and uri
          if not (repo or repo_uri):
              raise CloudknotInputError(
                  "You must supply either `repo=" "<DockerRepo instance>` or `repo_uri`."
              )
  
          # User cannot supply both repo and repo_name or repo_uri
          if repo and repo_uri:
              raise CloudknotInputError(
                  "You may not specify both a repo object " "and `repo_uri`."
              )
  
          # Make sure that the user has called build first or somehow set tags.
          if not self.images:
              raise CloudknotInputError(
                  "The images property is empty, indicating that the build "
                  "method has not yet been called. Call `build(tags=<tags>)` "
                  "first before calling `tag()`."
              )
  
          fallback = "from_env"
          if get_profile(fallback=fallback) != fallback:
              cmd = [
                  "aws",
                  "ecr",
                  "get-login",
                  "--no-include-email",
                  "--region",
                  get_region(),
                  "--profile",
                  get_profile(),
              ]
          else:
              cmd = [
                  "aws",
                  "ecr",
                  "get-login",
                  "--no-include-email",
                  "--region",
                  get_region(),
              ]
  
          # Refresh the aws ecr login credentials
          login_cmd = subprocess.check_output(cmd)
  
          # Login
          login_cmd_list = login_cmd.decode("ASCII").rstrip("\n").split(" ")
          login_result = subprocess.run(
              login_cmd_list, stdout=subprocess.PIPE, stderr=subprocess.PIPE
          )
  
          # If login failed, pass error to user
          if login_result.returncode:  # pragma: nocover
              raise CloudknotConfigurationError(
                  "Unable to login to AWS ECR using the command:\n"
                  "\t{login:s}\nReturned exit code = {code}\n"
                  "STDOUT: {out:s}\nSTDERR: {err:s}\n".format(
                      login=login_cmd.decode(),
                      code=login_result.returncode,
                      out=login_result.stdout.decode(),
                      err=login_result.stderr.decode()
                  )
              )
  
          if repo:
              if not isinstance(repo, aws.DockerRepo):
                  raise CloudknotInputError("repo must be of type DockerRepo.")
              self._repo_uri = repo.repo_uri
          else:
              if not isinstance(repo_uri, six.string_types):
                  raise CloudknotInputError("`repo_uri` must be a string.")
              self._repo_uri = repo_uri
  
          # Use docker low-level APIClient for tagging
          c = docker.from_env().api
          # And the image client for pushing
          cli = docker.from_env().images
          for im in self.images:
              # Log tagging info
              mod_logger.info(
                  "Tagging image {name:s} with tag {tag:s}".format(
                      name=im["name"], tag=im["tag"]
                  )
              )
  
              # Tag it with the most recently added image_name
              c.tag(
                  image=im["name"] + ":" + im["tag"],
                  repository=self.repo_uri,
                  tag=im["tag"],
              )
  
              # Log push info
              mod_logger.info(
                  "Pushing image {name:s} with tag {tag:s}".format(
                      name=im["name"], tag=im["tag"]
                  )
              )
  
              for l in cli.push(repository=self.repo_uri, tag=im["tag"], stream=True):
                  mod_logger.debug(l)
  
          self._repo_uri = self._repo_uri + ":" + self.images[-1]["tag"]
  
          section_name = "docker-image " + self.name
          ckconfig.add_resource(section_name, "repo-uri", self.repo_uri)
code_tokens: def push ( self , repo = None , repo_uri = None ) : if self . clobbered : raise ResourceClobberedException ( "This docker image has already been clobbered." , self . name ) if not ( repo or repo_uri ) : raise CloudknotInputError ( "You must supply either `repo=" "<DockerRepo instance>` or `repo_uri`." ) if repo and repo_uri : raise CloudknotInputError ( "You may not specify both a repo object " "and `repo_uri`." ) if not self . images : raise CloudknotInputError ( "The images property is empty, indicating that the build " "method has not yet been called. Call `build(tags=<tags>)` " "first before calling `tag()`." ) fallback = "from_env" if get_profile ( fallback = fallback ) != fallback : cmd = [ "aws" , "ecr" , "get-login" , "--no-include-email" , "--region" , get_region ( ) , "--profile" , get_profile ( ) , ] else : cmd = [ "aws" , "ecr" , "get-login" , "--no-include-email" , "--region" , get_region ( ) , ] login_cmd = subprocess . check_output ( cmd ) login_cmd_list = login_cmd . decode ( "ASCII" ) . rstrip ( "\n" ) . split ( " " ) login_result = subprocess . run ( login_cmd_list , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) if login_result . returncode : raise CloudknotConfigurationError ( "Unable to login to AWS ECR using the command:\n" "\t{login:s}\nReturned exit code = {code}\n" "STDOUT: {out:s}\nSTDERR: {err:s}\n" . format ( login = login_cmd . decode ( ) , code = login_result . returncode , out = login_result . stdout . decode ( ) , err = login_result . stderr . decode ( ) ) ) if repo : if not isinstance ( repo , aws . DockerRepo ) : raise CloudknotInputError ( "repo must be of type DockerRepo." ) self . _repo_uri = repo . repo_uri else : if not isinstance ( repo_uri , six . string_types ) : raise CloudknotInputError ( "`repo_uri` must be a string." ) self . _repo_uri = repo_uri c = docker . from_env ( ) . api cli = docker . from_env ( ) . images for im in self . images : mod_logger . info ( "Tagging image {name:s} with tag {tag:s}" . format ( name = im [ "name" ] , tag = im [ "tag" ] ) ) c . tag ( image = im [ "name" ] + ":" + im [ "tag" ] , repository = self . repo_uri , tag = im [ "tag" ] , ) mod_logger . info ( "Pushing image {name:s} with tag {tag:s}" . format ( name = im [ "name" ] , tag = im [ "tag" ] ) ) for l in cli . push ( repository = self . repo_uri , tag = im [ "tag" ] , stream = True ) : mod_logger . debug ( l ) self . _repo_uri = self . _repo_uri + ":" + self . images [ - 1 ] [ "tag" ] section_name = "docker-image " + self . name ckconfig . add_resource ( section_name , "repo-uri" , self . repo_uri )
short_docstring: Tag and push a DockerContainer image to a repository
  Parameters
short_docstring_tokens: Tag and push a DockerContainer image to a repository Parameters
comment: """Tag and push a DockerContainer image to a repository
  
          Parameters
          ----------
          repo : DockerRepo, optional
              DockerRepo instance to which to push this image
  
          repo_uri : string, optional
              URI for the docker repository to which to push this instance
          """$SEP$# User must supply either a repo object or the repo name and uri$SEP$# User cannot supply both repo and repo_name or repo_uri$SEP$# Make sure that the user has called build first or somehow set tags.$SEP$# Refresh the aws ecr login credentials$SEP$# Login$SEP$# If login failed, pass error to user$SEP$# pragma: nocover$SEP$# Use docker low-level APIClient for tagging$SEP$# And the image client for pushing$SEP$# Log tagging info$SEP$# Tag it with the most recently added image_name$SEP$# Log push info