When working with containers it's useful to have a proper shell inside the environment for debugging or general research purposes. This repository contains the package definition and a Github action that creates and pushes a container with bash as a webshell:
There are two sample images provided:
- Nix-based one
- Debian-based one
The instructions below could be applied to either one of them
Follow the common setup tutorial to have the image repository and a compute pool in your account.
-
Fork/clone this repository in your Github account
-
In your copy of this repository add action secrets (repository Settings > Secrets and variables > Actions):
REGISTRY_URL
:<snowflakeOrg-snowflakeAccount>.registry.snowflakecomputing.com/<database>/<schema>/<registry_name>
. See output ofSHOW IMAGE REPOSITORIES
for exact valueSNOWFLAKE_USER
: username of Snowflake user that has access to the image repositorySNOWFLAKE_PASSWORD
: password forSNOWFLAKE_USER
-
Run "Build and push image to Snowflake" action for the chosen image
SPCS (at the time of writing) only works with x86_64
images. So, on an M1
machine you would need access to a remote builder capable of building x86_64
packages – for example a virtual machine.
The nix-based image requires nix
.
-
Have
nix
available (optionally withdirenv
) -
Clone the repository
-
Configure the environment variables:
If using
direnv
: edit.envrc
.Otherwise, define
REGISTRY_URL
,SNOWFLAKE_USER
andSNOWFLAKE_PASSWORD
variables -
Run
nix run <pathToClonedRepo>#buildAndPushToSpcs -- "ttydContainer"
Change directory to ./non-nix/
and follow the "Build image and upload" steps
from Snowpark container services
tutorial.
After the image has been pushed to Snowflake (through action or from local machine).
-
Create the service:
CREATE SERVICE <serviceName> IN COMPUTE POOL <computePoolName> FROM SPECIFICATION $$ spec: containers: - name: <container_name> image: /<database>>/<schema>/<registry_name>/<containerTag>:latest command: - "ttyd" - "--port=8000" - "--writable" - "sh" endpoints: - name: ttyd port: 8000 public: true $$;
where
<containerTag>
isnix-ttydcontainer
orttydcontainer
. Check action logs for the specific value. -
Wait for endpoints provisioning to complete (you can monitor the output of
SHOW ENDPOINTS IN SERVICE <serviceName>
) -
Open the
ttyd
endpoint URL
The container comes with certain tools pre-installed (see the list in package definition).
Additional packages can be temporarily pulled in as:
$ nix shell nixpkgs#hello
$ hello
Hello World!
# or
$ nix run nixpkgs#hello
Hello World!
This works for any package from nixpkgs or for any flake reference.
To add/remove a package to the container, edit the container definition file and rerun the pipeline.
The main mechanism through which the shell is displayed in the browser is ttyd which can be added to any other Docker image.
A sample Debian-based image is provided in this repo.