예제 #1
0
    def build_release(self, use_prepare=False, use_build=False):
        """
        :return: (True, image_name) or (False, None)
        """
        self._prepare_act()
        if (not use_build) and (not self.build_base(use_prepare)[0]):
            return (False, None)

        if self.release.script != []:
            params = {
                'base': self.img_names['build'],
                'workdir': self.workdir,
                'copy_list': [],
                'scripts': self.release.script,
                'build_args': [arg.split('=')[0] for arg in self.build.build_arg]
            }
            inter_name = self.gen_name(phase='script_inter')
            script_inter_name = mydocker.build(
                inter_name, self.ctx, self.ignore, self.img_temps['build'], params, self.build.build_arg)
            if script_inter_name is None:
                return (False, None)
        else:
            script_inter_name = self.img_names['build']

        dest_base = self.release.dest_base
        release_copy = list(self.release.copy)
        if self.release.dest_base == '':
            if self.build.volumes is None:
                mydocker.tag(script_inter_name, self.img_names['release'])
                return (True, self.img_names['release'])

            dest_base = script_inter_name
            release_copy = self.build.volumes + [DOCKER_APP_ROOT]
            release_copy = [{'src': x, 'dest': x} for x in release_copy]

        try:
            tmp_dir = tempfile.mkdtemp(dir='/tmp')
            mydocker.copy_to_host(script_inter_name, release_copy,
                                  tmp_dir, context=self.ctx,
                                  volumes=self.build.volumes)
            params = {
                'base': dest_base,
                'workdir': self.workdir,
                'copy_list': ['.'],
            }
            name = self.img_builders['release'](context=tmp_dir, params=params, build_args=[])
        except Exception as e:
            info('Exception: {}'.format(e))
            name = None
        finally:
            delete = [tmp_dir]
            for f in delete:
                if p.exists(f):
                    rm(f)

        if name is None:
            return (False, None)
        return (True, name)
예제 #2
0
 def tag_meta_version(self, name, sha1=''):
     tagged = '%s/%s' % (PRIVATE_REGISTRY, name)
     mydocker.tag(name, tagged)
     return tagged
예제 #3
0
    def build_release(self, use_prepare=False, use_build=False):
        """
        :return: (True, image_name) or (False, None)
        """
        self._prepare_act()
        if (not use_build) and (not self.build_base(use_prepare)[0]):
            return (False, None)

        if self.release.script != []:
            params = {
                'base': self.img_names['build'],
                'workdir': self.workdir,
                'copy_list': [],
                'scripts': self.release.script,
                'build_args':
                [arg.split('=')[0] for arg in self.build.build_arg]
            }
            inter_name = self.gen_name(phase='script_inter')
            script_inter_name = mydocker.build(inter_name, self.ctx,
                                               self.ignore,
                                               self.img_temps['build'], params,
                                               self.build.build_arg)
            if script_inter_name is None:
                return (False, None)
        else:
            script_inter_name = self.img_names['build']

        if self.release.dest_base == '':
            mydocker.tag(script_inter_name, self.img_names['release'])
            return (True, self.img_names['release'])

        copy_dest = '/lain/release'

        def to_dest(f):
            return copy_dest + p.join(DOCKER_APP_ROOT, f)

        src_dest = [(x.get('src', x), to_dest(x.get('dest', x)))
                    for x in self.release.copy]
        copy_scripts = []
        release_tar = 'release.tar'
        for src, dest in src_dest:
            copy_scripts.append(' '.join(['mkdir', '-p', p.dirname(dest)]))
            copy_scripts.append(' '.join(['cp', '-r', src, dest]))
        tar_script = ["tar -cf {} -C {} .".format(release_tar, copy_dest)]
        params = {
            'base': script_inter_name,
            'workdir': self.workdir,
            'copy_list': [],
            'scripts': copy_scripts + tar_script
        }
        inter_name = self.gen_name(phase='copy_inter')
        copy_inter_name = mydocker.build(inter_name, self.ctx, self.ignore,
                                         self.img_temps['build'], params, [])
        if script_inter_name != self.img_names['build']:
            mydocker.remove_image(script_inter_name)
        if copy_inter_name is None:
            return (False, None)

        try:
            host_release_tar = tempfile.NamedTemporaryFile(delete=False).name
            untar = tempfile.mkdtemp()

            mydocker.copy_to_host(copy_inter_name,
                                  p.join(DOCKER_APP_ROOT, release_tar),
                                  host_release_tar)
            mydocker.remove_image(copy_inter_name)

            mkdir_p(untar)
            call(['tar', '-xf', host_release_tar, '-C', untar])

            params = {
                'base': self.release.dest_base,
                'workdir': self.workdir,
                'copy_list': ['.'],
            }
            name = self.img_builders['release'](context=untar,
                                                params=params,
                                                build_args=[])
        except Exception:
            name = None
        finally:
            delete = (host_release_tar, untar)
            for f in delete:
                if p.exists(f):
                    rm(f)

        if name is None:
            return (False, None)
        return (True, name)
예제 #4
0
    def build_release(self, use_prepare=False, use_build=False):
        """
        :return: (True, image_name) or (False, None)
        """
        self._prepare_act()
        if (not use_build) and (not self.build_base(use_prepare)[0]):
            return (False, None)

        if self.release.script != []:
            params = {
                'base': self.img_names['build'],
                'workdir': self.workdir,
                'copy_list': [],
                'scripts': self.release.script,
                'build_args':
                [arg.split('=')[0] for arg in self.build.build_arg]
            }
            inter_name = self.gen_name(phase='script_inter')
            script_inter_name = mydocker.build(inter_name, self.ctx,
                                               self.ignore,
                                               self.img_temps['build'], params,
                                               self.build.build_arg)
            if script_inter_name is None:
                return (False, None)
        else:
            script_inter_name = self.img_names['build']

        dest_base = self.release.dest_base
        release_copy = list(self.release.copy)
        if self.release.dest_base == '':
            if self.build.volumes is None:
                mydocker.tag(script_inter_name, self.img_names['release'])
                return (True, self.img_names['release'])

            dest_base = script_inter_name
            release_copy = self.build.volumes + [DOCKER_APP_ROOT]
            release_copy = [{'src': x, 'dest': x} for x in release_copy]

        try:
            tmp_dir = tempfile.mkdtemp(dir='/tmp')
            mydocker.copy_to_host(script_inter_name,
                                  release_copy,
                                  tmp_dir,
                                  context=self.ctx,
                                  volumes=self.build.volumes)
            params = {
                'base': dest_base,
                'workdir': self.workdir,
                'copy_list': ['.'],
            }
            name = self.img_builders['release'](context=tmp_dir,
                                                params=params,
                                                build_args=[])
        except Exception as e:
            info('Exception: {}'.format(e))
            name = None
        finally:
            delete = [tmp_dir]
            for f in delete:
                if p.exists(f):
                    rm(f)

        if name is None:
            return (False, None)
        return (True, name)
예제 #5
0
 def tag_meta_version(self, name, sha1=''):
     tagged = '%s/%s' % (PRIVATE_REGISTRY, name)
     mydocker.tag(name, tagged)
     return tagged