

# Create a conda build recipe for Blender
<a name="create-conda-recipe-blender"></a>

Blender is free to use and simple to package with conda, which makes it a good starting point for learning how to create conda packages for AWS Deadline Cloud (Deadline Cloud). The Blender Foundation provides [application archives](https://download.blender.org/release/Blender4.5/) for multiple operating systems. The [Blender 4.5 sample recipe](https://github.com/aws-deadline/deadline-cloud-samples/tree/mainline/conda_recipes/blender-4.5) in the Deadline Cloud samples repository on GitHub packages these archives into a conda package.

## Understanding the recipe
<a name="blender-recipe-structure"></a>

The [recipe.yaml](https://github.com/aws-deadline/deadline-cloud-samples/blob/mainline/conda_recipes/blender-4.5/recipe/recipe.yaml) file defines the package metadata, source URLs, and build options in [rattler-build template syntax](https://rattler-build.prefix.dev/latest/reference/recipe_file/#spec-reference). The recipe specifies the version number once and provides different source URLs based on the operating system.

The `build` section in `recipe.yaml` turns off binary relocation and dynamic shared object (DSO) linking checks. These options control how the package works when installed into a conda virtual environment at any directory prefix. The default values used in the `build` section are designed for packaging each dependency library separately, but when binary repackaging an application, you need to change them. Blender does not require any RPATH adjustment because the application archives are built with relocatability in mind. See [Create a conda recipe for Maya](create-conda-recipe-maya.md) for an example of adding relocatability.

During the package build, the [build.sh](https://github.com/aws-deadline/deadline-cloud-samples/blob/mainline/conda_recipes/blender-4.5/recipe/build.sh) or [build\$1win.sh](https://github.com/aws-deadline/deadline-cloud-samples/blob/mainline/conda_recipes/blender-4.5/recipe/build_win.sh) script runs to install files into the environment. These scripts copy the installation files into `$PREFIX/opt/blender`, create symlinks from `$PREFIX/bin` (on Linux), and set up activation scripts that configure environment variables such as `BLENDER_LOCATION`. On Windows, the activation script adds the Blender directory to the PATH instead of creating symlinks.

The Windows build script uses `bash` instead of a `cmd.exe` .bat file for consistency across platforms. You can install [git for Windows](https://gitforwindows.org/) to provide `bash` for package building.

The recipe also includes a `deadline-cloud.yaml` file that specifies the conda platforms and metadata for submitting automated package build jobs to Deadline Cloud. For more information, see [Submit a package build job](automate-package-builds.md#automate-submit-package-job).

## Building the Blender package
<a name="s3-channel-build-blender"></a>

Use `rattler-build publish` to build the Blender 4.5 recipe and publish the package to a channel. You can publish to a local filesystem channel for testing or directly to an Amazon S3 channel for production use. If you completed the setup in [Build and test packages locally](build-test-packages-locally.md), run the following command from the `conda_recipes` directory.

```
rattler-build publish blender-4.5/recipe/recipe.yaml \
    --to file://$HOME/my-conda-channel \
    --build-number=+1
```

For other publishing options:
+ To publish to an Amazon S3 channel, see [Publish packages to an S3 conda channel](publish-packages-s3-channel.md).
+ To automate builds using a Deadline Cloud package building queue, see [Automate package builds with Deadline Cloud](automate-package-builds.md).

# Test your package with a Blender render job
<a name="s3-channel-submit-job"></a>

After you build the Blender 4.5 package, you can test it with a render job. If you do not have a Blender scene, download the Blender 3.5 - Cozy Kitchen scene from the [Blender demo files](https://www.blender.org/download/demo-files) page. The Deadline Cloud samples repository contains a `blender_render` job bundle and a conda queue environment that you can use for both local and cloud testing.

## Testing locally
<a name="blender-test-locally"></a>

You can run the job template on your workstation using the [Open Job Description CLI](https://github.com/OpenJobDescription/openjd-cli#readme). Install the CLI with `pip`.

```
pip install openjd-cli
```

From the `job_bundles` directory in the samples repository, run the following command. Replace */path/to/scene.blend* with the path to your Blender scene file.

```
openjd run blender_render/template.yaml \
    --environment ../queue_environments/conda_queue_env_pyrattler.yaml \
    -p CondaPackages=blender=4.5 \
    -p CondaChannels=file://$HOME/my-conda-channel \
    -p BlenderSceneFile=/path/to/scene.blend \
    -p Frames=1
```

The `--environment` option applies the conda queue environment, which creates a conda virtual environment with the packages specified in `CondaPackages`. The `CondaChannels` parameter tells the queue environment where to find the packages. If you published to an Amazon S3 channel instead of a local channel, replace the `file://` path with your `s3://` channel URL.

## Testing on Deadline Cloud
<a name="blender-test-deadline-cloud"></a>

After you configure your production queue to use the Amazon S3 conda channel, you can submit the render job to Deadline Cloud. From the `job_bundles` directory in the samples repository, run the following command.

```
deadline bundle submit blender_render \
    -p CondaPackages=blender=4.5 \
    -p BlenderSceneFile=/path/to/scene.blend \
    -p Frames=1
```

Use the Deadline Cloud monitor to track the progress of the job. In the monitor, select the task for the job and choose **View logs**. Select the **Launch Conda** session action to verify that the package was found in the Amazon S3 channel.