Image and Build

πŸ“˜

Note

While using ServiceFoundry 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

Image

Description

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

Schema

{
  "type": "string",
  "image_uri": "string",
  "docker_registry": "string",
  "command": null
}

Properties

NameTypeRequiredDescription
typestringtruenone
image_uristringtrueThe 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_registrystringfalseFQN of the container registry. You can the FQN of your desired container registry (or add one)
in the Integrations page
commandanyfalseOverride 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}}

Python Examples

from servicefoundry import (
    Service, Image
)

service = Service(
    ...
  	image=Image(
      image_uri="seldonio/mlserver:1.2.0",
      docker_registry="admin-truefoundry:production-euwe1-ecr",  # optional, FQN registry to pull the built image from
    )
)

Build

Description

Describes how we build our code into a Docker image.

Schema

{
  "type": "string",
  "docker_registry": "string",
  "build_source": {},
  "build_spec": {}
}

Properties

NameTypeRequiredDescription
typestringtruenone
docker_registrystringfalseFQN of the container registry. You can the FQN of your desired container registry (or add one)
in the Integrations pageIntegrations page
build_sourceobjecttrueSource code location.
build_specobjecttrueInstructions to build a container image out of the build source

Python Examples

from servicefoundry import (
    Service, Build, PythonBuild, LocalSource
)

service = Service(
    ...,
  	image=Build(
        docker_registry="admin-truefoundry:production-euwe1-ecr",  # optional, FQN registry to push the built image to
        build_source=LocalSource(
            project_root_path="./"
        ),
        build_spec=PythonBuild(
            python_version="3.9",
            build_context_path="./",
            requirements_path="requirements.txt",
            pip_packages=["requests", "numpy==1.20.0"],
            apt_packages=["ffmpeg", "curl", "wget"],
            command="uvicorn app:app --port 8000 --host 127.0.0.1", # or as a list ["python", "main.py"]
        ),
    )
)
from servicefoundry import (
    Service, Build, DockerFileBuild, LocalSource
)

service = Service(
    ...,
  	image=Build(
        docker_registry="admin-truefoundry:production-euwe1-ecr",  # optional, FQN registry to push the built image to
        build_source=LocalSource(
            project_root_path="./"
        ),
        build_spec=DockerFileBuild(
            dockerfile_path='./Dockerfile',
            build_context_path='./'
        ),
    ),
)
from servicefoundry import (
    Service, Image
)

service = Service(
    ...,
  	image=Image(
      image_uri="seldonio/mlserver:1.2.0",
      docker_registry="admin-truefoundry:production-euwe1-ecr",  # optional, FQN registry to pull the built image from
    ),
)
from servicefoundry import (
    Service, Build, GitSource, PythonBuild
)

service = Service(
    ...,
  	image=Build(
        docker_registry="admin-truefoundry:production-euwe1-ecr",  # optional, FQN registry to push the built image to
        build_source=GitSource(
            repo_url="https://github.com/myorg/myrepo",
            branch_name="main", # Optional, by default the default branch configured on the repo
            ref="547ea1423267902a6ff98517d4ae205d8f7c47f8", # Optional, by default latest commit on the branch
        ),
        build_spec=PythonBuild(
            python_version="3.9",
            build_context_path="./",
            requirements_path="requirements.txt",
            pip_packages=["requests", "numpy==1.20.0"],
            apt_packages=["ffmpeg", "curl", "wget"],
            command="uvicorn app:app --port 8000 --host 127.0.0.1", # or as a list ["python", "main.py"]
        ),
    ),    
)
from servicefoundry import (
    Service, Build, DockerFileBuild, GitSource
)

service = Service(
    ...,
  	image=Build(
        docker_registry="admin-truefoundry:production-euwe1-ecr",  # optional, FQN registry to push the built image to
        build_source=GitSource(
            repo_url="https://github.com/myorg/myrepo",
            branch_name="main", # Optional, by default the default branch configured on the repo
            ref="547ea1423267902a6ff98517d4ae205d8f7c47f8", # Optional, by default latest commit on the branch
        ),
        build_spec=DockerFileBuild(
            dockerfile_path='./Dockerfile',
            build_context_path='./'
        ),
    ),
)

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

{
  "type": "string",
  "python_version": "3.9",
  "build_context_path": "./",
  "requirements_path": "string",
  "pip_packages": [
    "string"
  ],
  "apt_packages": [
    "string"
  ],
  "command": null
}

Properties

NameTypeRequiredDescription
typestringtruenone
python_versionstringtruePython version to run your application.
build_context_pathstringtrueBuild path relative to project root path.
requirements_pathstringfalsePath to requirements.txt relative to
Path to build context
pip_packages[string]falseDefine pip package requirements.
apt_packages[string]falseDefine Debian packages to install via apt.
E.g. `["ffmpeg", "libsm6", "libxext6"]
commandanytrueCommand 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}}

Python Examples

from servicefoundry import (
    Service, Build, PythonBuild, LocalSource
)

service = Service(
    ...,
  	image=Build(
        docker_registry="admin-truefoundry:production-euwe1-ecr",  # optional, FQN registry to push the built image to
        build_source=LocalSource(
            project_root_path="./"
        ),
        build_spec=PythonBuild(
            python_version="3.9",
            build_context_path="./",
            requirements_path="requirements.txt",
            pip_packages=["requests", "numpy==1.20.0"],
            apt_packages=["ffmpeg", "curl", "wget"],
            command="uvicorn app:app --port 8000 --host 127.0.0.1", # or as a list ["python", "main.py"]
        ),
    )
)
from servicefoundry import (
    Service, Build, GitSource, PythonBuild
)

service = Service(
    ...,
  	image=Build(
        docker_registry="admin-truefoundry:production-euwe1-ecr",  # optional, FQN registry to push the built image to
        build_source=GitSource(
            repo_url="https://github.com/myorg/myrepo",
            branch_name="main", # Optional, by default the default branch configured on the repo
            ref="547ea1423267902a6ff98517d4ae205d8f7c47f8", # Optional, by default latest commit on the branch
        ),
        build_spec=PythonBuild(
            python_version="3.9",
            build_context_path="./",
            requirements_path="requirements.txt",
            pip_packages=["requests", "numpy==1.20.0"],
            apt_packages=["ffmpeg", "curl", "wget"],
            command="uvicorn app:app --port 8000 --host 127.0.0.1", # or as a list ["python", "main.py"]
        ),
    ),    
)

DockerFileBuild

Description

Describes that we are using a dockerfile to build our image

Schema

{
  "type": "string",
  "dockerfile_path": "./Dockerfile",
  "build_context_path": "./",
  "command": null,
  "build_args": {},
}

Properties

NameTypeRequiredDescription
typestringtruenone
dockerfile_pathstringtrueThe file path of the Dockerfile relative to project root path.
build_context_pathstringtrueBuild context path for the Dockerfile relative to project root path.
commandanyfalseOverride 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_argsdictfalseBuild arguments to pass to --build-arg option in docker build.

Python Examples

from servicefoundry import (
    Service, Build, DockerFileBuild, LocalSource
)

service = Service(
    ...,
  	image=Build(
        docker_registry="admin-truefoundry:production-euwe1-ecr",  # optional, FQN registry to push the built image to
        build_source=LocalSource(
            project_root_path="./"
        ),
        build_spec=DockerFileBuild(
            dockerfile_path='./Dockerfile',
            build_context_path='./',
          	build_args={
            	"param": "value",
              "param1": "value1",
            },
        ),
    ),
)
from servicefoundry import (
    Service, Build, DockerFileBuild, GitSource
)

service = Service(
    ...,
  	image=Build(
        docker_registry="admin-truefoundry:production-euwe1-ecr",  # optional, FQN registry to push the built image to
        build_source=GitSource(
            repo_url="https://github.com/myorg/myrepo",
            branch_name="main", # Optional, by default the default branch configured on the repo
            ref="547ea1423267902a6ff98517d4ae205d8f7c47f8", # Optional, by default latest commit on the branch
        ),
        build_spec=DockerFileBuild(
            dockerfile_path='./Dockerfile',
            build_context_path='./',
            build_args={
            	"param": "value",
              "param1": "value1",
            },
        ),
    ),
)

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

{
  "type": "string",
  "project_root_path": "./",
  "local_build": false
}

Properties

NameTypeRequiredDescription
typestringtruenone
project_root_pathstringtrueLocal project root path.
local_buildbooleantruerun docker build locally

Python Examples

from servicefoundry import (
    Service, Build, PythonBuild, LocalSource
)

service = Service(
    ...,
  	image=Build(
        docker_registry="admin-truefoundry:production-euwe1-ecr",  # optional, FQN registry to push the built image to
        build_source=LocalSource(
            project_root_path="./"
        ),
        build_spec=PythonBuild(
            python_version="3.9",
            build_context_path="./",
            requirements_path="requirements.txt",
            pip_packages=["requests", "numpy==1.20.0"],
            apt_packages=["ffmpeg", "curl", "wget"],
            command="uvicorn app:app --port 8000 --host 127.0.0.1", # or as a list ["python", "main.py"]
        ),
    )
)
from servicefoundry import (
    Service, Build, DockerFileBuild, LocalSource
)

service = Service(
    ...,
  	image=Build(
        docker_registry="admin-truefoundry:production-euwe1-ecr",  # optional, FQN registry to push the built image to
        build_source=LocalSource(
            project_root_path="./"
        ),
        build_spec=DockerFileBuild(
            dockerfile_path='./Dockerfile',
            build_context_path='./'
        ),
    ),
)

GitSource

Description

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

Schema

{
  "type": "string",
  "repo_url": "string",
  "ref": "string",
  "branch_name": "string"
}

Properties

NameTypeRequiredDescription
typestringtruenone
repo_urlstringtrueThe repository URL.
refstringtrueThe commit SHA.
branch_namestringfalseSelecting branch will select latest commit SHA of the branch.

Python Examples

from servicefoundry import (
    Service, Build, GitSource, PythonBuild
)

service = Service(
    ...,
  	image=Build(
        docker_registry="admin-truefoundry:production-euwe1-ecr",  # optional, FQN registry to push the built image to
        build_source=GitSource(
            repo_url="https://github.com/myorg/myrepo",
            branch_name="main", # Optional, by default the default branch configured on the repo
            ref="547ea1423267902a6ff98517d4ae205d8f7c47f8", # Optional, by default latest commit on the branch
        ),
        build_spec=PythonBuild(
            python_version="3.9",
            build_context_path="./",
            requirements_path="requirements.txt",
            pip_packages=["requests", "numpy==1.20.0"],
            apt_packages=["ffmpeg", "curl", "wget"],
            command="uvicorn app:app --port 8000 --host 127.0.0.1", # or as a list ["python", "main.py"]
        ),
    ),    
)
from servicefoundry import (
    Service, Build, DockerFileBuild, GitSource
)

service = Service(
    ...,
  	image=Build(
        docker_registry="admin-truefoundry:production-euwe1-ecr",  # optional, FQN registry to push the built image to
        build_source=GitSource(
            repo_url="https://github.com/myorg/myrepo",
            branch_name="main", # Optional, by default the default branch configured on the repo
            ref="547ea1423267902a6ff98517d4ae205d8f7c47f8", # Optional, by default latest commit on the branch
        ),
        build_spec=DockerFileBuild(
            dockerfile_path='./Dockerfile',
            build_context_path='./'
        ),
    ),
)

RemoteSource

Description

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

Schema

{
  "type": "string",
  "remote_uri": "string"
}

Properties

NameTypeRequiredDescription
typestringtruenone
remote_uristringtrueRemote repository URI

Python Examples

from servicefoundry import (
    Service, Build, RemoteSource, PythonBuild
)

service = Service(
    ...,
  	image=Build(
        docker_registry="admin-truefoundry:production-euwe1-ecr",  # optional, FQN registry to push the built image to
        build_source=RemoteSource(
  					remote_uri="https://example.code/path/to/my/code.zip"
				),
        build_spec=PythonBuild(
            python_version="3.9",
            build_context_path="./",
            requirements_path="requirements.txt",
            pip_packages=["requests", "numpy==1.20.0"],
            apt_packages=["ffmpeg", "curl", "wget"],
            command="uvicorn app:app --port 8000 --host 127.0.0.1", # or as a list ["python", "main.py"]
        ),
    ),    
)