Skip to content

Upgrade to envd v1

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: envd v1 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.

Syntax changes

To use the v1, all you need is to declare the version in the first line of the build.envd file.

python
# 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 git, vim, 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.conda() & install.python() to install them if necessary. Or you can choose to use a Python official base image like base(image="python:3.11").

For CUDA toolkit, the following codes have the same effect.

python
# 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.

  • v0
python
def build():
    base(language="python3")
    install.python_packages(name = [
        "numpy",
    ])
    shell("zsh")
  • v1
python
# syntax=v1

def build():
    base(dev=True)
    install.conda()
    install.python()
    install.python_packages(name = [
        "numpy",
    ])
    shell("zsh")

Best practices

Moby builder

To enable the moby builder, you can create a new context like:

bash
envd context create --name moby --builder moby-worker --use

Consistent dependencies

To bridge the gap between development and production, you can define the environment as following:

python
# 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.

Additional resources

Released under the Apache-2.0 License. Built with VitePress.