craft_providers.base module

Base configuration module.

class craft_providers.base.Base[source]

Bases: abc.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.

compatibility_tag: str = 'base-v0'
abstract get_command_environment()[source]

Get command environment to use when executing commands.

Return type

Dict[str, Optional[str]]

Returns

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

abstract setup(*, executor, retry_wait=0.25, timeout=None)[source]

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) – Executor for target container.

  • retry_wait (float) – Duration to sleep() between status checks (if required).

  • timeout (Optional[float]) – Timeout in seconds.

Raises
Return type

None

abstract wait_until_ready(*, executor, retry_wait=0.25, timeout=None)[source]

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.

Parameters
  • executor (Executor) – Executor for target container.

  • retry_wait (float) – Duration to sleep() between status checks (if required).

  • timeout (Optional[float]) – Timeout in seconds.

Raises
Return type

None

abstract warmup(*, executor, retry_wait=0.25, timeout=None)[source]

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) – Executor for target container.

  • retry_wait (float) – Duration to sleep() between status checks (if required).

  • timeout (Optional[float]) – Timeout in seconds.

Raises
Return type

None