예제 #1
0
    def build(
            self,
            namespace: argparse.Namespace,
            image: str,
            build_config: config.ImageBuildConfig):
        '''
        :param namespace: Namespace passed in via CLI.
        :param image: The image to build.
        :param build_config: the image build configuration.
        :raises: subprocess.CalledProcessError
        '''
        LOGGER.info('Build image')
        LOGGER.info('Dry Run: %s', namespace.dry_run)

        image_dir = util.get_image_dir(namespace.path, image)
        image = build_config.image.full_name
        build_args = builder.get_build_args(build_config)

        command = util.Command(['buildah', 'bud', '-t'])
        command.add_arg(image)
        command.add_args_list('--build-arg', build_args)

        version = build_config.image.tag_build.version
        if version:
            command.add_args('--build-arg', f'VERSION={version}')

        # add build context
        command.add_arg('.')

        LOGGER.info('Image name: %s', image)
        LOGGER.info('Command: %s', ' '.join(command))

        if namespace.dry_run:
            return

        # build
        with util.pushd(image_dir):
            subprocess.check_call(command)

        image_tag = build_config.image.tag
        if namespace.tag_latest and image_tag != 'latest':
            self.tag_latest(image)

        if namespace.push:
            self.push(
                namespace=namespace,
                image=image)
예제 #2
0
    def _tag(self, image: str, tag: str):
        '''
        :param image: The image to tag.
        :param tag: The tag for the image.
        :raises: subprocess.CalledProcessError
        '''
        LOGGER.info('Tag image')

        command = util.Command(['buildah', 'tag', image])
        name, _ = image.rsplit(':', 1)
        new_image = ':'.join([name, tag])
        command.add_arg(new_image)

        LOGGER.info('Image to tag: %s', image)
        LOGGER.info('Additional tag: %s', new_image)
        LOGGER.info('Command: %s', ' '.join(command))
        subprocess.check_call(command)
예제 #3
0
파일: buildkit.py 프로젝트: spiarh/jojo
    def _create_command(self, namespace: argparse.Namespace, action: str,
                        build_args: list):
        '''
        Creates the command for the buildkit builder.
        '''
        command = util.Command(['buildctl'])

        if namespace.addr:
            command.add_args(name='--addr', value=namespace.addr)

        command.add_arg(name=action)
        command.add_args(name='--frontend', value='dockerfile.v0')
        command.add_args(name='--local', value='context=.')
        command.add_args(name='--local', value='dockerfile=.')
        command.add_args_list(
            name='--opt', values=[f'build-arg:{arg}' for arg in build_args])

        return command
예제 #4
0
    def push(self, namespace: argparse.Namespace, image: str):
        '''
        :param image: The image to tag.
        :raises: subprocess.CalledProcessError
        '''
        LOGGER.info('Push image')
        LOGGER.info('Dry Run: %s', namespace.dry_run)
        LOGGER.info('Image to push: %s', image)

        command = util.Command(['podman', 'push', image])
        LOGGER.info('Command: %s', ' '.join(command))

        if namespace.dry_run:
            return

        subprocess.check_call(command)

        if namespace.tag_latest:
            self.tag_latest(image)
            command[-1] = util.set_image_tag_latest(image=image)
            LOGGER.info('Command: %s', ' '.join(command))
            subprocess.check_call(command)