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
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? :)
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.