Container Services - Introduction
Goal of this tutorial is to move our Streamlit in Snowflake "SiS" application into Snowflake container services. This is a typical workflow to remove the Snowflake headers around the application.
Video
Requirements
Download
- Files (Link)
Setup
Lets go through some setup before to go into our application.
Snowflake
Let's start by setting up Snowflake before we jump to docker. Create a worksheet in snowflake and add / run the code below.
If you don't have a database, schema or warehouse yet.
use role sysadmin;
-- Create a database to store our schemas.
create database raw;
-- Create the schema. The schema stores all our objectss.
create schema raw.website;
/*
Warehouses are synonymous with the idea of compute
resources in other systems. We will use this
warehouse to call our user defined function.
*/
create warehouse if not exists developer
warehouse_size = xsmall
initially_suspended = true;
use database raw;
use schema website;
use warehouse developer;
repository_url |
---|
sfsenorthamerica-wilczak-videos2.registry.snowflakecomputing.com/raw/website/images |
Docker
Our goal is to run the application locally and check if it works and then upload the built docker image to our snowflake image repository so it can be hosted on Snowflake container services.
Note
Please install docker desktop - https://www.docker.com/products/docker-desktop/
Using terminal, navigate to the folder that has the docker file you downloaded.
Now you can go to Localhost or the direct local url http://127.0.0.1:8501/. To see what the website will look like before we upload it.
Upload
Now that we have our image created. Lets upload it to Snowflake. We will need our Snowflake image url (1) that we got from our Snowflake setup.
-
repository_url sfsenorthamerica-wilczak-videos2.registry.snowflakecomputing.com/raw/docker/images
Next docker login to our snowflake image repo and upload the image. We will use the login name that has access to sysadmin role.
If your user is using MFA - Please enable token caching before uploading
Docker will upload the image in a multi threaded way, if you have MFA it will ask you a hundred times. To prevent this we suggest to enable token caching.
Finally push the image to your image repository living on Snowflake.
The push refers to repository [sfsenorthamerica-wilczak-videos2.registry.snowflakecomputing.com/raw/website/docker/website]
5c496785191b: Pushed
af426fba40ce: Pushed
89732b928ca7: Pushed
c3fcfdebbdeb: Pushed
5930c727f5d3: Pushed
fe4e91e03123: Pushed
1ee7a83db2c7: Pushed
57bbd9d1460f: Pushed
2920aec4783e: Pushed
61255a2b6a94: Pushed
4c519b360763: Pushed
abf3d7b50651: Pushed
a0b7220ad76b: Pushed
website: digest: sha256:f0ef0b8e2a6e9fa218fd7cd771bce6befeecd1d62a26c740df8fb8b45ed6831c size: 3045
Run
Lets switch back to snowflake to start our container.
Start Service
Create the service to host the container with our inline service specification..
ingress_url |
---|
br2sbye-sfsenorthamerica-wilczak-videos2.snowflakecomputing.app |
Set default role
Before we go to our URL. Please make sure your default role is set to Sysadmin
Now go to the webiste url, login and see your amazing website!
Clean up script
If you don't plan to keep this running. Which I don't reccomend considering it's using .11 credits per hour. Here is a clean up script.