uber-compose 3.0.0a24__tar.gz → 3.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {uber_compose-3.0.0a24/uber_compose.egg-info → uber_compose-3.1.0}/PKG-INFO +4 -1
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/README.md +1 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/docs/CLI_USAGE.md +7 -1
- uber_compose-3.1.0/docs/EXEC_STRATEGIES.md +112 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/docs/PARALLELISM.md +33 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/docs/README.md +1 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/docs/UBER_COMPOSE_VEDRO_CONFIG.md +3 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/requirements.txt +2 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/__init__.py +11 -1
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/core/constants.py +37 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/core/docker_compose.py +15 -2
- uber_compose-3.1.0/uber_compose/core/docker_compose_shell/exec_strategies.py +245 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/core/docker_compose_shell/interface.py +49 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/core/docker_compose_shell/types.py +2 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/core/system_docker_compose.py +14 -2
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/core/utils/state_waiting.py +21 -3
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/helpers/exec_result.py +4 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/helpers/jobs_result.py +2 -1
- uber_compose-3.1.0/uber_compose/helpers/live_env.py +93 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/output/console.py +9 -4
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/uber_compose.py +55 -20
- uber_compose-3.1.0/uber_compose/utils/search_docker_compose_files.py +25 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/vedro_plugin/__init__.py +1 -3
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/vedro_plugin/base_structures/common_json_cli.py +14 -2
- uber_compose-3.1.0/uber_compose/version +1 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0/uber_compose.egg-info}/PKG-INFO +4 -1
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose.egg-info/SOURCES.txt +3 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose.egg-info/requires.txt +2 -0
- uber_compose-3.0.0a24/uber_compose/utils/search_docker_compose_files.py +0 -17
- uber_compose-3.0.0a24/uber_compose/version +0 -1
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/LICENSE +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/MANIFEST.in +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/docs/E2E_CONTAINER_SETUP.md +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/docs/ENV_LOCKS_FEATURE_REQUEST.md +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/docs/HOOKS.md +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/docs/LLM_RULES.md +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/docs/PLAN_CONSISTENCY.md +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/docs/RELEASE_TAGS.md +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/docs/X_MIGRATION.md +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/docs/common.puml +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/setup.cfg +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/setup.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/core/__init__.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/core/docker_compose_shell/__init__.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/core/sequence_run_types.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/core/utils/__init__.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/core/utils/compose_files.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/core/utils/compose_instance_cfg.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/core/utils/env_files.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/core/utils/process_command_output.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/core/utils/shell_process.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/env_description/__init__.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/env_description/env_tools.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/env_description/env_types.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/errors/__init__.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/errors/migrations.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/errors/mounted_files.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/errors/up.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/helpers/__init__.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/helpers/broken_services.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/helpers/bytes_pickle.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/helpers/countdown_counter.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/helpers/current_env.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/helpers/env_id.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/helpers/exec_record.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/helpers/health_policy.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/helpers/hooks.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/helpers/labels.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/helpers/parameterization.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/helpers/singleton.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/helpers/state_keeper.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/helpers/workers_per_env.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/output/__init__.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/output/styles.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/parallel_plugin/__init__.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/parallel_plugin/details.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/parallel_plugin/grouper.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/parallel_plugin/grouping.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/parallel_plugin/planner.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/parallel_plugin/plugin.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/parallel_plugin/runner.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/parallel_plugin/types.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/parallel_plugin/worker_api.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/parallel_plugin/worker_filter.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/utils/__init__.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/utils/docker_compose_files_path.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/utils/docker_compose_service_deps.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/utils/services_construction.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/vedro_plugin/base_structures/__init__.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/vedro_plugin/helpers/__init__.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/vedro_plugin/helpers/scenario_ordering.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/vedro_plugin/helpers/scenario_tag_processing.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/vedro_plugin/helpers/test_env_vars_setter.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/vedro_plugin/plugin.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose/version.py +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose.egg-info/dependency_links.txt +0 -0
- {uber_compose-3.0.0a24 → uber_compose-3.1.0}/uber_compose.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: uber-compose
|
|
3
|
-
Version: 3.0
|
|
3
|
+
Version: 3.1.0
|
|
4
4
|
Summary: docker compose testing env orchestrator
|
|
5
5
|
Home-page: https://github.com/ko10ok/uber-compose
|
|
6
6
|
Author: Yuriy Sagitov
|
|
@@ -16,6 +16,8 @@ Requires-Python: >=3.10.0
|
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
17
|
License-File: LICENSE
|
|
18
18
|
Requires-Dist: vedro<2.0,>=1.15
|
|
19
|
+
Requires-Dist: cabina<2.0,>=1.1.2
|
|
20
|
+
Requires-Dist: niltype<2.0,>=1.0.2
|
|
19
21
|
Requires-Dist: PyYAML<6.1,>=6.0.1
|
|
20
22
|
Requires-Dist: rtry<2.0,>=1.4.0
|
|
21
23
|
Requires-Dist: rich<16.0,>=11.0
|
|
@@ -235,6 +237,7 @@ This is particularly useful when:
|
|
|
235
237
|
|
|
236
238
|
- **[E2E Test Setup](docs/E2E_CONTAINER_SETUP.md)** - Configure test container for E2E testing
|
|
237
239
|
- **[CLI Usage Guide](docs/CLI_USAGE.md)** - Guide for using CommonJsonCli with JSON log parsing
|
|
240
|
+
- **[Alternative Exec Strategies](docs/EXEC_STRATEGIES.md)** - Built-in exec alternatives and custom strategies
|
|
238
241
|
- **[X-Migration](docs/X_MIGRATION.md)** - Extended service initialization and migration commands
|
|
239
242
|
- **[Lifecycle Hooks](docs/HOOKS.md)** - Register callbacks that run after the environment is up
|
|
240
243
|
- **[Parallel Runs by Use Case](docs/PARALLELISM.md)** - When to pass `--uc-mt`, which `ComposeConfig` to use, workers per env, env rotation and per-service env access
|
|
@@ -202,6 +202,7 @@ This is particularly useful when:
|
|
|
202
202
|
|
|
203
203
|
- **[E2E Test Setup](docs/E2E_CONTAINER_SETUP.md)** - Configure test container for E2E testing
|
|
204
204
|
- **[CLI Usage Guide](docs/CLI_USAGE.md)** - Guide for using CommonJsonCli with JSON log parsing
|
|
205
|
+
- **[Alternative Exec Strategies](docs/EXEC_STRATEGIES.md)** - Built-in exec alternatives and custom strategies
|
|
205
206
|
- **[X-Migration](docs/X_MIGRATION.md)** - Extended service initialization and migration commands
|
|
206
207
|
- **[Lifecycle Hooks](docs/HOOKS.md)** - Register callbacks that run after the environment is up
|
|
207
208
|
- **[Parallel Runs by Use Case](docs/PARALLELISM.md)** - When to pass `--uc-mt`, which `ComposeConfig` to use, workers per env, env rotation and per-service env access
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
- [CommandResult](#commandresult)
|
|
10
10
|
- [JsonParser Configuration](#jsonparser-configuration)
|
|
11
11
|
- [ExecLifeCyclePolicy](#execlifecyclepolicy)
|
|
12
|
+
- [Exec Strategies](#exec-strategies)
|
|
12
13
|
- [Timeouts Redefinition](#timeouts-redefinition)
|
|
13
14
|
|
|
14
15
|
---
|
|
@@ -216,10 +217,11 @@ cli = CommonJsonCli(parse_json_logs=parser.parse_output_to_json)
|
|
|
216
217
|
- **`stderr`**: `list[str | dict]` - Error logs (based on log level)
|
|
217
218
|
- **`cmd`**: `str` - Executed command
|
|
218
219
|
- **`env`**: `dict[str, str]` - Environment variables used
|
|
220
|
+
- **`exit_code`**: `int | None` - Application exit code; `None` means the process did not finish
|
|
219
221
|
|
|
220
222
|
### Methods
|
|
221
223
|
|
|
222
|
-
- **`has_no_errors()`**: Returns `True` if `stderr` is empty
|
|
224
|
+
- **`has_no_errors()`**: Returns `True` only if `stderr` is empty and `exit_code` is `0`
|
|
223
225
|
|
|
224
226
|
### Example
|
|
225
227
|
|
|
@@ -373,6 +375,10 @@ policy = ExecLifeCyclePolicy(
|
|
|
373
375
|
)
|
|
374
376
|
```
|
|
375
377
|
|
|
378
|
+
## Exec Strategies
|
|
379
|
+
|
|
380
|
+
See [Alternative Exec Strategies](EXEC_STRATEGIES.md).
|
|
381
|
+
|
|
376
382
|
## Timeouts Redefinition
|
|
377
383
|
|
|
378
384
|
By default `CommonJsonCli` uses the following timeouts for command execution:
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Alternative Exec Strategies
|
|
2
|
+
|
|
3
|
+
Pass a strategy class through the `exec` parameter:
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
from uber_compose import PidofExecStrategy, StatusFileExecStrategy
|
|
7
|
+
|
|
8
|
+
await cli.exec(command='my-app', exec=StatusFileExecStrategy) # default
|
|
9
|
+
await cli.exec(command='my-app', exec=PidofExecStrategy) # legacy pidof checks
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
`StatusFileExecStrategy` returns the application exit code.
|
|
13
|
+
`PidofExecStrategy` returns `exit_code=None` because the legacy path does not
|
|
14
|
+
collect it. A nonzero exit code is a normal result, not an exception.
|
|
15
|
+
|
|
16
|
+
## Writing a Strategy
|
|
17
|
+
|
|
18
|
+
A strategy is any class with `async execute(context)` returning `ExecResult`
|
|
19
|
+
or `ExecTimeout`. Subclassing `ExecStrategy` is optional.
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from uber_compose import ExecContext, ExecStrategy
|
|
23
|
+
from uber_compose.helpers.exec_result import ExecResult, ExecTimeout
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class MyExecStrategy(ExecStrategy):
|
|
27
|
+
async def execute(self, context: ExecContext) -> ExecResult | ExecTimeout:
|
|
28
|
+
...
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`ExecContext` provides `shell`, `container` (resolved compose service name),
|
|
32
|
+
`command`, `extra_env`, `wait`, `timeout`, `life_cycle_policy`, `env`, `root`.
|
|
33
|
+
|
|
34
|
+
- `wait=ProcessExit()` — wait for completion and return the exit code.
|
|
35
|
+
- `wait=None` — return immediately with `exit_code=None`.
|
|
36
|
+
- `wait=<callable>` — call it; return `ExecTimeout` if it reports unfinished.
|
|
37
|
+
- `exit_code=None` means the process did not finish. There is no separate flag.
|
|
38
|
+
- Timeout budget is `timeout.attempts * timeout.delay_s`.
|
|
39
|
+
|
|
40
|
+
## Docker Engine API Example
|
|
41
|
+
|
|
42
|
+
Uses `docker-py` (`pip install docker`) and never calls the Docker CLI.
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import asyncio
|
|
46
|
+
|
|
47
|
+
from docker import DockerClient
|
|
48
|
+
|
|
49
|
+
from uber_compose import ExecContext
|
|
50
|
+
from uber_compose import ExecStrategy
|
|
51
|
+
from uber_compose import ProcessExit
|
|
52
|
+
from uber_compose.helpers.exec_result import ExecResult
|
|
53
|
+
from uber_compose.helpers.exec_result import ExecTimeout
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class DockerApiExecStrategy(ExecStrategy):
|
|
57
|
+
def __init__(self, base_url: str = 'unix:///var/run/docker.sock'):
|
|
58
|
+
self._client = DockerClient(base_url=base_url)
|
|
59
|
+
|
|
60
|
+
async def execute(self, context: ExecContext) -> ExecResult | ExecTimeout:
|
|
61
|
+
container = await asyncio.to_thread(self._find_container, context.container)
|
|
62
|
+
exec_id = await asyncio.to_thread(self._create_exec, container, context)
|
|
63
|
+
|
|
64
|
+
if context.wait is None:
|
|
65
|
+
await asyncio.to_thread(self._client.api.exec_start, exec_id, detach=True)
|
|
66
|
+
return ExecResult(stdout=b'', cmd=context.command, exit_code=None)
|
|
67
|
+
|
|
68
|
+
if context.wait != ProcessExit():
|
|
69
|
+
raise NotImplementedError('Supports only ProcessExit and wait=None')
|
|
70
|
+
|
|
71
|
+
try:
|
|
72
|
+
stdout = await asyncio.wait_for(
|
|
73
|
+
asyncio.to_thread(self._client.api.exec_start, exec_id, detach=False),
|
|
74
|
+
timeout=self._timeout_s(context),
|
|
75
|
+
)
|
|
76
|
+
except asyncio.TimeoutError:
|
|
77
|
+
return ExecTimeout(stdout=b'', cmd=context.command)
|
|
78
|
+
|
|
79
|
+
exit_code = await asyncio.to_thread(
|
|
80
|
+
lambda: self._client.api.exec_inspect(exec_id).get('ExitCode'),
|
|
81
|
+
)
|
|
82
|
+
return ExecResult(stdout=stdout, cmd=context.command, exit_code=exit_code)
|
|
83
|
+
|
|
84
|
+
def _find_container(self, service_name: str):
|
|
85
|
+
containers = self._client.containers.list(
|
|
86
|
+
all=True,
|
|
87
|
+
filters={'label': f'com.docker.compose.service={service_name}'},
|
|
88
|
+
)
|
|
89
|
+
if not containers:
|
|
90
|
+
raise LookupError(f'Container for service {service_name!r} not found')
|
|
91
|
+
return containers[0]
|
|
92
|
+
|
|
93
|
+
def _create_exec(self, container, context: ExecContext) -> str:
|
|
94
|
+
environment = [
|
|
95
|
+
f'{key}={value}' for key, value in (context.extra_env or {}).items()
|
|
96
|
+
]
|
|
97
|
+
return self._client.api.exec_create(
|
|
98
|
+
container.id,
|
|
99
|
+
['sh', '-c', context.command],
|
|
100
|
+
environment=environment,
|
|
101
|
+
)['Id']
|
|
102
|
+
|
|
103
|
+
@staticmethod
|
|
104
|
+
def _timeout_s(context: ExecContext) -> float:
|
|
105
|
+
if context.timeout is None:
|
|
106
|
+
return 150.0
|
|
107
|
+
return max(context.timeout.attempts * context.timeout.delay_s, 0.05)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Use `context.container` as a compose service name; lookup by the
|
|
111
|
+
`com.docker.compose.service` label works across compose projects.
|
|
112
|
+
Handle `kill_before`/`kill_after` from `context.life_cycle_policy` if needed.
|
|
@@ -511,6 +511,39 @@ cassandra:
|
|
|
511
511
|
host: "[[cassandra]]"
|
|
512
512
|
```
|
|
513
513
|
|
|
514
|
+
## Live config values
|
|
515
|
+
|
|
516
|
+
Config values are resolved once, at import time — before the current env is
|
|
517
|
+
known. `live_env` (based on Cabina's `LazyEnvironment` / `FutureValue`) resolves
|
|
518
|
+
them on every access instead:
|
|
519
|
+
|
|
520
|
+
```python
|
|
521
|
+
import cabina
|
|
522
|
+
|
|
523
|
+
from uber_compose import live_env
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
class Config(cabina.Config, cabina.Section):
|
|
527
|
+
class Database(cabina.Section):
|
|
528
|
+
dsn: str = live_env.literal("postgres://db-[[namespace]]:5432/app")
|
|
529
|
+
|
|
530
|
+
class Api(cabina.Section):
|
|
531
|
+
url: str = live_env.raw("API_URL")
|
|
532
|
+
port: int = live_env.int("API_PORT")
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
Values are read through the sections, e.g. `Config.Api.port`.
|
|
536
|
+
|
|
537
|
+
- `raw` / `str` / `int` and other Cabina accessors read an env var;
|
|
538
|
+
- `literal` substitutes placeholders in an explicit value;
|
|
539
|
+
- placeholders are taken from the current env context (env id, namespace, worker
|
|
540
|
+
id, run id, service names) on every read, without caching.
|
|
541
|
+
|
|
542
|
+
Supported placeholders are the same as for `Service.env`: `[[env_id]]`,
|
|
543
|
+
`[[namespace]]`, `[[worker_id]]`, `[[worker_id_alpha_numeric]]`,
|
|
544
|
+
`[[namespace_alpha_numeric]]`, `[[worker_id_alpha_numeric_6]]`,
|
|
545
|
+
`[[namespace_alpha_numeric_6]]`, `[[test_run_id]]`, and `[[<service>]]`.
|
|
546
|
+
|
|
514
547
|
## Reporting details
|
|
515
548
|
|
|
516
549
|
Workers emit JSON events that the parent turns back into regular vedro events,
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
- [Parallel Runs by Use Case](PARALLELISM.md) — workers per env, parallelism and placeholders.
|
|
4
4
|
- [Uber-Compose vedro config](UBER_COMPOSE_VEDRO_CONFIG.md) — plugin configuration.
|
|
5
5
|
- [CLI Usage Guide](CLI_USAGE.md) — `CommonJsonCli` and JSON log parsing.
|
|
6
|
+
- [Alternative Exec Strategies](EXEC_STRATEGIES.md) — built-in alternatives and custom strategies.
|
|
6
7
|
- [Lifecycle Hooks](HOOKS.md) — hooks around environment startup.
|
|
7
8
|
- [X-Migration](X_MIGRATION.md) — initialization and migration commands.
|
|
8
9
|
- [E2E Test Setup](E2E_CONTAINER_SETUP.md) — configuring the E2E test container.
|
|
@@ -44,6 +44,9 @@ class UberCompose(VedroUberCompose):
|
|
|
44
44
|
|
|
45
45
|
Fine-tune health check parameters to ensure that your services are up and running before tests start executing. This can help avoid flaky tests due to services not being ready yet.
|
|
46
46
|
|
|
47
|
+
Waiting stops early when a service is `unhealthy` or exits non-zero without a
|
|
48
|
+
`restart` policy. With a restart policy, Uber-Compose keeps waiting for recovery.
|
|
49
|
+
|
|
47
50
|
## HealthCheck interval and attempts
|
|
48
51
|
```python
|
|
49
52
|
from uber_compose import VedroUberCompose, ComposeConfig, Environment, Service, UpHealthPolicy
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
from uber_compose.core.docker_compose_shell.exec_strategies import ExecContext
|
|
2
|
+
from uber_compose.core.docker_compose_shell.exec_strategies import ExecStrategy
|
|
3
|
+
from uber_compose.core.docker_compose_shell.exec_strategies import PidofExecStrategy
|
|
4
|
+
from uber_compose.core.docker_compose_shell.exec_strategies import StatusFileExecStrategy
|
|
1
5
|
from uber_compose.core.docker_compose_shell.interface import ProcessExit
|
|
2
6
|
from uber_compose.core.docker_compose_shell.interface import TimeOutCheck
|
|
3
7
|
from uber_compose.core.docker_compose_shell.types import ExecLifeCyclePolicy
|
|
@@ -11,9 +15,13 @@ from uber_compose.env_description.env_types import Service
|
|
|
11
15
|
from uber_compose.errors.mounted_files import MountedFileNotFoundError
|
|
12
16
|
from uber_compose.helpers.current_env import get_run_depth
|
|
13
17
|
from uber_compose.helpers.current_env import is_child_project
|
|
18
|
+
from uber_compose.helpers.exec_result import ExecResult
|
|
14
19
|
from uber_compose.helpers.exec_result import ExecTimeout
|
|
15
20
|
from uber_compose.helpers.health_policy import UpHealthPolicy
|
|
16
21
|
from uber_compose.helpers.hooks import UberComposeEvent
|
|
22
|
+
from uber_compose.helpers.live_env import LiveEnvironment
|
|
23
|
+
from uber_compose.helpers.live_env import LiveValue
|
|
24
|
+
from uber_compose.helpers.live_env import live_env
|
|
17
25
|
from uber_compose.output.console import LogEvents
|
|
18
26
|
from uber_compose.output.console import LogPolicy
|
|
19
27
|
from uber_compose.output.console import LogPolicySet
|
|
@@ -48,7 +56,8 @@ __all__ = (
|
|
|
48
56
|
'TheUberCompose', 'SystemUberCompose',
|
|
49
57
|
'Environment', 'Service', 'Env', 'OverridenService',
|
|
50
58
|
'CommonJsonCli', 'CommandResult', 'ProcessExit', 'JsonParser', 'json_parser', 'ExecTimeout', 'TimeOutCheck',
|
|
51
|
-
'ExecLifeCyclePolicy',
|
|
59
|
+
'ExecLifeCyclePolicy', 'ExecResult',
|
|
60
|
+
'ExecStrategy', 'ExecContext', 'PidofExecStrategy', 'StatusFileExecStrategy',
|
|
52
61
|
'VedroUberCompose', 'UpHealthPolicy', 'DEFAULT_COMPOSE', 'ComposeConfig', 'DEFAULT_ENV_DESCRIPTION',
|
|
53
62
|
'LogEvents', 'LogPolicy', 'LogPolicySet',
|
|
54
63
|
'DEFAULT_ENV_ID', 'UberComposeEvent', 'MountedFileNotFoundError',
|
|
@@ -57,4 +66,5 @@ __all__ = (
|
|
|
57
66
|
'get_run_depth', 'is_child_project',
|
|
58
67
|
'is_parallel_worker', 'is_parallel_worker_process', 'reset_execution_plan', 'set_execution_plan',
|
|
59
68
|
'VedroUberComposeParallel', 'build_execution_plan', 'build_execution_plan_from_scheduler',
|
|
69
|
+
'LiveEnvironment', 'LiveValue', 'live_env',
|
|
60
70
|
)
|
|
@@ -8,9 +8,35 @@ def default_log_file_path() -> Path:
|
|
|
8
8
|
return Path.cwd() / 'logs' / 'startup' / f'uber-compose-{timestamp}-{os.getpid()}.log'
|
|
9
9
|
|
|
10
10
|
|
|
11
|
+
def cleanup_log_files(log_file_path: str | Path, limit: int,
|
|
12
|
+
keep: str | Path | None = None) -> None:
|
|
13
|
+
"""Remove log files from the log directory when their count exceeds the limit."""
|
|
14
|
+
if limit is None or limit < 0:
|
|
15
|
+
return
|
|
16
|
+
|
|
17
|
+
directory = Path(log_file_path).parent
|
|
18
|
+
if not directory.is_dir():
|
|
19
|
+
return
|
|
20
|
+
|
|
21
|
+
keep_path = Path(keep) if keep is not None else None
|
|
22
|
+
files = [
|
|
23
|
+
file for file in directory.iterdir()
|
|
24
|
+
if file.is_file() and (keep_path is None or file != keep_path)
|
|
25
|
+
]
|
|
26
|
+
if len(files) <= limit:
|
|
27
|
+
return
|
|
28
|
+
|
|
29
|
+
for file in files:
|
|
30
|
+
file.unlink(missing_ok=True)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
DEFAULT_DOCKER_COMPOSE_FILES_AUTO_SCAN_PATTERN = r'(?:.*/)?docker-compose[^/]*\.(yaml|yml)$'
|
|
34
|
+
|
|
35
|
+
|
|
11
36
|
class Constants:
|
|
12
37
|
def __init__(self,
|
|
13
38
|
docker_compose_files_scan_depth: int = 2,
|
|
39
|
+
docker_compose_files_auto_scan_pattern: str = DEFAULT_DOCKER_COMPOSE_FILES_AUTO_SCAN_PATTERN,
|
|
14
40
|
cli_compose_util_override: str = None,
|
|
15
41
|
compose_project_name: str = None,
|
|
16
42
|
tmp_envs_path: str | Path = None,
|
|
@@ -18,6 +44,7 @@ class Constants:
|
|
|
18
44
|
mounted_files_path: str | Path = None,
|
|
19
45
|
mounted_files_host_path: str | Path = None,
|
|
20
46
|
log_file_path: str | Path = None,
|
|
47
|
+
log_files_limit: int = 10,
|
|
21
48
|
):
|
|
22
49
|
self.default_log_policy = os.environ.get('LOG_POLICY', 'DEFAULT')
|
|
23
50
|
|
|
@@ -35,6 +62,12 @@ class Constants:
|
|
|
35
62
|
tmp_envs_path or os.environ.get('TMP_ENVS_DIRECTORY', '/tmp/uc-envs')
|
|
36
63
|
)
|
|
37
64
|
self.log_file_path: Path = Path(log_file_path or default_log_file_path())
|
|
65
|
+
log_files_limit_env = os.environ.get('LOG_FILES_LIMIT')
|
|
66
|
+
self.log_files_limit: int | None = (
|
|
67
|
+
int(log_files_limit_env)
|
|
68
|
+
if log_files_limit_env is not None
|
|
69
|
+
else log_files_limit
|
|
70
|
+
)
|
|
38
71
|
|
|
39
72
|
self.in_docker_project_root_path: Path = Path(
|
|
40
73
|
in_docker_project_root_path or os.environ.get('PROJECT_ROOT_DIRECTORY', '/project')
|
|
@@ -74,6 +107,10 @@ class Constants:
|
|
|
74
107
|
self.docker_compose_files_scan_depth: int = int(
|
|
75
108
|
os.environ.get('DOCKER_COMPOSE_FILES_SCAN_DEPTH', docker_compose_files_scan_depth)
|
|
76
109
|
)
|
|
110
|
+
self.docker_compose_files_auto_scan_pattern: str = os.environ.get(
|
|
111
|
+
'DOCKER_COMPOSE_FILES_AUTO_SCAN_PATTERN',
|
|
112
|
+
docker_compose_files_auto_scan_pattern,
|
|
113
|
+
)
|
|
77
114
|
|
|
78
115
|
self.ignore_pidof_unexistance: bool = bool(os.environ.get('IGNORE_PIDOF_UNEXISTANCE', 'True') == 'True')
|
|
79
116
|
|
|
@@ -6,6 +6,7 @@ import sys
|
|
|
6
6
|
from rich.text import Text
|
|
7
7
|
|
|
8
8
|
from uber_compose.core.docker_compose_shell.interface import ComposeShellInterface
|
|
9
|
+
from uber_compose.core.docker_compose_shell.types import ComposeHealth
|
|
9
10
|
from uber_compose.core.docker_compose_shell.types import ComposeState
|
|
10
11
|
from uber_compose.core.docker_compose_shell.types import ServicesComposeState
|
|
11
12
|
from uber_compose.core.sequence_run_types import ComposeInstanceFiles
|
|
@@ -272,17 +273,29 @@ class ComposeInstance:
|
|
|
272
273
|
failed_services = [
|
|
273
274
|
service_state
|
|
274
275
|
for service_state in services_status
|
|
275
|
-
if
|
|
276
|
+
if self._is_failed_service(service_state)
|
|
276
277
|
]
|
|
277
278
|
for service_state in failed_services:
|
|
278
279
|
service_logs = await self.logs([service_state.name])
|
|
280
|
+
if service_state.state == ComposeState.EXITED:
|
|
281
|
+
failure_reason = f'exit code {service_state.exit_code}'
|
|
282
|
+
else:
|
|
283
|
+
failure_reason = 'unhealthy'
|
|
279
284
|
self.logger.write_file_log(
|
|
280
285
|
f'\n===== Logs for failed service {service_state.name} '
|
|
281
|
-
f'(
|
|
286
|
+
f'({failure_reason}) ====='
|
|
282
287
|
)
|
|
283
288
|
self.logger.write_file_log(service_logs.rstrip() or '<no service logs>')
|
|
284
289
|
self.logger.write_file_log(f'===== End of logs for failed service {service_state.name} =====\n')
|
|
285
290
|
|
|
291
|
+
@staticmethod
|
|
292
|
+
def _is_failed_service(service_state) -> bool:
|
|
293
|
+
if service_state.state == ComposeState.EXITED:
|
|
294
|
+
return service_state.exit_code != 0
|
|
295
|
+
if service_state.state == ComposeState.RUNNING:
|
|
296
|
+
return service_state.health == ComposeHealth.UNHEALTHY
|
|
297
|
+
return False
|
|
298
|
+
|
|
286
299
|
async def run(self):
|
|
287
300
|
with self.logger.stage_details(Text('Generating compose environment files', style=Style.info)):
|
|
288
301
|
self.compose_instance_files = await self.generate_config_files()
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
import shlex
|
|
5
|
+
from time import perf_counter
|
|
6
|
+
from typing import Callable
|
|
7
|
+
from typing import TYPE_CHECKING
|
|
8
|
+
from typing import Type
|
|
9
|
+
from uuid import uuid4
|
|
10
|
+
|
|
11
|
+
from uber_compose.core.constants import Constants
|
|
12
|
+
from uber_compose.core.docker_compose_shell.interface import ExecWasntSuccesfullyDone
|
|
13
|
+
from uber_compose.core.docker_compose_shell.interface import ProcessExit
|
|
14
|
+
from uber_compose.core.docker_compose_shell.interface import TimeOutCheck
|
|
15
|
+
from uber_compose.core.docker_compose_shell.types import ExecLifeCyclePolicy
|
|
16
|
+
from uber_compose.core.utils.shell_process import parse_process_command_name
|
|
17
|
+
from uber_compose.helpers.exec_result import ExecResult
|
|
18
|
+
from uber_compose.helpers.exec_result import ExecTimeout
|
|
19
|
+
from uber_compose.helpers.jobs_result import JobResult
|
|
20
|
+
|
|
21
|
+
if TYPE_CHECKING:
|
|
22
|
+
from uber_compose.core.docker_compose_shell.interface import ComposeShellInterface
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
INITIAL_POLL_DELAY_S = 0.05
|
|
26
|
+
MAX_POLL_DELAY_S = 1.0
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass(frozen=True)
|
|
30
|
+
class ExecContext:
|
|
31
|
+
shell: "ComposeShellInterface"
|
|
32
|
+
container: str
|
|
33
|
+
command: str
|
|
34
|
+
extra_env: dict[str, str] | None
|
|
35
|
+
wait: Callable | ProcessExit | None
|
|
36
|
+
timeout: TimeOutCheck | None
|
|
37
|
+
life_cycle_policy: ExecLifeCyclePolicy
|
|
38
|
+
env: dict | None = None
|
|
39
|
+
root: Path | str | None = None
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class ExecStrategy:
|
|
43
|
+
async def execute(self, context: ExecContext) -> ExecResult | ExecTimeout:
|
|
44
|
+
raise NotImplementedError
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class PidofExecStrategy(ExecStrategy):
|
|
48
|
+
"""Legacy exec strategy. Keeps the original pidof-based wait logic untouched."""
|
|
49
|
+
|
|
50
|
+
async def execute(self, context: ExecContext) -> ExecResult | ExecTimeout:
|
|
51
|
+
shell = context.shell
|
|
52
|
+
log_file = f'{uuid4()}.log'
|
|
53
|
+
cmd = f'sh -c \'{shlex.quote(context.command)[1:-1]} > /tmp/{log_file} 2>&1\''
|
|
54
|
+
|
|
55
|
+
result = await shell.dc_exec_until_state(
|
|
56
|
+
container=context.container,
|
|
57
|
+
cmd=cmd,
|
|
58
|
+
extra_env=context.extra_env,
|
|
59
|
+
wait=context.wait,
|
|
60
|
+
timeout=context.timeout,
|
|
61
|
+
break_on_timeout=context.life_cycle_policy.break_on_timeout,
|
|
62
|
+
kill_before=context.life_cycle_policy.kill_before_same_old_command_running,
|
|
63
|
+
kill_after=context.life_cycle_policy.kill_after_command_still_running,
|
|
64
|
+
env=context.env,
|
|
65
|
+
root=context.root,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
job_result, stdout, stderr = await shell.dc_exec(
|
|
69
|
+
context.container, f'cat /tmp/{log_file}', env=context.env, root=context.root,
|
|
70
|
+
)
|
|
71
|
+
if job_result != JobResult.GOOD:
|
|
72
|
+
shell.logger.error(
|
|
73
|
+
f'Error executing command in container {context.container}: {stderr}'
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
if not result.finished:
|
|
77
|
+
return ExecTimeout(stdout=stdout, cmd=context.command)
|
|
78
|
+
return ExecResult(stdout=stdout, cmd=context.command, exit_code=None)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class StatusFileExecStrategy(ExecStrategy):
|
|
82
|
+
"""Async exec strategy which waits for a status file and returns the command exit code."""
|
|
83
|
+
|
|
84
|
+
async def execute(self, context: ExecContext) -> ExecResult | ExecTimeout:
|
|
85
|
+
shell = context.shell
|
|
86
|
+
command = context.command.strip()
|
|
87
|
+
wait = context.wait
|
|
88
|
+
timeout = self._resolve_timeout(context.timeout)
|
|
89
|
+
|
|
90
|
+
if command.endswith('&'):
|
|
91
|
+
command = command[:-1].strip()
|
|
92
|
+
wait = None
|
|
93
|
+
|
|
94
|
+
cmd_name = parse_process_command_name(command) if command else ''
|
|
95
|
+
|
|
96
|
+
if context.life_cycle_policy.kill_before_same_old_command_running:
|
|
97
|
+
await self._kill(shell, context, cmd_name)
|
|
98
|
+
|
|
99
|
+
uid = uuid4().hex
|
|
100
|
+
log_file = f'/tmp/uber-compose-exec-{uid}.log'
|
|
101
|
+
exit_file = f'/tmp/uber-compose-exec-{uid}.exit'
|
|
102
|
+
marker = f'__UBER_COMPOSE_EXIT_{uid}__'
|
|
103
|
+
|
|
104
|
+
wrapped_command = (
|
|
105
|
+
f'( {command} ) > {log_file} 2>&1; '
|
|
106
|
+
f'printf \'%s\' "$?" > {exit_file}'
|
|
107
|
+
)
|
|
108
|
+
launch_cmd = f'sh -c {shlex.quote(wrapped_command)}'
|
|
109
|
+
launch_result = await shell.dc_exec_raw(
|
|
110
|
+
context.container,
|
|
111
|
+
launch_cmd,
|
|
112
|
+
extra_env=context.extra_env,
|
|
113
|
+
env=context.env,
|
|
114
|
+
root=context.root,
|
|
115
|
+
detached=True,
|
|
116
|
+
)
|
|
117
|
+
if launch_result.returncode != 0:
|
|
118
|
+
raise ExecWasntSuccesfullyDone(
|
|
119
|
+
f'\nCommand\n{command}\nwas not started in {context.container}:\n'
|
|
120
|
+
f'{launch_result.stdout=}\n{launch_result.stderr=}'
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
if wait is None:
|
|
124
|
+
if context.life_cycle_policy.kill_after_command_still_running:
|
|
125
|
+
await self._kill(shell, context, cmd_name)
|
|
126
|
+
stdout, _ = await self._read_result(
|
|
127
|
+
shell, context, log_file, exit_file, marker,
|
|
128
|
+
)
|
|
129
|
+
return ExecResult(stdout=stdout, cmd=command, exit_code=None)
|
|
130
|
+
|
|
131
|
+
if wait == ProcessExit():
|
|
132
|
+
finished = await self._wait_for_exit_file(
|
|
133
|
+
shell, context, exit_file, timeout,
|
|
134
|
+
)
|
|
135
|
+
stdout, exit_code = await self._read_result(
|
|
136
|
+
shell, context, log_file, exit_file, marker,
|
|
137
|
+
)
|
|
138
|
+
if not finished:
|
|
139
|
+
if context.life_cycle_policy.kill_after_command_still_running:
|
|
140
|
+
await self._kill(shell, context, cmd_name)
|
|
141
|
+
return ExecTimeout(stdout=stdout, cmd=command)
|
|
142
|
+
return ExecResult(stdout=stdout, cmd=command, exit_code=exit_code)
|
|
143
|
+
|
|
144
|
+
finished = await self._run_wait_callable(context, command, wait)
|
|
145
|
+
stdout, exit_code = await self._read_result(
|
|
146
|
+
shell, context, log_file, exit_file, marker,
|
|
147
|
+
)
|
|
148
|
+
if not finished:
|
|
149
|
+
if context.life_cycle_policy.kill_after_command_still_running:
|
|
150
|
+
await self._kill(shell, context, cmd_name)
|
|
151
|
+
return ExecTimeout(stdout=stdout, cmd=command)
|
|
152
|
+
return ExecResult(stdout=stdout, cmd=command, exit_code=exit_code)
|
|
153
|
+
|
|
154
|
+
@staticmethod
|
|
155
|
+
def _resolve_timeout(timeout: TimeOutCheck | None) -> TimeOutCheck:
|
|
156
|
+
if timeout is not None:
|
|
157
|
+
return timeout
|
|
158
|
+
return TimeOutCheck(
|
|
159
|
+
attempts=Constants().exec_pids_check_attempts_count,
|
|
160
|
+
delay_s=Constants().exec_pids_check_retry_delay,
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
async def _wait_for_exit_file(self, shell: "ComposeShellInterface", context: ExecContext,
|
|
164
|
+
exit_file: str, timeout: TimeOutCheck) -> bool:
|
|
165
|
+
timeout_s = max(timeout.attempts * timeout.delay_s, timeout.delay_s, INITIAL_POLL_DELAY_S)
|
|
166
|
+
started_at = perf_counter()
|
|
167
|
+
delay_s = INITIAL_POLL_DELAY_S
|
|
168
|
+
|
|
169
|
+
while True:
|
|
170
|
+
if await self._exit_file_exists(shell, context, exit_file):
|
|
171
|
+
return True
|
|
172
|
+
|
|
173
|
+
remaining_s = timeout_s - (perf_counter() - started_at)
|
|
174
|
+
if remaining_s <= 0:
|
|
175
|
+
return False
|
|
176
|
+
|
|
177
|
+
await asyncio.sleep(min(delay_s, remaining_s))
|
|
178
|
+
delay_s = min(delay_s * 2, MAX_POLL_DELAY_S)
|
|
179
|
+
|
|
180
|
+
@staticmethod
|
|
181
|
+
async def _exit_file_exists(shell: "ComposeShellInterface", context: ExecContext,
|
|
182
|
+
exit_file: str) -> bool:
|
|
183
|
+
result = await shell.dc_exec_raw(
|
|
184
|
+
context.container,
|
|
185
|
+
f'test -f {shlex.quote(exit_file)}',
|
|
186
|
+
env=context.env,
|
|
187
|
+
root=context.root,
|
|
188
|
+
)
|
|
189
|
+
return result.returncode == 0
|
|
190
|
+
|
|
191
|
+
@staticmethod
|
|
192
|
+
async def _read_result(shell: "ComposeShellInterface", context: ExecContext, log_file: str,
|
|
193
|
+
exit_file: str, marker: str) -> tuple[bytes, int | None]:
|
|
194
|
+
read_script = (
|
|
195
|
+
f'cat {log_file}; '
|
|
196
|
+
f'printf "\\n{marker}%s" "$(cat {exit_file} 2>/dev/null)"'
|
|
197
|
+
)
|
|
198
|
+
read_result = await shell.dc_exec_raw(
|
|
199
|
+
context.container,
|
|
200
|
+
f'sh -c {shlex.quote(read_script)}',
|
|
201
|
+
env=context.env,
|
|
202
|
+
root=context.root,
|
|
203
|
+
)
|
|
204
|
+
stdout, separator, raw_exit_code = read_result.stdout.partition(
|
|
205
|
+
f'\n{marker}'.encode(),
|
|
206
|
+
)
|
|
207
|
+
if not separator:
|
|
208
|
+
return read_result.stdout, None
|
|
209
|
+
try:
|
|
210
|
+
exit_code = int(raw_exit_code.strip())
|
|
211
|
+
except ValueError:
|
|
212
|
+
exit_code = None
|
|
213
|
+
return stdout, exit_code
|
|
214
|
+
|
|
215
|
+
@staticmethod
|
|
216
|
+
async def _run_wait_callable(context: ExecContext, command: str, wait: Callable) -> bool:
|
|
217
|
+
if asyncio.iscoroutinefunction(wait):
|
|
218
|
+
return await wait(
|
|
219
|
+
context.container,
|
|
220
|
+
command,
|
|
221
|
+
context.env,
|
|
222
|
+
context.extra_env,
|
|
223
|
+
context.life_cycle_policy.break_on_timeout,
|
|
224
|
+
)
|
|
225
|
+
return wait(
|
|
226
|
+
context.container,
|
|
227
|
+
command,
|
|
228
|
+
context.env,
|
|
229
|
+
context.extra_env,
|
|
230
|
+
context.life_cycle_policy.break_on_timeout,
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
@staticmethod
|
|
234
|
+
async def _kill(shell: "ComposeShellInterface", context: ExecContext, cmd_name: str) -> None:
|
|
235
|
+
if not cmd_name:
|
|
236
|
+
return
|
|
237
|
+
await shell.dc_exec_raw(
|
|
238
|
+
context.container,
|
|
239
|
+
f'killall {shlex.quote(cmd_name)}',
|
|
240
|
+
env=context.env,
|
|
241
|
+
root=context.root,
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
ExecStrategyType = Type[ExecStrategy]
|