OpenFactory Deployment Strategies#

OpenFactory Assets are deployed on the OpenFactory cluster using one of the deployment strategy classes listed below. These classes inherit from the abstract base class openfactory.openfactory_deploy_strategy.OpenFactoryServiceDeploymentStrategy.

Currently, two deployment strategies are implemented:

class openfactory.openfactory_deploy_strategy.OpenFactoryServiceDeploymentStrategy[source]#

Bases: ABC

Abstract base class for OpenFactory service deployment strategies.

abstractmethod deploy(*, image, image_pull_policy='missing', user=None, name, env, labels=None, command=None, ports=None, networks=None, constraints=None, resources=None, open_files=None, mode=None, mounts=None)[source]#

Deploy a service using the specified parameters.

Return type:

None

Parameters:
  • image (str) – Docker image to deploy.

  • image_pull_policy (str) –

    Image pull behavior.

    • missing: Pull the image only if it is not available locally.

    • always: Always pull the image before deployment.

  • user (Optional[str]) – Runtime user in Docker format UID:GID.

  • name (str) – Name of the service or container.

  • env (List[str]) – Environment variables in KEY=VALUE format.

  • labels (Optional[Dict[str, str]]) – Metadata labels attached to the deployed container or service.

  • command (Optional[str]) – Command to override the default entrypoint.

  • ports (Optional[Dict[int, int]]) – Port mappings from host to container (host:container).

  • networks (Optional[List[str]]) – Networks to connect the service or container to.

  • constraints (Optional[List[str]]) – Constraints for placement (Swarm only).

  • resources (Optional[Dict[str, Any]]) – Resource limits and reservations.

  • open_files (Optional[int]) – Maximum number of open file descriptors (RLIMIT_NOFILE) available to the process inside the container. If not specified, the container runtime default is used.

  • mode (Optional[Dict[str, Any]]) – Service mode (Swarm only).

  • mounts (Optional[List[dict]]) – List of Docker mount specifications.

abstractmethod remove(service_name)[source]#

Remove a service.

Parameters:

service_name (str) – Service to be removed.

class openfactory.openfactory_deploy_strategy.LocalDockerDeploymentStrategy[source]#

Bases: OpenFactoryServiceDeploymentStrategy

Deployment strategy for local Docker containers (non-Swarm).

deploy(*, image, image_pull_policy='missing', user=None, name, env, labels=None, command=None, ports=None, networks=None, constraints=None, resources=None, open_files=None, mode=None, mounts=None)[source]#

Run a local Docker container.

See parent method for argument descriptions.

Return type:

None

Note

  • constraints and mode are ignored for local containers.

  • image_pull_policy="always" forces a Docker image pull before deployment.

  • When open_files is specified, a nofile ulimit is configured with identical soft and hard limits.

  • If open_files is not specified, the Docker Engine default file descriptor limit is used.

remove(service_name)[source]#

Remove a Docker container.

Parameters:

service_name (str) – Docker container to be removed.

Raises:
  • docker.errors.NotFound – If the container does not exist.

  • docker.errors.APIError – If removal fails due to a Docker API issue.

swarm_mount_to_container_mount(mount_dict)[source]#

Convert a Docker Swarm-style mount dictionary to a local Docker Mount object.

Return type:

Mount

Parameters:

mount_dict (dict) – Mount dictionary in Swarm format, as returned by openfactory.filelayer.nfs_backend.NFSBackend.get_mount_spec().

Returns:

docker.types.Mount – A Mount object suitable for use with docker.containers.run().

Note

  • Supports volume mounts only; bind mounts should be handled separately.

  • The returned Mount preserves the target path, source name, read-only flag, and driver configuration specified in the input dictionary.

  • NFS-specific options (e.g., nfsvers=4) are already included in the mount dictionary by get_mount_spec().

class openfactory.openfactory_deploy_strategy.SwarmDeploymentStrategy[source]#

Bases: OpenFactoryServiceDeploymentStrategy

Deployment strategy for Docker Swarm mode.

Uses the Docker Engine API directly to create services, allowing support for advanced container settings such as file descriptor limits (ulimits) that are not exposed by the high-level Docker SDK service API.

deploy(*, image, image_pull_policy='missing', user=None, name, env, labels=None, command=None, ports=None, networks=None, constraints=None, resources=None, open_files=None, mode=None, mounts=None)[source]#

Deploy a Docker service using Docker Swarm.

See parent method for argument descriptions.

Return type:

None

Note

  • image_pull_policy is currently ignored for Swarm deployments.

  • When open_files is specified, the service is deployed with a nofile ulimit using identical soft and hard limits.

  • If open_files is not specified, the Docker Engine default file descriptor limit is used.

remove(service_name)[source]#

Remove a Docker service from a Docker Swarm cluster.

Parameters:

service_name (str) – Docker swarm service to be removed.