ecsjobs.jobs.ecs_docker_exec module¶
-
class
ecsjobs.jobs.ecs_docker_exec.
EcsDockerExec
(name, schedule, summary_regex=None, cron_expression=None, task_definition_family=None, container_name=None, command=None, tty=False, stdout=True, stderr=True, privileged=False, user='root', environment=None)[source]¶ Bases:
ecsjobs.jobs.base.Job
,ecsjobs.jobs.docker_exec_mixin.DockerExecMixin
Subclass of
DockerExec
that runs theexec
against a Docker container that is part of an ECS Task, using the ECS Agent Introspection metadata to identify the container toexec
against.Note that the functionality of this class depends on the Docker container labels set by the Amazon ECS Container Agent, specifically the
com.amazonaws.ecs.task-definition-family
andcom.amazonaws.ecs.container-name
labels as set in version 1.16.0Parameters: - name (str) – unique name for this job
- schedule (str) – the name of the schedule this job runs on
- summary_regex (
string
orNone
) – A regular expression to use for extracting a string from the job output for use in the summary table. If there is more than one match, the last one will be used. - cron_expression (str) – A cron-like expression parsable by cronex specifying when the job should run. This has the effect of causing runs to skip this job unless the expression matches. It’s recommended not to use any minute specifiers and not to use any hour specifiers if the total runtime of all jobs is more than an hour.
- task_definition_family (str) – The ECS Task Definition “family” to use to find the container to execute in. Required.
- container_name (str) – The name of the Docker container (within the specified Task Definition Family) to run the exec in. Required. If more than one running container is found with a matching family and container name, the first match will be used.
- command (
str
orlist
) – The command to execute as either a String or a List of Strings, as used bydocker.api.exec_api.ExecApiMixin.exec_create()
. - tty (bool) – Whether or not to allocate a TTY when reading output from
the command; passed through to
docker.api.exec_api.ExecApiMixin.exec_start()
. - stdout (bool) – Whether or not to attach to/capture STDOUT. Passed
through to
docker.api.exec_api.ExecApiMixin.exec_create()
. - stderr (bool) – Whether or not to attach to/capture STDERR. Passed
through to
docker.api.exec_api.ExecApiMixin.exec_create()
. - privileged (bool) – Whether or not to run the command as privileged.
Passed through to
docker.api.exec_api.ExecApiMixin.exec_create()
. - user (str) – The username to run the command as. Default is “root”.
- environment (
dict
orlist
) – A dictionary or list of string environment variables to set. Passed through todocker.api.exec_api.ExecApiMixin.exec_create()
.
-
_find_container
()[source]¶ Using
self._family
andself._task_container_name
, find the name of the first currently-running Docker container for that task.Returns: name of first matching running Docker container Return type: str
-
_schema_dict
= {'properties': {'command': {'oneOf': [{'type': 'string'}, {'type': 'array', 'items': [{'type': 'string'}]}]}, 'container_name': {'type': 'string'}, 'environment': {'oneOf': [{'type': 'object'}, {'type': 'array'}]}, 'privileged': {'type': 'boolean'}, 'stderr': {'type': 'boolean'}, 'stdout': {'type': 'boolean'}, 'task_definition_family': {'type': 'string'}, 'tty': {'type': 'boolean'}, 'user': {'type': 'string'}}, 'required': ['container_name', 'command'], 'type': 'object'}¶ Dictionary describing the configuration file schema, to be validated with jsonschema.
-
error_repr
¶ Return a detailed representation of the job state for use in error reporting.
Returns: detailed representation of job in case of error Return type: str