In the new envd v1 release, the syntax for defining environments has been improved. The key benefits of the v1 syntax include:
Enhanced support for custom base images - v1 environments can utilize any base image and inherit configurations such as environment variables, working directory, and entrypoint.
Production ready - v1 syntax can disable the development tools for production use, enabling parity between local development and deployed environments.
A faster build with the Moby builder:
envdv1 can utilize BuildKitd in Moby to decrease image conversion time.
These improvements make envd v1 a powerful tool for streamlining development workflow and enabling portable, production-grade environments. This guide will cover the changes in v1 syntax, how to upgrade from v0, and best practices for using envd in production environments.
To use the v1, all you need is to declare the version in the first line of the
# syntax=v1 def build(): base(image="ubuntu:20.04", dev=True) install.conda() install.python()
You can use any base images. The
dev flag will enable the development tools, such as
starship, etc. If you want to use the environment in production, you can set
dev=False to disable the development tools.
Conda and Python are no longer installed by default. You can use
install.python() to install them if necessary. Or you can choose to use a Python official base image like
For CUDA toolkit, the following codes have the same effect.
# use `install` install.cuda(version="11.2.2", cudnn="8") # replace the base image base(image="nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04")
Upgrade from v0
The main difference is how to declare the base image with language support. Here is a comparison between v0 and v1 syntax.
def build(): base(language="python3") install.python_packages(name = [ "numpy", ]) shell("zsh")
# syntax=v1 def build(): base(dev=True) install.conda() install.python() install.python_packages(name = [ "numpy", ]) shell("zsh")
To enable the
moby builder, you can create a new context like:
envd context create --name moby --builder moby-worker --use
To bridge the gap between development and production, you can define the environment as following:
# syntax=v1 def dependencies(): install.conda() install.python() install.cuda(version="11.2.2", cudnn="8") install.python_packages(name = [ "torch", "transformers", ]) def build(): base(dev=True) dependencies() shell("zsh") def prod(): base(dev=False) dependencies()
Then you can use
envd up -f :build to work in the development environment and
envd build -f :prod --output type=image,name=registry/username/project,push=true to build and push the production images.