Ejemplo n.º 1
0
    def load(self) -> typing.Iterable[Engine]:
        engine_sources = [
            ContainerEngineSource(
                name="hamlet-engine-base",
                description="hamlet official engine source",
                registry_url="https://ghcr.io",
                repository="hamlet-io/hamlet-engine-base",
                tag="nightly",
            ),
        ]

        engine_parts = [
            WrapperEnginePart(source_path="engine-core/",
                              source_name="hamlet-engine-base"),
            CoreEnginePart(source_path="engine/",
                           source_name="hamlet-engine-base"),
            BashExecutorEnginePart(source_path="executor-bash/",
                                   source_name="hamlet-engine-base"),
            AWSEnginePluginPart(source_path="engine-plugin-aws/",
                                source_name="hamlet-engine-base"),
            AzureEnginePluginPart(source_path="engine-plugin-azure/",
                                  source_name="hamlet-engine-base"),
        ]

        engine = Engine(name="tram",
                        description="Nightly build of the official engine")
        engine.parts = engine_parts
        engine.sources = engine_sources

        yield engine
Ejemplo n.º 2
0
    def load(self) -> typing.Iterable[Engine]:
        engine_sources = [
            ContainerEngineSource(
                name="engine",
                description="hamlet core engine",
                registry_url="https://ghcr.io",
                repository="hamlet-io/engine",
                tag="edge",
            ),
            ContainerEngineSource(
                name="executor-bash",
                description="hamlet bash executor",
                registry_url="https://ghcr.io",
                repository="hamlet-io/executor-bash",
                tag="edge",
            ),
            ContainerEngineSource(
                name="engine-plugin-aws",
                description="hamlet aws engine plugin",
                registry_url="https://ghcr.io",
                repository="hamlet-io/engine-plugin-aws",
                tag="edge",
            ),
            ContainerEngineSource(
                name="engine-plugin-azure",
                description="hamlet azure engine plugin",
                registry_url="https://ghcr.io",
                repository="hamlet-io/engine-plugin-azure",
                tag="edge",
            ),
            ContainerEngineSource(
                name="engine-core",
                description="hamlet freemarker wrapper",
                registry_url="https://ghcr.io",
                repository="hamlet-io/engine-core",
                tag="edge",
            ),
        ]

        engine_parts = [
            WrapperEnginePart(source_path="", source_name="engine-core"),
            CoreEnginePart(source_path="", source_name="engine"),
            BashExecutorEnginePart(source_path="",
                                   source_name="executor-bash"),
            AWSEnginePluginPart(source_path="",
                                source_name="engine-plugin-aws"),
            AzureEnginePluginPart(source_path="",
                                  source_name="engine-plugin-azure"),
        ]

        engine = Engine(
            name="unicycle",
            description="Latest build of the official engine parts")
        engine.parts = engine_parts
        engine.sources = engine_sources

        yield engine
Ejemplo n.º 3
0
    def load(self) -> typing.Iterable[Engine]:

        container_repo = ContainerRepository(
            registry_url="https://ghcr.io", repository="hamlet-io/hamlet-engine-base"
        )

        for tag in container_repo.tags:
            if re.fullmatch("^v?[0-9]*.[0-9]*.[0-9]*.$", tag) is not None:

                engine_sources = [
                    ContainerEngineSource(
                        name="hamlet-engine-base",
                        description="hamlet official engine source",
                        registry_url="https://ghcr.io",
                        repository="hamlet-io/hamlet-engine-base",
                        tag=tag,
                    ),
                ]

                engine_parts = [
                    WrapperEnginePart(
                        source_path="engine-core/", source_name="hamlet-engine-base"
                    ),
                    CoreEnginePart(
                        source_path="engine/", source_name="hamlet-engine-base"
                    ),
                    BashExecutorEnginePart(
                        source_path="executor-bash/", source_name="hamlet-engine-base"
                    ),
                    AWSEnginePluginPart(
                        source_path="engine-plugin-aws/",
                        source_name="hamlet-engine-base",
                    ),
                    AzureEnginePluginPart(
                        source_path="engine-plugin-azure/",
                        source_name="hamlet-engine-base",
                    ),
                ]

                engine = Engine(
                    name=tag,
                    description="Stable release of the official hamlet engine",
                )
                engine.parts = engine_parts
                engine.sources = engine_sources

                yield engine
Ejemplo n.º 4
0
    def load(self) -> typing.Iterable[Engine]:
        container_repo = ContainerRepository(
            registry_url="https://ghcr.io",
            repository="hamlet-io/hamlet-engine-base")

        for tag in container_repo.tags:
            if tag.startswith("schedule-") and datetime.datetime.now(
            ) - datetime.datetime.strptime(tag.split("-")[1],
                                           "%Y%m%d") <= datetime.timedelta(
                                               days=90):

                engine_sources = [
                    ContainerEngineSource(
                        name="hamlet-engine-base",
                        description="hamlet official engine source",
                        registry_url="https://ghcr.io",
                        repository="hamlet-io/hamlet-engine-base",
                        tag=tag,
                    ),
                ]

                engine_parts = [
                    WrapperEnginePart(source_path="engine-core/",
                                      source_name="hamlet-engine-base"),
                    CoreEnginePart(source_path="engine/",
                                   source_name="hamlet-engine-base"),
                    BashExecutorEnginePart(source_path="executor-bash/",
                                           source_name="hamlet-engine-base"),
                    AWSEnginePluginPart(
                        source_path="engine-plugin-aws/",
                        source_name="hamlet-engine-base",
                    ),
                    AzureEnginePluginPart(
                        source_path="engine-plugin-azure/",
                        source_name="hamlet-engine-base",
                    ),
                ]

                engine = Engine(
                    name=tag.replace("schedule-", "tram-"),
                    description="Scheduled build of the official hamlet engine",
                )
                engine.parts = engine_parts
                engine.sources = engine_sources

                yield engine
Ejemplo n.º 5
0
def test_installed_engine_loading():
    """
    Tests that we can discover engines that have been installed
    and that they can be discovered by the InstalledEngine basic loader
    """
    with tempfile.TemporaryDirectory() as store_dir:
        engine_store = EngineStore(store_dir=store_dir)
        assert len(engine_store.get_engines()) == 0
        """
        Engine is created in a directory which matches the engine_store engine search location
        The engine isn't loaded through an engine loader yet
        """
        manually_installed_engine = Engine(name="installed_engine",
                                           description="an installed engine")
        manually_installed_engine.engine_dir = engine_store.engine_dir

        manually_installed_engine.sources = [
            ShimPathEngineSource(name="shim_source",
                                 description="A basic shim engine")
        ]

        manually_installed_engine.parts = [
            CoreEnginePart(source_name="shim_source", source_path="")
        ]

        manually_installed_engine.install()
        assert os.path.isfile(manually_installed_engine.engine_state_file)
        """
        Use the Installed loader to discover the manually installed engine
        """

        engine_store.load_engines(locations=["installed"])

        discovered_engine = engine_store.get_engine("installed_engine")
        assert discovered_engine.name == "installed_engine"

        generation_engine_path = os.path.join(discovered_engine.install_path,
                                              "shim_source")
        assert (discovered_engine.environment["GENERATION_ENGINE_DIR"] ==
                generation_engine_path)
Ejemplo n.º 6
0
    def load_engines(cls):
        """Load engines found in the config file."""

        if os.path.exists(HAMLET_GLOBAL_CONFIG.config_dir):
            if os.path.isdir(HAMLET_GLOBAL_CONFIG.config_dir):
                cls.config_searchpath.insert(0, HAMLET_GLOBAL_CONFIG.config_dir)

        config = cls.read_config()

        for k, v in config.items():
            if k.startswith("engine:"):
                engine = Engine(
                    name=k[len("engine:") :],
                    description=v.get("description", None),
                )

                sources = []
                for source_name in v.get("sources"):
                    try:
                        source_config = config[f"engine_source:{source_name}"]

                    except KeyError as e:
                        e.msg = (
                            f"The provided engine source {source_name}"
                            "could not be found in the configured local sources"
                        )
                        raise e

                    if source_config["type"] == "local_dir":
                        sources.append(
                            LocalDirectoryEngineSource(
                                name=source_name,
                                description=source_config.get("description", None),
                                env_path=source_config["local_dir_path"],
                            )
                        )

                    if source_config["type"] == "container":
                        sources.append(
                            ContainerEngineSource(
                                name=source_name,
                                description=source_config.get("description", None),
                                registry_url=source_config.get(
                                    "container_registry_url"
                                ),
                                repository=source_config.get("container_repository"),
                                tag=source_config.get("container_tag"),
                            )
                        )

                parts = []
                for part_name in v.get("parts"):

                    part_config = config[f"engine_part:{part_name}"]

                    part_source_config = {
                        "source_name": part_config["source_name"],
                        "source_path": part_config.get("source_path", ""),
                    }

                    if part_config["type"] == "engine":
                        parts.append(CoreEnginePart(**part_source_config))

                    if part_config["type"] == "engine-plugin-aws":
                        parts.append(AWSEnginePluginPart(**part_source_config))

                    if part_config["type"] == "engine-plugin-azure":
                        parts.append(AzureEnginePluginPart(**part_source_config))

                    if part_config["type"] == "engine-plugin-cmdb":
                        parts.append(CMDBEnginePluginPart(**part_source_config))

                    if part_config["type"] == "executor-bash":
                        parts.append(BashExecutorEnginePart(**part_source_config))

                    if part_config["type"] == "wrapper":
                        parts.append(WrapperEnginePart(**part_source_config))

                engine.sources = sources
                engine.parts = parts

                yield engine