Skip to content

Instantly share code, notes, and snippets.

@hamelsmu
Last active May 6, 2024 21:58
Show Gist options
  • Save hamelsmu/0641c240817e5d2b6a3a42508fd47ab6 to your computer and use it in GitHub Desktop.
Save hamelsmu/0641c240817e5d2b6a3a42508fd47ab6 to your computer and use it in GitHub Desktop.
Interesting learnings from modal

Mandatory Packages

The below script will print all the packages modal installs in every image. If these packages cannot be installed, the image will not be built and you will have a bad time.

from modal import Image, App
app = App("01a_modal_requirements")

def see_reqs():
    with open('/modal_requirements.txt') as f: print(f.read())
img = Image.debian_slim().run_function(see_reqs)

@app.function(image=img)
def f(): ...

Running this returns:

grpclib==0.4.7
importlib_metadata==4.8.1
ipython>=7.34.0
protobuf>=3.19.0
python-multipart>=0.0.5
rich==12.3.0
tblib==1.7.0
toml==0.10.2
typer==0.6.1
types-certifi==2021.10.8.3
types-toml==0.10.4
typeguard>=3.0.0
Creating image snapshot...
Finished snapshot; took 1.38s
Finished image build for im-Nzy3j17os08EF2tsf0QGdu

@local_entrypoint

Its slightly buried in the docs but pretty cool way of:

  • turning py script into a CLI
  • having multiple entrypoints with the :: syntax

I love the simplicity of it. Should I use it for all my non-modal scripts? :)

Incremental building of images

You can incrementally build docker images as demonstrated in this file, which is a great way of having a "base image" in modal that is the foundation for other images.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment