Esempio n. 1
0
def push(target_image: Image) -> int:
    log = logging.getLogger('dcb.push')
    log.info('tagging {0} as {1}...'.format(target_image.name(),
                                            target_image.fq_name()))
    rc = run_it(['docker', 'tag', target_image.name(), target_image.fq_name()])
    if rc == 0:
        log.info('pushing {0}...'.format(target_image.fq_name()))
        rc = run_it(['docker', 'push', target_image.fq_name()])
        if rc == 0:
            describe(target_image)
        else:
            raise Exception('Error pushing {0}: {1}'.format(
                target_image.fq_name(), rc))
    else:
        raise Exception('Error tagging {0} as {1}...'.format(
            target_image.name(), target_image.fq_name()))
Esempio n. 2
0
def pull(upstream_image: Image) -> int:
    log = logging.getLogger('dcb.pull')
    upstream_image_fq_name = upstream_image.fq_name()
    log.info('pulling {0}...'.format(upstream_image_fq_name))
    rc = run_it(['docker', 'pull', upstream_image_fq_name])
    if rc == 0:
        describe(upstream_image)
    else:
        raise Exception('Error pulling {0}: {1}'.format(
            upstream_image_fq_name, rc))
Esempio n. 3
0
 def login(self) -> bool:
     log = logging.getLogger("dcb.login")
     if self.user is None:
         log.debug(
             "{0}: no user specified. skipping registry login.".format(
                 self.env_infix
             )
         )
         return False
     elif self.pwd is None:
         log.debug(
             "{0}: no password specified for {1}. skipping registry login.".format(
                 self.env_infix,
                 self.user
             )
         )
         return False
     else:
         if not self._logged_in:
             log.info(
                 "{0}: logging {1} into {2}...".format(
                     self.env_infix,
                     self.user,
                     self.registry
                 )
             )
             cmd = ['docker', 'login', '-u', self.user, '-p', self.pwd]
             if self.email:
                 cmd += ['-e', self.email]
             cmd += [self.registry]
             run_it(cmd)
             log.info("logged in")
             self._logged_in = True
         else:
             log.debug(
                 "{0}: already logged into {1} as {2}".format(
                     self.env_infix,
                     self.registry,
                     self.user
                 )
             )
         return True
Esempio n. 4
0
def build(target_image: Image, build_envs: List[str], sub_dirs: bool) -> int:
    log = logging.getLogger('dcb.build')
    log.info('building the {0} container...'.format(target_image.name()))
    cmd = ['docker', 'build', '--rm=false', "--progress=plain"]
    cmd += fmt_build_args(build_envs)
    cmd += ['-t', target_image.name()]
    cmd += ['-f', dockerfile(target_image.tag, sub_dirs)]
    cmd += [docker_build_dir(target_image.tag, sub_dirs)]
    rc = run_it(cmd)
    if rc == 0:
        describe(target_image)
    else:
        raise Exception('Error building {0}: {1}'.format(target_image, rc))
Esempio n. 5
0
def describe(image: Image) -> int:
    return run_it(['docker', 'images', image.fq_name()])