to make a package i need to create a temporary dir...
# general
b
to make a package i need to create a temporary directory, do a few operations on it, and then package it up. But i think pulumi is having trouble with that. the command immediately following mkdtemp can't find the directory. My guess this is do to some backend async'ness. is there a way to group a few things together so they run synchronously? (on python if thats relevant)
Copy code
import pulumi
import pulumi_command as command

import tempfile
import shutil
from pathlib import Path
import yaml

def package_chart(root, image_tag, local_repo_path):
    def package_chart_inner(tag):
        name, version = tag.split(":")
        values_patch = {"image": {"tag": version}}

        tmpdirname = tempfile.mkdtemp()
        try:
            shutil.copytree(root, tmpdirname, dirs_exist_ok=True)

            values_file = Path(tmpdirname) / 'values.yaml'
            values_data = yaml.safe_load(values_file.read_text())
            values_data.update(values_patch)
            values_file.write_text(
                yaml.safe_dump(values_data)
            )

            # Run helm dependency update
            dependency_update_command = command.local.Command(
                f"dependency_update_{name}",
                create=f"helm dependency update {tmpdirname}"
            )

            # Package the Helm chart
            chart_filename = f"{name}-1.0.0-x{version}.tgz"
            chart_path = local_repo_path / chart_filename
            package_chart_command = command.local.Command(
                f"package_chart_{name}",
                create=f"helm package {tmpdirname} --destination {local_repo_path} --version 1.0.0-x{version}",
                opts=pulumi.ResourceOptions(depends_on=[dependency_update_command])
            )

            # Update the Helm repository index
            helm_repo_index_command = command.local.Command(
                f"helm_repo_index_{name}",
                create=f"helm repo index {local_repo_path} --url file://{local_repo_path}",
                opts=pulumi.ResourceOptions(depends_on=[package_chart_command])
            )

            return helm_repo_index_command, chart_path
        finally:
            shutil.rmtree(tmpdirname)

    if isinstance(image_tag, pulumi.Output):
        return image_tag.apply(package_chart_inner)
    else:
        return package_chart_inner(image_tag)
e
is there a way to group a few things together so they run synchronously?
Add artificial dependencies between them: https://www.pulumi.com/docs/iac/concepts/options/dependson/