Bases

Abstract Base

class craft_providers.Base(*, alias: Enum, compatibility_tag: str | None = None, environment: Dict[str, str | None] | None = None, hostname: str = 'craft-instance', snaps: List | None = None, packages: List[str] | None = None, use_default_packages: bool = True, cache_path: Path | None = None)

Bases: ABC

Interface for providers to configure instantiated environments.

Defines how to setup/configure an environment that has been instantiated by a provider and prepare it for some operation, e.g. execute build. It must account for:

  1. the OS type and version.

(2) the provided image that was launched, e.g. bootstrapping a minimal image versus a more fully featured one.

(3) any dependencies that are required for the operation to complete, e.g. installed applications, networking configuration, etc. This includes any environment configuration that the application will assume is available.

Variables:

compatibility_tag – Tag/Version for variant of build configuration and setup. Any change to this version would indicate that prior [versioned] instances are incompatible and must be cleaned. As such, any new value should be unique to old values (e.g. incrementing). It is suggested to extend this tag, not overwrite it, e.g.: compatibility_tag = f”{appname}-{Base.compatibility_tag}.{apprevision}” to ensure base compatibility levels are maintained.

Parameters:

cache_path – (Optional) Path to the shared cache directory. If this is provided, shared cache directories will be mounted as appropriate. Some directories depend on the base implementation.

static default_command_environment() Dict[str, str | None]

Provide default command environment dictionary.

The minimum environment for the image to be configured and function properly. This contains the default environment for most Linux systems in /etc/environment.

Returns:

Dictionary of environment key/values.

get_command_environment() Dict[str, str | None]

Get command environment to use when executing commands.

Returns:

Dictionary of environment, allowing None as a value to indicate that a value should be unset.

final setup(*, executor: Executor, timeout: float | None = 3600, mount_cache: bool = True) None

Prepare base instance for use by the application.

Wait for environment to become ready and configure it. At completion of setup, the executor environment should have networking up and have all of the installed dependencies required for subsequent use by the application.

Setup should not be called more than once in a given instance to refresh/update the environment, use warmup for that.

If timeout is specified, abort operation if time has been exceeded.

Parameters:
  • executor – Executor for target container.

  • timeout – Timeout in seconds.

  • mount_cache – If true, mount the cache directories.

Raises:
  • BaseCompatibilityError – if instance is incompatible.

  • BaseConfigurationError – on other unexpected error.

wait_until_ready(executor: Executor) None

Wait until base instance is ready.

Ensure minimum-required boot services are running. This would be used when starting an environment’s container/VM after already [recently] running setup(), e.g. rebooting the instance. Allows the environment to be used without the cost incurred by re-executing the steps unnecessarily.

If timeout is specified, abort operation if time has been exceeded.

Guarantees provided by this wait:

  • networking available (IP & DNS resolution)

  • system services are started and ready

Raises:

ProviderError – on timeout or unexpected error.

final warmup(*, executor: Executor, timeout: float | None = 3600) None

Prepare a previously created and setup instance for use by the application.

Ensure the instance is still valid and wait for environment to become ready.

If timeout is specified, abort operation if time has been exceeded.

Parameters:
  • executor – Executor for target container.

  • timeout – Timeout in seconds.

Raises:
  • BaseCompatibilityError – if instance is incompatible.

  • BaseConfigurationError – on other unexpected error.

Buildd Base

class craft_providers.bases.BuilddBase(*, alias: BuilddBaseAlias, compatibility_tag: str | None = None, environment: Dict[str, str | None] | None = None, hostname: str = 'craft-buildd-instance', snaps: List[Snap] | None = None, packages: List[str] | None = None, use_default_packages: bool = True, cache_path: Path | None = None)

Bases: Base

Support for Ubuntu minimal buildd images.

Variables:
  • compatibility_tag – Tag/Version for variant of build configuration and setup. Any change to this version would indicate that prior [versioned] instances are incompatible and must be cleaned. As such, any new value should be unique to old values (e.g. incrementing). It is suggested to extend this tag, not overwrite it, e.g.: compatibility_tag = f”{appname}-{BuildBase.compatibility_tag}.{apprevision}” to ensure base compatibility levels are maintained.

  • instance_config_path – Path to persistent environment configuration used for compatibility checks (or other data). Set to /etc/craft-instance.conf, but may be overridden for application-specific reasons.

  • instance_config_class – Class defining instance configuration. May be overridden with an application-specific subclass of InstanceConfiguration to enable application-specific extensions.

Parameters:
  • alias – Base alias / version.

  • environment – Environment to set in /etc/environment.

  • hostname – Hostname to configure.

  • snaps – Optional list of snaps to install on the base image.

  • packages – Optional list of system packages to install on the base image.

  • use_default_packages – Optional bool to enable/disable default packages.

  • cache_path – Optional path to the shared cache directory. If this is provided, shared cache directories will be mounted as appropriate.