runway.cfngin.hooks.awslambda.docker module
Docker logic for the awslambda hook.
- class runway.cfngin.hooks.awslambda.docker.DockerDependencyInstaller[source]
Bases:
object
Docker dependency installer.
- CACHE_DIR: ClassVar[str] = '/var/task/cache_dir'
Mount path where dependency managers can cache data.
- DEPENDENCY_DIR: ClassVar[str] = '/var/task/lambda'
Mount path were dependencies will be installed to within the Docker container. Other files can be moved to this directory to be included in the deployment package.
- PROJECT_DIR: ClassVar[str] = '/var/task/project'
Mount path where the project directory is available within the Docker container.
- __init__(project: Project[AwsLambdaHookArgs], *, client: Optional[DockerClient] = None, context: Optional[Union[CfnginContext, RunwayContext]] = None) None [source]
Instantiate class.
This is a low-level method that requires the user to implement error handling. It is recommended to use
from_project()
instead of instantiating this class directly.- Parameters
project – awslambda project.
client – Pre-configured
docker.client.DockerClient
.context – CFNgin or Runway context object.
- client: DockerClient
Docker client.
- ctx: Union[CfnginContext, RunwayContext]
Context object.
- options: DockerOptions
Hook arguments specific to Docker.
- property bind_mounts: List[docker.types.services.Mount]
Bind mounts that will be used by the container.
- property environment_variables: Dict[str, str]
Environment variables to pass to the Docker container.
This is a subset of the environment variables stored in the context object as some will cause issues if they are passed.
- property image: Union[docker.models.images.Image, str]
Docker image that will be used.
- Raises
ValueError – Insufficient data to determine the desired Docker image.
- __new__(**kwargs)
- build_image(docker_file: Path, *, name: Optional[str] = None, tag: Optional[str] = None) Image [source]
Build Docker image from Dockerfile.
This method is exposed as a low-level interface.
image
should be used in place for this for most cases.- Parameters
docker_file – Path to the Dockerfile to build. This path should be absolute, must exist, and must be a file.
name – Name of the Docker image. The name should not contain a tag. If not provided, a default value is use.
tag – Tag to apply to the image after it is built. If not provided, a default value of
latest
is used.
- Returns
Object representing the image that was built.
- log_docker_msg_bytes(stream: Iterator[bytes], *, level: int = 20) List[str] [source]
Log Docker output message from blocking generator that return bytes.
- Parameters
stream – Blocking generator that returns log messages as bytes.
level – Log level to use when logging messages.
- Returns
List of log messages.
- log_docker_msg_dict(stream: Iterator[Dict[str, Any]], *, level: int = 20) List[str] [source]
Log Docker output message from blocking generator that return dict.
- Parameters
stream – Blocking generator that returns log messages as a dict.
level – Log level to use when logging messages.
- Returns
list of log messages.
- install() None [source]
Install dependencies using Docker.
Commands are run as they are defined in the following cached properties:
- pull_image(name: str, *, force: bool = True) docker.models.images.Image [source]
Pull a Docker image from a repository if it does not exist locally.
This method is exposed as a low-level interface.
image
should be used in place for this for most cases.- Parameters
name – Name of the Docker image including tag.
force – Always pull the image even if it exists locally. This will ensure that the latest version is always used.
- Returns
Object representing the image found locally or pulled from a repository.
- run_command(command: str, *, level: int = 20) List[str] [source]
Execute equivalent of
docker container run
.- Parameters
command – Command to be run.
level – Log level to use when logging messages.
- Raises
DockerExecFailedError – Docker container returned a non-zero exit code.
- Returns
List of log messages.
- classmethod from_project(project: Project[AwsLambdaHookArgs]) Optional[_T] [source]
Instantiate class from a project.
High-level method that wraps instantiation in error handling.
- Parameters
project – Project being processed.
- Returns
Object to handle dependency installation with Docker if Docker is available and not disabled.
- Raises
DockerConnectionRefused – Docker is not install or is unreachable.