Skip to content

Commit

Permalink
Convert snow app deploy to v2-native
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-fcampbell committed Oct 8, 2024
1 parent 8402b55 commit f792e74
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
30 changes: 10 additions & 20 deletions src/snowflake/cli/_plugins/nativeapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def app_teardown(

@app.command("deploy", requires_connection=True)
@with_project_definition()
@nativeapp_definition_v2_to_v1()
@single_app_and_package()
def app_deploy(
prune: Optional[bool] = typer.Option(
default=None,
Expand Down Expand Up @@ -345,16 +345,6 @@ def app_deploy(
Creates an application package in your Snowflake account and syncs the local changes to the stage without creating or updating the application.
Running this command with no arguments at all, as in `snow app deploy`, is a shorthand for `snow app deploy --prune --recursive`.
"""

assert_project_type("native_app")

if force:
policy = AllowAlwaysPolicy()
elif interactive:
policy = AskAlwaysPolicy()
else:
policy = DenyAlwaysPolicy()

has_paths = paths is not None and len(paths) > 0
if prune is None and recursive is None and not has_paths:
prune = True
Expand All @@ -364,24 +354,24 @@ def app_deploy(
prune = False
if recursive is None:
recursive = False

if has_paths and prune:
raise IncompatibleParametersError(["paths", "--prune"])

cli_context = get_cli_context()
manager = NativeAppManager(
project_definition=cli_context.project_definition.native_app,
ws = WorkspaceManager(
project_definition=cli_context.project_definition,
project_root=cli_context.project_root,
)

bundle_map = manager.build_bundle()
manager.deploy(
bundle_map=bundle_map,
package_id = options["package_entity_id"]
ws.perform_action(
package_id,
EntityActions.DEPLOY,
prune=prune,
recursive=recursive,
local_paths_to_sync=paths,
paths=paths,
validate=validate,
policy=policy,
interactive=interactive,
force=force,
)

return MessageResult(
Expand Down
12 changes: 9 additions & 3 deletions src/snowflake/cli/_plugins/nativeapp/v2_conversions/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,20 @@ def wrapper(*args, **kwargs):
is_package = isinstance(entity, ApplicationPackageEntityModel)
key = "package_entity_id" if is_package else "app_entity_id"
kwargs[key] = entity_id

cm = get_cli_context_manager()

# Override the project definition so that the command operates on the new entities
cm.override_project_definition = pdfv2

# Override the template context so that templates refer to the new entities
# Reuse the old ctx.env and other top-level keys in the template context
# since they don't change between v1 and v2
pdfv2_dump = pdfv2.model_dump(
exclude_none=True, warnings=False, by_alias=True
)
cm.override_template_context = cm.template_context | dict(
ctx=pdfv2_dump
)
new_ctx = pdfv2_dump | dict(env=cm.template_context["ctx"]["env"])
cm.override_template_context = cm.template_context | dict(ctx=new_ctx)
else:
package_entity_id = kwargs.get("package_entity_id", "")
app_entity_id = kwargs.get("app_entity_id", "")
Expand Down
7 changes: 4 additions & 3 deletions tests_integration/nativeapp/test_feature_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,16 @@ def test_sql_templating_emits_counter(
CLICounterField.PACKAGE_SCRIPTS: 0,
},
),
# ensure that package scripts are picked up
# package scripts are auto-converted to post deploy scripts in v1
(
"app deploy",
"integration_external",
{
CLICounterField.SNOWPARK_PROCESSOR: 0,
CLICounterField.TEMPLATES_PROCESSOR: 0,
CLICounterField.POST_DEPLOY_SCRIPTS: 0,
CLICounterField.PACKAGE_SCRIPTS: 1,
CLICounterField.PDF_TEMPLATES: 1,
CLICounterField.POST_DEPLOY_SCRIPTS: 1,
CLICounterField.PACKAGE_SCRIPTS: 0,
},
),
# ensure post deploy scripts are picked up for v2
Expand Down

0 comments on commit f792e74

Please sign in to comment.