Exemplo n.º 1
0
    def normalise_filled(self, meta, val):
        val = sb.dictof(sb.string_choice_spec(["s3", "inline", "directory"]),
                        sb.any_spec()).normalise(meta, val)
        if not val:
            raise BadSpecValue(
                "Please specify s3, inline or directory for your code",
                meta=meta)

        if len(val) > 1:
            raise BadSpecValue(
                "Please only specify one of s3, inline or directory for your code",
                got=list(val.keys()),
                meta=meta)

        formatted_string = sb.formatted(sb.string_spec(),
                                        formatter=MergedOptionStringFormatter)
        if "s3" in val:
            return sb.create_spec(
                S3Code,
                key=formatted_string,
                bucket=formatted_string,
                version=sb.defaulted(sb.string_spec(),
                                     NotSpecified)).normalise(meta, val['s3'])
        elif "inline" in val:
            path = [p for p, _ in meta._path]
            path.pop()
            runtime = meta.everything['.'.join(path)].get("runtime", "python")
            runtime = sb.formatted(
                sb.string_spec(),
                formatter=MergedOptionStringFormatter).normalise(
                    meta.at("runtime"), runtime)

            return sb.create_spec(InlineCode,
                                  code=sb.string_spec(),
                                  runtime=sb.overridden(runtime)).normalise(
                                      meta, {"code": val['inline']})
        else:
            directory = val['directory']
            if isinstance(val['directory'], six.string_types):
                directory = {"directory": val['directory']}

            if 'directory' in directory:
                formatted_string = sb.formatted(
                    sb.string_spec(), formatter=MergedOptionStringFormatter)
                directory['directory'] = formatted_string.normalise(
                    meta.at("directory").at("directory"),
                    directory['directory'])

            return sb.create_spec(DirectoryCode,
                                  directory=sb.directory_spec(),
                                  exclude=sb.listof(
                                      sb.string_spec())).normalise(
                                          meta, directory)
Exemplo n.º 2
0
 def aws_syncr_spec(self):
     """Spec for aws_syncr options"""
     formatted_string = formatted(string_spec(), MergedOptionStringFormatter, expected_type=six.string_types)
     return create_spec(AwsSyncr
         , extra = defaulted(formatted_string, "")
         , stage = defaulted(formatted_string, "")
         , debug = defaulted(boolean(), False)
         , dry_run = defaulted(boolean(), False)
         , location = defaulted(formatted_string, "ap-southeast-2")
         , artifact = formatted_string
         , environment = formatted_string
         , config_folder = directory_spec()
         )
Exemplo n.º 3
0
    def context_spec(self):
        """Spec for specifying context options"""
        from harpoon.option_spec import image_objs
        return dict_from_bool_spec(lambda meta, val: {"enabled": val}
            , create_spec(image_objs.Context
                , include = listof(string_spec())
                , exclude = listof(string_spec())
                , enabled = defaulted(boolean(), True)

                , parent_dir = directory_spec(formatted(defaulted(string_spec(), "{config_root}"), formatter=MergedOptionStringFormatter))
                , use_gitignore = defaulted(boolean(), False)
                , use_git_timestamps = defaulted(or_spec(boolean(), listof(string_spec())), False)
                )
            )
Exemplo n.º 4
0
 def aws_syncr_spec(self):
     """Spec for aws_syncr options"""
     formatted_string = formatted(string_spec(),
                                  MergedOptionStringFormatter,
                                  expected_type=six.string_types)
     return create_spec(AwsSyncr,
                        extra=defaulted(formatted_string, ""),
                        stage=defaulted(formatted_string, ""),
                        debug=defaulted(boolean(), False),
                        dry_run=defaulted(boolean(), False),
                        location=defaulted(formatted_string,
                                           "ap-southeast-2"),
                        artifact=formatted_string,
                        environment=formatted_string,
                        config_folder=directory_spec())
Exemplo n.º 5
0
 def context_spec(self):
     """Spec for specifying context options"""
     from harpoon.option_spec import image_objs
     return dict_from_bool_spec(
         lambda meta, val: {"enabled": val},
         create_spec(image_objs.Context,
                     include=listof(string_spec()),
                     exclude=listof(string_spec()),
                     enabled=defaulted(boolean(), True),
                     parent_dir=directory_spec(
                         formatted(defaulted(string_spec(),
                                             "{config_root}"),
                                   formatter=MergedOptionStringFormatter)),
                     use_gitignore=defaulted(boolean(), False),
                     use_git_timestamps=defaulted(
                         or_spec(boolean(), listof(string_spec())), False)))
Exemplo n.º 6
0
    def context_spec(self):
        """Spec for specifying context options"""
        from harpoon.option_spec import image_objs
        return dict_from_bool_spec(lambda meta, val: {"enabled": val}
            , create_spec(image_objs.Context
                , validators.deprecated_key("use_git_timestamps", "Since docker 1.8, timestamps no longer invalidate the docker layer cache")

                , include = listof(string_spec())
                , exclude = listof(string_spec())
                , enabled = defaulted(boolean(), True)
                , find_options = string_spec()

                , parent_dir = directory_spec(formatted(defaulted(string_spec(), "{config_root}"), formatter=MergedOptionStringFormatter))
                , use_gitignore = defaulted(boolean(), False)
                , ignore_find_errors = defaulted(boolean(), False)
                )
            )
Exemplo n.º 7
0
    def normalise_filled(self, meta, val):
        val = sb.dictof(sb.string_choice_spec(["s3", "inline", "directory"]), sb.any_spec()).normalise(meta, val)
        if not val:
            raise BadSpecValue("Please specify s3, inline or directory for your code", meta=meta)

        if len(val) > 1:
            raise BadSpecValue("Please only specify one of s3, inline or directory for your code", got=list(val.keys()), meta=meta)

        formatted_string = sb.formatted(sb.string_spec(), formatter=MergedOptionStringFormatter)
        if "s3" in val:
            return sb.create_spec(S3Code
                , key = formatted_string
                , bucket = formatted_string
                , version = sb.defaulted(sb.string_spec(), NotSpecified)
                ).normalise(meta, val['s3'])
        elif "inline" in val:
            path = [p for p, _ in meta._path]
            path.pop()
            runtime = meta.everything['.'.join(path)].get("runtime", "python")
            runtime = sb.formatted(sb.string_spec(), formatter=MergedOptionStringFormatter).normalise(meta.at("runtime"), runtime)

            return sb.create_spec(InlineCode
                , code = sb.string_spec()
                , runtime = sb.overridden(runtime)
                ).normalise(meta, {"code": val['inline']})
        else:
            directory = val['directory']
            if isinstance(val['directory'], six.string_types):
                directory = {"directory": val['directory']}

            if 'directory' in directory:
                formatted_string = sb.formatted(sb.string_spec(), formatter=MergedOptionStringFormatter)
                directory['directory'] = formatted_string.normalise(meta.at("directory").at("directory"), directory['directory'])

            return sb.create_spec(DirectoryCode
                , directory = sb.directory_spec()
                , exclude = sb.listof(sb.string_spec())
                ).normalise(meta, directory)
Exemplo n.º 8
0
 def create_result(self, directory, import_name, meta, val, dividers):
     directory = sb.directory_spec().normalise(meta, directory)
     return Import(directory, import_name)
Exemplo n.º 9
0
    def image_spec(self):
        """Spec for each image"""
        from harpoon.option_spec import image_specs as specs
        from harpoon.option_spec import image_objs
        return create_spec(
            image_objs.Image
            # Change the context options
            ,
            validators.deprecated_key("exclude_context",
                                      "Use ``context.exclude``"),
            validators.deprecated_key("use_git_timestamps",
                                      "Use ``context.use_git_timestamps``"),
            validators.deprecated_key("respect_gitignore",
                                      "Use ``context.use_gitignore``"),
            validators.deprecated_key("parent_dir",
                                      "Use ``context.parent_dir``")

            # Changed how volumes_from works
            ,
            validators.deprecated_key("volumes_from",
                                      "Use ``volumes.share_with``")

            # Deprecated link
            ,
            validators.deprecated_key("link", "Use ``links``")

            # Harpoon options
            ,
            harpoon=any_spec()

            # default the name to the key of the image
            ,
            name=formatted(defaulted(string_spec(), "{_key_name_1}"),
                           formatter=MergedOptionStringFormatter),
            key_name=formatted(overridden("{_key_name_1}"),
                               formatter=MergedOptionStringFormatter),
            image_name=optional_spec(string_spec()),
            image_index=defaulted(string_spec(), ""),
            container_name=optional_spec(string_spec()),
            image_name_prefix=defaulted(string_spec(), ""),
            user=defaulted(string_spec(), None),
            mtime=defaulted(any_spec(), time.time()),
            configuration=any_spec()

            # The spec itself
            ,
            bash=optional_spec(
                formatted(string_spec(),
                          formatter=MergedOptionStringFormatter)),
            command=optional_spec(
                formatted(string_spec(),
                          formatter=MergedOptionStringFormatter)),
            commands=required(container_spec(Commands,
                                             listof(command_spec()))),
            links=listof(specs.link_spec(), expect=image_objs.Link),
            context=dict_from_bool_spec(
                lambda meta, val: {"enabled": val},
                create_spec(
                    image_objs.Context,
                    include=listof(string_spec()),
                    exclude=listof(string_spec()),
                    enabled=defaulted(boolean(), True),
                    parent_dir=directory_spec(
                        formatted(defaulted(string_spec(), "{config_root}"),
                                  formatter=MergedOptionStringFormatter)),
                    use_gitignore=defaulted(boolean(), False),
                    use_git_timestamps=defaulted(
                        or_spec(boolean(), listof(string_spec())), False))),
            lxc_conf=defaulted(filename_spec(), None),
            volumes=create_spec(image_objs.Volumes,
                                mount=listof(specs.mount_spec(),
                                             expect=image_objs.Mount),
                                share_with=listof(
                                    formatted(
                                        string_spec(),
                                        MergedOptionStringFormatter,
                                        expected_type=image_objs.Image))),
            dependency_options=dictof(
                self.image_name_spec,
                create_spec(image_objs.DependencyOptions,
                            attached=defaulted(boolean(), False))),
            env=listof(specs.env_spec(), expect=image_objs.Environment),
            ports=listof(specs.port_spec(), expect=image_objs.Port),
            other_options=create_spec(other_options,
                                      run=dictionary_spec(),
                                      build=dictionary_spec(),
                                      create=dictionary_spec()),
            network=create_spec(image_objs.Network,
                                dns=defaulted(listof(string_spec()), None),
                                mode=defaulted(string_spec(), None),
                                hostname=defaulted(string_spec(), None),
                                domainname=defaulted(string_spec(), None),
                                disabled=defaulted(boolean(), False),
                                dns_search=defaulted(listof(string_spec()),
                                                     None),
                                extra_hosts=optional_spec(
                                    listof(string_spec(), None)),
                                publish_all_ports=defaulted(boolean(), False)),
            cpu=create_spec(image_objs.Cpu,
                            cap_add=defaulted(boolean(), None),
                            cpuset=defaulted(listof(string_spec()), None),
                            cap_drop=defaulted(boolean(), None),
                            mem_limit=defaulted(integer_spec(), 0),
                            cpu_shares=defaulted(integer_spec(), None),
                            memswap_limit=defaulted(integer_spec(), 0)),
            devices=defaulted(listof(string_spec()), None),
            privileged=defaulted(boolean(), False),
            restart_policy=defaulted(string_spec(), None))
Exemplo n.º 10
0
 def create_result(self, directory, import_name, meta, val, dividers):
     directory = sb.directory_spec().normalise(meta, directory)
     return Import(directory, import_name)