ecsjobs.jobs.docker_exec module

class ecsjobs.jobs.docker_exec.DockerExec(name, schedule, summary_regex=None, cron_expression=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

Class to run a command in an existing Docker container via exec. Captures combined STDOUT and STDERR to output and sets exitcode to the exit code of the command/process.

Parameters:
  • name (str) – unique name for this job
  • schedule (str) – the name of the schedule this job runs on
  • summary_regex (string or None) – 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.
  • container_name (str) – The name of the Docker container to run the exec in. Required. This can also be a container ID, but that’s much less useful in a scheduled job.
  • command (str or list) – The command to execute as either a String or a List of Strings, as used by docker.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 or list) – A dictionary or list of string environment variables to set. Passed through to docker.api.exec_api.ExecApiMixin.exec_create().
_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'}, '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
report_description()[source]

Return a one-line description of the Job for use in reports.

Return type:str
run()[source]

Run the command for the job. Either raise an exception or return True if the command exited 0, False if it exited non-zero.

Returns:True if command exited 0, False otherwise.