Skip to content

Commit

Permalink
add as-template to buildflow build
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshTanke committed Nov 13, 2023
1 parent b30151f commit 77e612c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions buildflow/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,23 +189,35 @@ def build(
[],
help="Files to ignore when building, these can be the same syntax as .gitignore", # noqa
), # noqa
as_template: bool = typer.Option(
False,
help="Whether to output the build as a template, this will not include the flowstate.yaml file.", # noqa
),
):
buildflow_config = BuildFlowConfig.load()
sys.path.insert(0, "")
imported = utils.import_from_string(buildflow_config.entry_point)
if not build_path:
build_path = os.path.join(os.getcwd(), ".buildflow", "build", "build.flow")
if as_template:
build_path = os.path.join(
os.getcwd(), ".buildflow", "build", "template.flow"
)
else:
build_path = os.path.join(os.getcwd(), ".buildflow", "build", "build.flow")
build_path = os.path.abspath(build_path)
path = pathlib.Path(build_path)
path.parent.mkdir(parents=True, exist_ok=True)
final_excludes = _BASE_EXCLUDE + ignores + buildflow_config.build_ignores
if as_template:
final_excludes.extend([".buildflow", "buildflow.yaml"])
print(f"Generating buildflow build at:\n {build_path}")
if isinstance(imported, (buildflow.Flow)):
flowstate = imported.flowstate()
with zipfile.ZipFile(build_path, "w", zipfile.ZIP_DEFLATED) as zipf:
zipdir(os.getcwd(), zipf, excludes=final_excludes)
yaml_str = yaml.dump(flowstate.to_dict())
zipf.writestr("flowstate.yaml", yaml_str)
if not as_template:
yaml_str = yaml.dump(flowstate.to_dict())
zipf.writestr("flowstate.yaml", yaml_str)
else:
typer.echo("build must be run on a flow")
typer.Exit(1)
Expand Down

0 comments on commit 77e612c

Please sign in to comment.