> ## Documentation Index
> Fetch the complete documentation index at: https://www.truefoundry.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Image And Build

> API reference for Image and Build configuration schemas used to specify Docker images and build instructions.

<Note>
  ### Note

  While using TrueFoundry python SDK `type` is not a required field in any of the imported classes\
  For image you can either give link to a pre-existing image via `Image` module, or give instructions on how to build the image via the `Build` class
</Note>

## Image

### Description

Describes that we are using a pre-built image stored in a Docker Image registry

### Schema

<CodeGroup>
  ```json JSON lines theme={"dark"}
  {
    "type": "string",
    "image_uri": "string",
    "docker_registry": "string",
    "command": null
  }
  ```
</CodeGroup>

### Properties

| Name             | Type   | Required | Description                                                                                                                                                                                                              |
| ---------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| type             | string | true     | +value=image                                                                                                                                                                                                             |
| image\_uri       | string | true     | The image URI. Specify the name of the image and the tag. If the image is in Dockerhub, you can skip registry-url (for e.g. `tensorflow/tensorflow`). You can use an image from a private registry using Advanced fields |
| docker\_registry | string | false    | FQN of the container registry. You can the FQN of your desired container registry (or add one) in the Integrations page[Integrations](https://app.truefoundry.tech/integrations?tab=docker-registry) page                |
| command          | any    | false    | Override the command to run when container starts. When deploying a Job, the command can be templatized by defining `params` and referencing them in command E.g. `python main.py --learning_rate {{learning_rate}}`     |

## Build

### Description

Describes how we build our code into a Docker image.

### Schema

<CodeGroup>
  ```json JSON lines theme={"dark"}
  {
    "type": "string",
    "docker_registry": "string",
    "build_source": {},
    "build_spec": {}
  }
  ```
</CodeGroup>

### Properties

| Name             | Type   | Required | Description                                                                                                                                                                                               |
| ---------------- | ------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| type             | string | true     | +value=build                                                                                                                                                                                              |
| docker\_registry | string | false    | FQN of the container registry. You can the FQN of your desired container registry (or add one) in the Integrations page[Integrations](https://app.truefoundry.tech/integrations?tab=docker-registry) page |
| build\_source    | object | true     | Source code location.                                                                                                                                                                                     |
| build\_spec      | object | true     | Instructions to build a container image out of the build source                                                                                                                                           |

## Build Spec

The modules below help define the build specification.

## PythonBuild

### Description

Describes that we are using python to build a container image with a specific python version and pip packages installed.

### Schema

<CodeGroup>
  ```json JSON lines theme={"dark"}
  {
    "type": "string",
    "python_version": "3.9",
    "build_context_path": "./",
    "requirements_path": "string",
    "pip_packages": [
      "string"
    ],
    "apt_packages": [
      "string"
    ],
    "command": null,
    "cuda_version": "string"
  }
  ```
</CodeGroup>

### Properties

| Name                 | Type      | Required | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| -------------------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| type                 | string    | true     | +value=tfy-python-buildpack                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| python\_version      | string    | true     | Python version to run your application. Should be one of the tags listed on[Official Python Docker Page](https://hub.docker.com/_/python)                                                                                                                                                                                                                                                                                                                                                                                      |
| build\_context\_path | string    | true     | Build path relative to project root path.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| requirements\_path   | string    | false    | Path to `requirements.txt` relative to `Path to build context`                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| pip\_packages        | \[string] | false    | Define pip package requirements. In Python/YAML E.g. \["fastapi>=0.90,\<1.0", "uvicorn"]                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| apt\_packages        | \[string] | false    | Debian packages to install via `apt get`. In Python/YAML E.g. \["git", "ffmpeg", "htop"]                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| command              | any       | true     | Command to run when the container starts. Command will be set as the Entrypoint of the generated image. When deploying a Job, the command can be templatized by defining `params` and referencing them in command E.g. `python main.py --learning_rate {{learning_rate}}`                                                                                                                                                                                                                                                      |
| cuda\_version        | string    | false    | Version of CUDA Toolkit and CUDNN to install in the image These combinations are based off of publically available docker images on docker hub You can also specify a valid tag of the form \{cuda\_version\_number}-cudnn\{cudnn\_version\_number}-\{runtime/devel}-ubuntu\{ubuntu\_version} Refer [https://hub.docker.com/r/nvidia/cuda/tags](https://hub.docker.com/r/nvidia/cuda/tags) for valid set of values Note: We use deadsnakes ubuntu ppa to add Python that currently supports only Ubuntu 18.04, 20.04 and 22.04 |

## DockerFileBuild

### Description

Describes that we are using a dockerfile to build our image

### Schema

<CodeGroup>
  ```json JSON lines theme={"dark"}
  {
    "type": "string",
    "dockerfile_path": "./Dockerfile",
    "build_context_path": "./",
    "command": null,
    "build_args": {
      "property1": "string",
      "property2": "string"
    }
  }
  ```
</CodeGroup>

### Properties

| Name                 | Type   | Required | Description                                                                                                                                                                                                             |
| -------------------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| type                 | string | true     | +value=dockerfile                                                                                                                                                                                                       |
| dockerfile\_path     | string | true     | The file path of the Dockerfile relative to project root path.                                                                                                                                                          |
| build\_context\_path | string | true     | Build context path for the Dockerfile relative to project root path.                                                                                                                                                    |
| command              | any    | false    | Override the command to run when the container starts When deploying a Job, the command can be templatized by defining `params` and referencing them in command E.g. `python main.py --learning_rate {{learning_rate}}` |
| build\_args          | object | false    | Build arguments to pass to`docker build`.                                                                                                                                                                               |

## Build Source

The modules below help define the build specification.

## LocalSource

### Description

Describes that we are using code stored in a local developement environment to build our image

### Schema

<CodeGroup>
  ```json JSON lines theme={"dark"}
  {
    "type": "string",
    "project_root_path": "./",
    "local_build": true
  }
  ```
</CodeGroup>

### Properties

| Name                | Type    | Required | Description              |
| ------------------- | ------- | -------- | ------------------------ |
| type                | string  | true     | +value=local             |
| project\_root\_path | string  | true     | Local project root path. |
| local\_build        | boolean | true     | run docker build locally |

## GitSource

### Description

Describes that we are using code stored in a git repository to build our image

### Schema

<CodeGroup>
  ```json JSON lines theme={"dark"}
  {
    "type": "string",
    "repo_url": "string",
    "ref": "string",
    "branch_name": "string"
  }
  ```
</CodeGroup>

### Properties

| Name         | Type   | Required | Description                                                   |
| ------------ | ------ | -------- | ------------------------------------------------------------- |
| type         | string | true     | +value=git                                                    |
| repo\_url    | string | true     | The repository URL.                                           |
| ref          | string | true     | The commit SHA.                                               |
| branch\_name | string | false    | Selecting branch will select latest commit SHA of the branch. |

## RemoteSource

### Description

Describes that we are using code stored in a remote respository to build our image

### Schema

<CodeGroup>
  ```json JSON lines theme={"dark"}
  {
    "type": "string",
    "remote_uri": "string"
  }
  ```
</CodeGroup>

### Properties

| Name        | Type   | Required | Description           |
| ----------- | ------ | -------- | --------------------- |
| type        | string | true     | +value=remote         |
| remote\_uri | string | true     | Remote repository URI |
