Native Application Framework 的声明式共享中的应用程序包

As a provider, you create an application package to bundle your data content and notebooks into a Declarative Native App. This topic explains what an application package is and describes the high-level steps to create one, from creating the initial package to adding your manifest and notebook files.

应用程序包和实时版本

应用程序包是构成应用程序的所有文件的容器,包括 清单 文件和任何 Snowflake 笔记本。创建应用程序包时,还会创建应用程序包的实时(暂存)版本。实时版本是一个开发工作区,您可以在其中添加或更新文件(例如清单文件和笔记本文件),并在发布前预览和测试体验。

对应用程序的实时版本感到满意后,您可以提交实时版本以创建新的应用程序包的不可变版本,然后可以发布该版本。

使用实时版本进行开发,通过维护准备发布的应用程序包的单个不可变版本和用于开发的单个实时版本,从而简化了版本管理。Snowflake Native App Framework 自动管理应用程序包的版本控制,因此您无需手动跟踪版本号。

Snowflake Native App Framework 自动维护任何应用程序包的实时版本。即使您移除了实时版本,系统也会根据应用程序包的最后提交版本自动创建一个新的实时版本。

创建应用程序包

提供商开发和测试 应用程序包。应用程序包包含在应用程序中共享数据所需的文件,并定义了使用者如何访问数据。

该过程涉及以下步骤:

  1. **创建应用程序包文件**(仅限第一次):创建稍后发布的应用程序包文件。这还会创建应用程序包的实时版本。

  2. 向应用程序包中添加内容

    1. 创建或更新清单文件:此文件介绍了应用程序包及其内容。

    2. 下载笔记本文件。如果要添加笔记本,请下载要在应用程序包中添加的副本。

    3. 将文件添加到应用程序包的实时版本中

  3. 构建应用程序包:允许您验证清单文件是否有效,以及清单文件中的所有链接是否正确。

  4. 测试应用程序。安装应用程序并试用。进行更改并重建。

  5. 提交应用程序包:创建可发布的应用程序的新不可变版本。

  6. 发布应用程序包。使用已发布的包,您可以在 Snowflake Marketplace 上私下或公开创建新的列表。

Tutorial: Getting started with Declarative Native Apps 中介绍了此过程。本部分包括不同开发阶段可用选项的其他详细信息。

显示创建应用程序包的步骤的图:添加实时包、构建、提交和发布。该图还显示了可以跳过的可选步骤,以便一次性完成构建、提交和发布实时版本的操作。

创建新的应用程序包

Create an Declarative Native App package using the command: CREATE APPLICATION PACKAGE ... TYPE=DATA:

CREATE APPLICATION PACKAGE DECL_SHARE_APP_PKG TYPE = DATA;
Copy

新的空应用程序包已创建。这还会创建可以编辑的应用程序包的实时版本。

向应用程序包中添加内容

在应用程序包中添加以下内容:

  • 清单 文件(必填):基于文本的文件,可定义应用程序的结构。

  • Snowflake 笔记本 文件(可选):基于文本的文件,可充当使用者体验的前端,可引用共享的视图和表。这些文件还可以包括代码、引用可视化,以及包括帮助呈现数据的逻辑。

应用程序包组件图

创建或更新清单文件

提供商创建或更新 清单 文件,该文件描述应用程序包及其共享内容,例如笔记本、表和视图。该文件定义了其他元数据,例如该应用程序所包含的 应用程序角色

清单文件必须命名为 manifest.yml,并且必须添加到应用程序包的根级别。

For more information, see Declarative Native App manifest reference. The associated Tutorial: Getting started with Declarative Native Apps includes an example manifest file.

Create or update a manifest file from a Snowflake data share

备注

The following content is not supported by Snowflake. All code is provided "AS IS" and without warranty.

If you have an existing data share in Snowflake, you can automatically create a manifest file using the open-source Manifest from Share tool. This Snowflake-provided tool generates a manifest file based on the objects in a specified share. The tool also includes options to customize the generated manifest file. You can use this tool in the following ways:

  • Generate a manifest file using the command-line interface (CLI).

  • Integrate the tool into an existing Python automation workflow as a library.

For more information about how to download and use the tool, see the Snowflake Manifest from Share (https://github.com/snowflakedb/native-apps-examples/tree/main/snowflake-manifest-from-share-library) repository on GitHub.

备注

The Manifest from Share tool only creates the manifest file using the data share's databases, schemas, tables and views. The tool doesn't include any other objects in the generated manifest file.

获取笔记本文件

如果 Snowflake 笔记本 要包含在应用程序中,请下载笔记本文件的副本,以便将其包含在应用程序包中。

通过 Snowsight:

  1. In the navigation menu, select Projects » Notebooks, and then select the notebook you want to download.

  2. On the left pane, next to your notebook, select ... » Download.

文件会下载到本地计算机上,文件名为 <notebook_name>.ipynb

备注

The notebook environment has a set of pre-installed Anaconda packages, including Python and Streamlit. If your notebook uses additional Anaconda packages, you must add those as packages to your notebook so they can be used in the consumer's environment. For information about how to add Anaconda packages to your notebook, see the 将 Anaconda 包添加到笔记本.

将文件添加到实时版本中

通过 snow://package/<package_name>/versions/LIVE/ URL 方案,使用 Snowflake CLI 中的 SQL 命令添加和访问文件。示例:

  • 将文件添加到应用程序包中:

    snow sql -q "PUT file:////Users/test_user/Documents/manifest.yml  snow://package/DECL_SHARE_APP_PKG/versions/LIVE/ OVERWRITE=TRUE AUTO_COMPRESS=false;"
    
    snow sql -q "PUT file:////Users/test_user/Documents/NOTEBOOK.ipynb  snow://package/DECL_SHARE_APP_PKG/versions/LIVE/ OVERWRITE=TRUE AUTO_COMPRESS=false;"
    
    Copy
  • 验证文件是否在应用程序包中:

    snow sql -q "LIST snow://package/DECL_SHARE_APP_PKG/versions/LIVE"
    
    Copy
    +--------------------------------------------------------------------------------+
    | name                          | size | md5     | last_modified                 |
    |-------------------------------+------+---------+-------------------------------|
    | /versions/live/manifest.yml   | 304  | 843a... | Wed, 23 Jul 2025 08:27:26 GMT |
    | /versions/live/NOTEBOOK.ipynb | 832  | b014... | Wed, 23 Jul 2025 04:32:22 GMT |
    +--------------------------------------------------------------------------------+
    
  • 从应用程序包中下载文件:

    snow sql -q "GET snow://package/<package_name>/versions/LIVE/manifest.yml file://manifest.yml"
    
    Copy
  • 从应用程序包中移除内容:

    snow sql -q "RM snow://package/<package_name>/versions/LIVE/manifest.yml"
    
    Copy

构建应用程序包

Build a testable version of the app (and verify that the manifest file is valid and all links work) with the command: ALTER APPLICATION PACKAGE ... BUILD.

ALTER APPLICATION PACKAGE DECL_SHARE_APP_PKG BUILD;
Copy

如果清单文件中存在任何错误,则构建操作将失败,并提供有关如何修复错误的信息。更正这些错误并重建应用程序包。

构建的应用程序仍处于实时状态,您可以继续对应用程序包进行更改。

跳过!

For updates that don't require further testing, you can skip ahead by building, committing, and releasing an application package all at once using the ALTER APPLICATION PACKAGE ... RELEASE LIVE VERSION command.

ALTER APPLICATION PACKAGE DECL_SHARE_APP_PKG RELEASE LIVE VERSION;
Copy

测试应用程序

构建应用程序包后,提供商可以在实时环境中执行基本测试。

使用以下命令从应用程序包安装应用程序:CREATE APPLICATION ... FROM APPLICATION PACKAGE。例如:

CREATE APPLICATION DECL_SHARE_APP FROM APPLICATION PACKAGE DECL_SHARE_APP_PKG
Copy

根据需要更新应用程序包中的文件,然后使用以下命令查看其是否有效:ALTER APPLICATION PACKAGE … UPGRADE USING VERSION LIVE

ALTER APPLICATION PACKAGE DECL_SHARE_APP_PKG UPGRADE USING VERSION LIVE;
Copy

要测试某些功能(例如应用程序角色),必须先发布应用程序包的新版本,然后使用单独的使用者账户进行测试。有关更多信息,请参阅 Install a Declarative Native App 和 。

可选:重置对实时版本的编辑

If the edits made to the live version of the application package are no longer needed, you can reset the application package to the state before the edits were made with the command: ALTER APPLICATION PACKAGE ... ABORT LIVE VERSION

ALTER APPLICATION PACKAGE <package_name> ABORT LIVE VERSION;
Copy

使用上述命令移除当前实时版本时,系统会创建一个新的实时版本,其内容与应用程序包的上次提交版本相同。实时版本将重置为上次提交的版本,并且对实时版本所做的所有变更都将丢弃。

提交应用程序包

提供商构建应用程序新的不可变版本,该版本无法编辑,可以发布。

使用 ALTER APPLICATION PACKAGE 命令:

ALTER APPLICATION PACKAGE <package_name> COMMIT;
Copy

应用程序包的实时版本已移除。根据新的提交版本创建应用程序包新的实时版本,以供进一步开发。

发布应用程序包

使用 ALTER APPLICATION PACKAGE ... RELEASEALTER APPLICATION PACKAGE ... RELEASE LIVE VERSION 命令发布应用程序包:

  • 发布已提交的应用程序包:

    ALTER APPLICATION PACKAGE <package_name> RELEASE;
    
    Copy
  • 构建、提交和发布应用程序包的实时版本:

    ALTER APPLICATION PACKAGE <package_name> RELEASE LIVE VERSION;
    
    Copy

发布应用程序包会执行以下操作:

  • 使已提交的应用程序可以与使用者共享。

  • 如果提供商已与使用者共享应用程序,则新版本将自动提供给这些使用者。

  • 如果 Snowflake Marketplace 上已有该应用程序的实时版本,则新版本会自动提供给已安装该应用程序的使用者。

发布应用程序包后,您可以在 Snowflake Marketplace 上私下或公开为应用程序创建新列表。有关更多信息,请参阅 使用声明式共享创建列表

语言: 中文