Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1731569 SPCS easy run mode app example #17

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

**Note**: Snowflake CLI is in Public Preview (PuPr). You can find the official documentation and download links [here](https://docs.snowflake.com/en/developer-guide/snowflake-cli-v2/index).

This repository contains example applications built using the [Snowflake Native App](https://docs.snowflake.com/en/developer-guide/native-apps/native-apps-about) Framework. These examples have been built and are supported by Snowflake Inc., are self-contained, and can be deployed directly to your account using Snowflake CLI.
This repository contains example applications built using the [Snowflake Native App](https://docs.snowflake.com/en/developer-guide/native-apps/native-apps-about) Framework. These examples have been built and are supported by Snowflake Inc., are self-contained, and can be deployed directly to your account using Snowflake CLI.

## Deploying example applications

Expand All @@ -17,18 +17,19 @@ Some applications require other account-level setup before they can be properly

## Available examples

| Application | Description |
| --- | --- |
| [Account Privileges](./account-privileges/) | How to add account privileges to an object reference within a native application. |
| [Custom Billing Events](./custom-billing-events/) | How to bill costs from the provider side by adding a billing event to a procedure call. |
| [Data Mapping](./data-mapping/) | Accompaniment to the [Data Mapping in Snowflake Native Apps using Streamlit](https://quickstarts.snowflake.com/guide/data_mapping_in_native_apps/index.html?index=..%2F..index#0) quickstart. |
| [External Access Integration](./external-access-integration/) | How to create an external access integration and connect to an API within a native application. |
| [Mailorder](./mailorder/) | How to implement the business operations of an imaginary mail-order business within a native application using Snowpark. |
| [Object-level References](./object-level-references/) | A simple dashboard to show how to interact with the object-level references and bindings. |
| [Reference Usage](./reference-usage/) | How to share a provider table with a native application whose data is replicated to any consumer in the data cloud. |
| [SPCS Three-tier](./spcs-three-tier/) | A simple three-tiered web app that can be deployed in Snowpark Container Services. It queries the TPC-H 100 data set and returns the top sales clerks. |
| [Snowflake Cortex](./snowflake-cortex/) | A simple example on how to implement the Cortex Complete and to make it interact with user data. |
| [Tasks and Streams](./tasks-streams/) | How to execute a task and visualize changes using streams within a native application. |
| Application | Description |
| ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Account Privileges](./account-privileges/) | How to add account privileges to an object reference within a native application. |
| [Custom Billing Events](./custom-billing-events/) | How to bill costs from the provider side by adding a billing event to a procedure call. |
| [Data Mapping](./data-mapping/) | Accompaniment to the [Data Mapping in Snowflake Native Apps using Streamlit](https://quickstarts.snowflake.com/guide/data_mapping_in_native_apps/index.html?index=..%2F..index#0) quickstart. |
| [External Access Integration](./external-access-integration/) | How to create an external access integration and connect to an API within a native application. |
| [Mailorder](./mailorder/) | How to implement the business operations of an imaginary mail-order business within a native application using Snowpark. |
| [Object-level References](./object-level-references/) | A simple dashboard to show how to interact with the object-level references and bindings. |
| [Reference Usage](./reference-usage/) | How to share a provider table with a native application whose data is replicated to any consumer in the data cloud. |
| [SPCS Three-tier](./spcs-three-tier/) | A simple three-tiered web app that can be deployed in Snowpark Container Services. It queries the TPC-H 100 data set and returns the top sales clerks. |
| [Snowflake Cortex](./snowflake-cortex/) | A simple example on how to implement the Cortex Complete and to make it interact with user data. |
| [Tasks and Streams](./tasks-streams/) | How to execute a task and visualize changes using streams within a native application. |
| [SPCS Easy Run Mode](./spcs-easy-run-mode/) | An easy-to-use UI that helps users start their SPCS service in a few clicks after they have completed the onboarding process. |

## Contributing

Expand Down
179 changes: 179 additions & 0 deletions spcs-easy-run-mode/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python

### Python ###
# Byte-compiled / optimized / DLL files
*/__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml

# ruff
.ruff_cache/

# LSP config files
pyrightconfig.json

# End of https://www.toptal.com/developers/gitignore/api/python

output/*
snowflake.local.yml
49 changes: 49 additions & 0 deletions spcs-easy-run-mode/app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 🎈 SPCS Easy Run Mode

## Motivation

**Why we need Easy-run mode for SPCS?**

As it requires a lot of steps to try SPCS, particularly:

- Setup a image repository and a compute pool 🤔
- **Write a `Dockerfile`** (which can including many works to set up all dependencies for services) 🤯
- **Build the docker image and push it to the image repository** (auth of the registry can also be annoying 😡)
- Write Spec function to create the service and wait (even need to check `SYSTEM$GET_SERVICE_LOGS` over and over again until the service starts) 😫
- Execute the function definition query carefully ⚠️
- Check where it builds the endpoint and then access the web UI 🤷‍♀️
- ...

Now with **SPCS easy-run mode**, you can stay in Snowflake ❄️ web portal (*SnowSight UI*) without any extra effort above, launch the service by just **one click**!

## Implementation

Generally, we wrap all those queries behind into a **Native App**, which will be published in Snowflake app marketplace.

1. Build the UI using *streamlit* to take some basic information as input
2. Store the customer's code files in stage
3. Execute [Kaniko](https://github.com/GoogleContainerTools/kaniko) job service to build and publish the container image from the stored files

## Demo

Code files:

- `templates/ui.html`
- `requirements.txt`
- `service.py`

We use the [echo service example](https://docs.snowflake.com/en/_downloads/c3a8f6109048f2ecca7734c7fd3b0b3b/SnowparkContainerServices-Tutorials.zip) in [SPCS official tutorial 1](https://docs.snowflake.com/en/developer-guide/snowpark-container-services/tutorials/tutorial-1#download-the-service-code) to show how the easy-run mode works in the following demo

**What we expect to see**

1. The Echo service `ECHO_TEST` is running. `SELECT SYSTEM$GET_SERVICE_STATUS('ECHO_TEST')`
2. Web UI (after login)
3. Service function `MY_UDF` `show functions like 'MY_UDF';`


## WIP features

1. Arbitary numbers of parameters in service function
2. Arbitary numbers and paths of code files
3. Metrics and Monitoring
4. Distribute the app in public Marketplace
10 changes: 10 additions & 0 deletions spcs-easy-run-mode/app/frontend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
spec:
containers:
- name: frontend
image: /spcs_easyrun_db/spcs_easyrun_schema/spcs_easyrun_repo/frontend:latest
# env:
# SNOWFLAKE_WAREHOUSE: tutorial_warehouse
endpoints:
- name: app
port: 8501
public: true
56 changes: 56 additions & 0 deletions spcs-easy-run-mode/app/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# This is a manifest.yml file, a required component of creating a Snowflake Native App.
# This file defines properties required by the application package, including the location of the setup script and version definitions.
# Refer to https://docs.snowflake.com/en/developer-guide/native-apps/creating-manifest for a detailed understanding of this file.

manifest_version: 1

artifacts:
setup_script: setup.sql
readme: README.md
extension_code: true
container_services:
images:
- /spcs_easyrun_db/spcs_easyrun_schema/spcs_easyrun_repo/easy-run-mode:latest
- /spcs_easyrun_db/spcs_easyrun_schema/spcs_easyrun_repo/frontend:latest
default_web_endpoint:
service: public.frontend_service
endpoint: app

lifecycle_callbacks:
version_initializer: public.init



privileges:
- BIND SERVICE ENDPOINT:
description: "A service that can respond to requests from public endpoints."
required_at_setup: true
- CREATE COMPUTE POOL:
description: "Permission to create compute pools for running services"
required_at_setup: true
- CREATE WAREHOUSE:
description: "To create warehouses for executing tasks"
required_at_setup: true

references:
- external_access_reference:
label: "EAI Reference"
description: "External Access Integration (EAI) in the consumer account that exists outside the APPLICATION object."
privileges:
- USAGE
object_type: EXTERNAL ACCESS INTEGRATION
multi_valued: false
register_callback: core.register_single_callback
configuration_callback: core.get_configuration
required_at_setup: true


configuration:
grant_callback: public.start_frontend
log_level: INFO
trace_level: ALWAYS
telemetry_event_definitions:
- type: ERRORS_AND_WARNINGS
sharing: MANDATORY
- type: DEBUG_LOGS
sharing: MANDATORY
Loading
Loading