Skip to content
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
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
60 changes: 60 additions & 0 deletions .github/workflows/sis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Deploy to Streamlit in Snowflake
on:
# manual trigger
workflow_dispatch:
# TODO other triggers
# does build and deploy app on push
# push:
# paths:
# - "data/*.csv"
# - "app/**"
# - "streamlit_app.py"
env:
SNOWFLAKE_DEFAULT_CONNECTION_NAME: "workflow"
SNOWFLAKE_CONNECTIONS_WORKFLOW_ACCOUNT: ${{ secrets.SNOWFLAKE_ACCOUNT }}
SNOWFLAKE_CONNECTIONS_WORKFLOW_USER: ${{ secrets.SNOWFLAKE_USER }}
SNOWFLAKE_CONNECTIONS_WORKFLOW_PRIVATE_KEY_PASSPHRASE:
${{ secrets.PRIVATE_KEY_PASSPHRASE }}
SNOWFLAKE_CONNECTIONS_WORKFLOW_PRIVATE_KEY_RAW:
${{ secrets.PRIVATE_KEY_RAW }}
# update it as per your application settings
STREAMLIT_APP_NAME: my_app
STREAMLIT_APP_WH: my_wh
STREAMLIT_APP_DB: my_app_db
STREAMLIT_APP_SCHEMA: apps
STREAMLIT_APP_DATA_SCHEMA: data
jobs:
Deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.GITHUB_REF_NAME }}
- uses: Snowflake-Labs/[email protected]
with:
cli-version: "latest"
default-config-file-path:
${{ github.workspace }}/config/config.toml
- name: Check Version and Verify Connection
env:
PRIVATE_KEY_PASSPHRASE: ${{ secrets.PRIVATE_KEY_PASSPHRASE }}
run: |
snow --version
snow connection test
echo "Using branch $GITHUB_REF_NAME"

- name: Deploy Streamlit App
env:
PRIVATE_KEY_PASSPHRASE: ${{ secrets.PRIVATE_KEY_PASSPHRASE }}
run: |
snow streamlit deploy --replace \
--database $STREAMLIT_APP_DB --schema $STREAMLIT_APP_SCHEMA
working-directory: app

- name: Get App URL
env:
PRIVATE_KEY_PASSPHRASE: ${{ secrets.PRIVATE_KEY_PASSPHRASE }}
run: |
snow streamlit get-url $STREAMLIT_APP_NAME \
--database $STREAMLIT_APP_DB --schema $STREAMLIT_APP_SCHEMA
working-directory: app
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.direnv
**/.envrc
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ This is filler text, please replace this with a explanatory text about further r
- Resource 1
- Resource 2
- Resource 3


## GitHub Workflow

The [GitHub workflow](./.github/workflows/sis.yml) allows you to deploy this application to Snowflake.
5 changes: 5 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.packages/
.venv/
app.zip
__pycache__
TODO.md
Empty file added app/common/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions app/common/data_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from snowflake.snowpark.session import Session
from snowflake.snowpark.table import Table
import pandas as pd
import os

import streamlit as st
import logging

logger = logging.getLogger("truck_analyis")


@st.cache_resource(show_spinner=True)
def get_active_session() -> Session:
"""Create or get new Snowflake Session"""
conn = st.connection(
os.getenv("SNOWFLAKE_CONNECTION_NAME", "snowflake"), type="snowflake"
)
return conn.session()
6 changes: 6 additions & 0 deletions app/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: sf_env
channels:
- snowflake
dependencies:
- streamlit=1.35.0
- snowflake-snowpark-python
20 changes: 20 additions & 0 deletions app/snowflake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
definition_version: "2"
env:
STREAMLIT_APP_NAME: my_app
STREAMLIT_APP_DB: my_app_db
STREAMLIT_APP_SCHEMA: apps
STREAMLIT_APP_WH: my_wh
entities:
todos_app:
type: streamlit
identifier:
name: <% ctx.env.STREAMLIT_APP_NAME %>
database: <% ctx.env.STREAMLIT_APP_DB %>
schema: <% ctx.env.STREAMLIT_APP_SCHEMA %>
main_file: streamlit_app.py
query_warehouse: <% ctx.env.STREAMLIT_APP_WH %>
stage: <% ctx.env.STREAMLIT_APP_NAME %>
artifacts:
- streamlit_app.py
- environment.yml
- common/data_utils.py
5 changes: 5 additions & 0 deletions app/streamlit_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import streamlit as st

st.title("🎈 App Name")

st.write("Hello world!")
5 changes: 5 additions & 0 deletions config/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
default_connection_name = "workflow"

[connections]
[connections.workflow]
authenticator="SNOWFLAKE_JWT"
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
streamlit>=1.26.0
streamlit=1.35.0
5 changes: 0 additions & 5 deletions streamlit_app.py

This file was deleted.

1 change: 1 addition & 0 deletions streamlit_app.py