Authoring a Compute Module in Foundry

Beta

The Compute Modules feature is in beta and may not be available on all enrollments.

To author code to use in a Compute module in Foundry, first navigate to a Project where you would like to save the repository. Then, select New and choose Code Repository. Click on Compute modules and select the language you’d like to work in to bootstrap your repository with a template. Finally, select Initialize repository.

For Python, app.py will be the most relevant file. Each function in this file will be mounted as an endpoint in the Compute Module when you deploy it.

You must not change the name or location of the app.py file. Any function defined at the root of the file will be "callable" by its case-sensitive name. You can write all of your code in this file, or write it across files. If you do create multiple files, you must only use relative imports. For example, if you create another file in the same directory as app.py called myExampleLib.py with a class called ExampleClass, you can import it into app.py as follows:

from .myExampleLib import ExampleClass # This will work, the '.' makes it relative
from myExampleLib import ExampleClass # This will not work

The final requirement is that the Python functions must return an object that is JSON serializable.

Author your new function in the app.py file, select Commit to save, and when you are ready, select Tag version. Tagging triggers checks on your repository, which will build a new Docker image that you can deploy in a compute module. Once checks have passed, you will have a Docker image ready to use in a compute module.

For an in-depth guide, see the documentation on Deploying a Compute Module.

Authoring

Dependencies

You can manage dependencies by adjusting the meta.yaml file, such as by adding a package name and version (pinning the version will improve build performance) under the Run section. By default, these repositories have external-conda-forge as a backing repository. If you need a package from a different artifact repository, feel free to add one.

Build Configurations

The gradle.properties hidden file allows you to manage some build configurations. Some of the important fields are:

userImageName = myimage
baseImageTag = xyz

The userImageName field will determine the name of the image this repo produces at build time. If you do not manually bump the tag between builds, the previous version will get overwritten. If this occurs, restart your build to apply your updated code quickly; otherwise, the code will update within the next ~24 hours.

The baseImageTag controls the version of the Conda base image that will be used at build time. Versions below 0.15.0 will need to select No Runtime, versions >= 0.15.0 will need to select COMPUTE_MODULE_RUNTIME_V1. It should generally be safe to bump this version.