uber-compose 2.3.3__tar.gz → 3.0.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.
Files changed (102) hide show
  1. uber_compose-3.0.0/MANIFEST.in +4 -0
  2. {uber_compose-2.3.3 → uber_compose-3.0.0}/PKG-INFO +10 -2
  3. {uber_compose-2.3.3 → uber_compose-3.0.0}/README.md +8 -0
  4. uber_compose-3.0.0/docs/CLI_USAGE.md +429 -0
  5. uber_compose-3.0.0/docs/E2E_CONTAINER_SETUP.md +171 -0
  6. uber_compose-3.0.0/docs/ENV_LOCKS_FEATURE_REQUEST.md +96 -0
  7. uber_compose-3.0.0/docs/EXEC_STRATEGIES.md +112 -0
  8. uber_compose-3.0.0/docs/HOOKS.md +35 -0
  9. uber_compose-3.0.0/docs/LLM_RULES.md +40 -0
  10. uber_compose-3.0.0/docs/PARALLELISM.md +545 -0
  11. uber_compose-3.0.0/docs/PLAN_CONSISTENCY.md +392 -0
  12. uber_compose-3.0.0/docs/README.md +10 -0
  13. uber_compose-3.0.0/docs/RELEASE_TAGS.md +85 -0
  14. uber_compose-3.0.0/docs/UBER_COMPOSE_VEDRO_CONFIG.md +82 -0
  15. uber_compose-3.0.0/docs/X_MIGRATION.md +192 -0
  16. uber_compose-3.0.0/docs/common.puml +24 -0
  17. uber_compose-3.0.0/requirements.txt +4 -0
  18. {uber_compose-2.3.3 → uber_compose-3.0.0}/setup.py +14 -1
  19. uber_compose-3.0.0/uber_compose/__init__.py +66 -0
  20. uber_compose-3.0.0/uber_compose/core/constants.py +112 -0
  21. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/core/docker_compose.py +150 -62
  22. uber_compose-3.0.0/uber_compose/core/docker_compose_shell/exec_strategies.py +245 -0
  23. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/core/docker_compose_shell/interface.py +49 -0
  24. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/core/docker_compose_shell/types.py +3 -0
  25. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/core/sequence_run_types.py +5 -2
  26. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/core/system_docker_compose.py +11 -0
  27. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/core/utils/compose_files.py +232 -31
  28. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/core/utils/compose_instance_cfg.py +34 -14
  29. uber_compose-3.0.0/uber_compose/core/utils/state_waiting.py +127 -0
  30. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/env_description/env_tools.py +4 -2
  31. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/env_description/env_types.py +4 -1
  32. uber_compose-3.0.0/uber_compose/errors/mounted_files.py +25 -0
  33. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/errors/up.py +4 -0
  34. uber_compose-3.0.0/uber_compose/helpers/broken_services.py +47 -0
  35. uber_compose-3.0.0/uber_compose/helpers/current_env.py +87 -0
  36. uber_compose-3.0.0/uber_compose/helpers/env_id.py +21 -0
  37. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/helpers/exec_result.py +4 -0
  38. uber_compose-3.0.0/uber_compose/helpers/hooks.py +24 -0
  39. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/helpers/jobs_result.py +2 -1
  40. uber_compose-3.0.0/uber_compose/helpers/parameterization.py +94 -0
  41. uber_compose-3.0.0/uber_compose/helpers/workers_per_env.py +16 -0
  42. uber_compose-3.0.0/uber_compose/output/console.py +215 -0
  43. uber_compose-3.0.0/uber_compose/parallel_plugin/__init__.py +43 -0
  44. uber_compose-3.0.0/uber_compose/parallel_plugin/details.py +58 -0
  45. uber_compose-3.0.0/uber_compose/parallel_plugin/grouper.py +97 -0
  46. uber_compose-3.0.0/uber_compose/parallel_plugin/grouping.py +30 -0
  47. uber_compose-3.0.0/uber_compose/parallel_plugin/planner.py +407 -0
  48. uber_compose-3.0.0/uber_compose/parallel_plugin/plugin.py +186 -0
  49. uber_compose-3.0.0/uber_compose/parallel_plugin/runner.py +511 -0
  50. uber_compose-3.0.0/uber_compose/parallel_plugin/types.py +34 -0
  51. uber_compose-3.0.0/uber_compose/parallel_plugin/worker_api.py +158 -0
  52. uber_compose-3.0.0/uber_compose/parallel_plugin/worker_filter.py +38 -0
  53. uber_compose-3.0.0/uber_compose/uber_compose.py +720 -0
  54. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/vedro_plugin/base_structures/common_json_cli.py +32 -10
  55. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/vedro_plugin/helpers/scenario_tag_processing.py +6 -6
  56. uber_compose-3.0.0/uber_compose/vedro_plugin/plugin.py +516 -0
  57. uber_compose-3.0.0/uber_compose/version +1 -0
  58. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose.egg-info/PKG-INFO +10 -2
  59. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose.egg-info/SOURCES.txt +32 -0
  60. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose.egg-info/requires.txt +1 -1
  61. uber_compose-2.3.3/uber_compose/__init__.py +0 -31
  62. uber_compose-2.3.3/uber_compose/core/constants.py +0 -40
  63. uber_compose-2.3.3/uber_compose/core/utils/state_waiting.py +0 -70
  64. uber_compose-2.3.3/uber_compose/helpers/broken_services.py +0 -29
  65. uber_compose-2.3.3/uber_compose/output/console.py +0 -111
  66. uber_compose-2.3.3/uber_compose/uber_compose.py +0 -284
  67. uber_compose-2.3.3/uber_compose/vedro_plugin/plugin.py +0 -266
  68. uber_compose-2.3.3/uber_compose/version +0 -1
  69. {uber_compose-2.3.3 → uber_compose-3.0.0}/LICENSE +0 -0
  70. {uber_compose-2.3.3 → uber_compose-3.0.0}/setup.cfg +0 -0
  71. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/core/__init__.py +0 -0
  72. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/core/docker_compose_shell/__init__.py +0 -0
  73. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/core/utils/__init__.py +0 -0
  74. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/core/utils/env_files.py +0 -0
  75. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/core/utils/process_command_output.py +0 -0
  76. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/core/utils/shell_process.py +0 -0
  77. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/env_description/__init__.py +0 -0
  78. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/errors/__init__.py +0 -0
  79. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/errors/migrations.py +0 -0
  80. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/helpers/__init__.py +0 -0
  81. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/helpers/bytes_pickle.py +0 -0
  82. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/helpers/countdown_counter.py +0 -0
  83. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/helpers/exec_record.py +0 -0
  84. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/helpers/health_policy.py +0 -0
  85. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/helpers/labels.py +0 -0
  86. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/helpers/singleton.py +0 -0
  87. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/helpers/state_keeper.py +0 -0
  88. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/output/__init__.py +0 -0
  89. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/output/styles.py +0 -0
  90. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/utils/__init__.py +0 -0
  91. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/utils/docker_compose_files_path.py +0 -0
  92. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/utils/docker_compose_service_deps.py +0 -0
  93. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/utils/search_docker_compose_files.py +0 -0
  94. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/utils/services_construction.py +0 -0
  95. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/vedro_plugin/__init__.py +0 -0
  96. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/vedro_plugin/base_structures/__init__.py +0 -0
  97. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/vedro_plugin/helpers/__init__.py +0 -0
  98. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/vedro_plugin/helpers/scenario_ordering.py +0 -0
  99. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/vedro_plugin/helpers/test_env_vars_setter.py +0 -0
  100. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose/version.py +0 -0
  101. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose.egg-info/dependency_links.txt +0 -0
  102. {uber_compose-2.3.3 → uber_compose-3.0.0}/uber_compose.egg-info/top_level.txt +0 -0
@@ -0,0 +1,4 @@
1
+ include LICENSE
2
+ include README.md
3
+ include requirements.txt
4
+ recursive-include docs *.md *.puml
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: uber-compose
3
- Version: 2.3.3
3
+ Version: 3.0.0
4
4
  Summary: docker compose testing env orchestrator
5
5
  Home-page: https://github.com/ko10ok/uber-compose
6
6
  Author: Yuriy Sagitov
@@ -15,7 +15,7 @@ Classifier: Programming Language :: Python :: 3.14
15
15
  Requires-Python: >=3.10.0
16
16
  Description-Content-Type: text/markdown
17
17
  License-File: LICENSE
18
- Requires-Dist: vedro<2.0,>=1.10
18
+ Requires-Dist: vedro<2.0,>=1.15
19
19
  Requires-Dist: PyYAML<6.1,>=6.0.1
20
20
  Requires-Dist: rtry<2.0,>=1.4.0
21
21
  Requires-Dist: rich<16.0,>=11.0
@@ -144,6 +144,11 @@ You can customize behavior dynamically:
144
144
  - --uc-ju — Bring up the environment without running any tests
145
145
  - --uc-default / --uc-dev — Choose between defined ComposeConfigs
146
146
  - --uc-env — Filter tests by environment name/description
147
+ - --uc-mt — Enable parallel scenario execution (worker processes)
148
+ - --uc-workers-per-env N / --uc-wpe N — Override workers per env for this run
149
+
150
+ For parallel runs see **[Parallel Runs by Use Case](docs/PARALLELISM.md)** — it
151
+ shows which config and which flag to use for each scenario.
147
152
 
148
153
  ---
149
154
 
@@ -230,7 +235,10 @@ This is particularly useful when:
230
235
 
231
236
  - **[E2E Test Setup](docs/E2E_CONTAINER_SETUP.md)** - Configure test container for E2E testing
232
237
  - **[CLI Usage Guide](docs/CLI_USAGE.md)** - Guide for using CommonJsonCli with JSON log parsing
238
+ - **[Alternative Exec Strategies](docs/EXEC_STRATEGIES.md)** - Built-in exec alternatives and custom strategies
233
239
  - **[X-Migration](docs/X_MIGRATION.md)** - Extended service initialization and migration commands
240
+ - **[Lifecycle Hooks](docs/HOOKS.md)** - Register callbacks that run after the environment is up
241
+ - **[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
234
242
 
235
243
  ## 🛠️ Development Guide
236
244
 
@@ -111,6 +111,11 @@ You can customize behavior dynamically:
111
111
  - --uc-ju — Bring up the environment without running any tests
112
112
  - --uc-default / --uc-dev — Choose between defined ComposeConfigs
113
113
  - --uc-env — Filter tests by environment name/description
114
+ - --uc-mt — Enable parallel scenario execution (worker processes)
115
+ - --uc-workers-per-env N / --uc-wpe N — Override workers per env for this run
116
+
117
+ For parallel runs see **[Parallel Runs by Use Case](docs/PARALLELISM.md)** — it
118
+ shows which config and which flag to use for each scenario.
114
119
 
115
120
  ---
116
121
 
@@ -197,7 +202,10 @@ This is particularly useful when:
197
202
 
198
203
  - **[E2E Test Setup](docs/E2E_CONTAINER_SETUP.md)** - Configure test container for E2E testing
199
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
200
206
  - **[X-Migration](docs/X_MIGRATION.md)** - Extended service initialization and migration commands
207
+ - **[Lifecycle Hooks](docs/HOOKS.md)** - Register callbacks that run after the environment is up
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
201
209
 
202
210
  ## 🛠️ Development Guide
203
211
 
@@ -0,0 +1,429 @@
1
+ # CommonJsonCli Usage Guide
2
+
3
+ `CommonJsonCli` is a client for executing commands in Docker containers with automatic JSON log parsing and error handling.
4
+
5
+ ## Table of Contents
6
+ - [Basic Usage](#basic-usage)
7
+ - [Extended Command Result](#extended-command-result)
8
+ - [Custom JSON Parser](#custom-json-parser)
9
+ - [CommandResult](#commandresult)
10
+ - [JsonParser Configuration](#jsonparser-configuration)
11
+ - [ExecLifeCyclePolicy](#execlifecyclepolicy)
12
+ - [Exec Strategies](#exec-strategies)
13
+ - [Timeouts Redefinition](#timeouts-redefinition)
14
+
15
+ ---
16
+
17
+ ## Basic Usage
18
+
19
+ Create a CLI client by inheriting from `CommonJsonCli`:
20
+
21
+ ```python
22
+ from uber_compose import CommonJsonCli, CommandResult
23
+
24
+ class MyCli(CommonJsonCli):
25
+ def __init__(self):
26
+ self.container = 'app_container'
27
+ super().__init__()
28
+
29
+ async def run_command(self) -> CommandResult:
30
+ return await self.exec(
31
+ container=self.container,
32
+ command='my-app --option value',
33
+ )
34
+
35
+ # Usage
36
+ cli = MyCli()
37
+ result = await cli.run_command()
38
+
39
+ # Access results
40
+ print(result.stdout) # list of parsed JSON logs or strings
41
+ print(result.stderr) # list of error logs
42
+ print(result.has_no_errors()) # True if no errors
43
+ ```
44
+
45
+ ### With Environment Variables
46
+
47
+ By default, any executed command uses env variables set in container.
48
+ You can override it by adding extra environment variables via extra_env.
49
+
50
+ ```python
51
+ async def run_with_env(self) -> CommandResult:
52
+ return await self.exec(
53
+ container='app_container',
54
+ command='my-app',
55
+ extra_env={'DEBUG': 'true', 'LOG_LEVEL': 'debug'}
56
+ )
57
+ ```
58
+
59
+ ---
60
+
61
+ ### Setup Container For All Commands
62
+
63
+ ```python
64
+ from uber_compose import CommonJsonCli, CommandResult
65
+
66
+ class MyCli(CommonJsonCli):
67
+ def __init__(self):
68
+ super().__init__(container = 'app_container')
69
+
70
+ async def run_command(self) -> CommandResult:
71
+ return await self.exec(command='my-app --option value')
72
+
73
+ async def run_another_command(self) -> CommandResult:
74
+ return await self.exec(command='my-app-another-part --any-option value2')
75
+
76
+ ```
77
+
78
+ ## Extended Command Result
79
+
80
+ Extend `CommandResult` to add custom fields:
81
+
82
+ ```python
83
+ from dataclasses import dataclass
84
+ from uber_compose import CommonJsonCli, CommandResult
85
+
86
+ @dataclass
87
+ class ExtendedCommandResult(CommandResult):
88
+ config_data: dict = None
89
+ metadata: str = ""
90
+
91
+ class MyCli(CommonJsonCli[ExtendedCommandResult]):
92
+ def __init__(self):
93
+ self.container = 'app_container'
94
+ super().__init__(result_factory=ExtendedCommandResult)
95
+
96
+ async def run_with_config(self, config: dict) -> ExtendedCommandResult:
97
+ return await self.exec(
98
+ container=self.container,
99
+ command='my-app',
100
+ command_result_extra={
101
+ 'config_data': config,
102
+ 'metadata': 'custom_metadata'
103
+ }
104
+ )
105
+
106
+ # Usage
107
+ cli = MyCli()
108
+ result = await cli.run_with_config({'key': 'value'})
109
+
110
+ # Access extended fields
111
+ print(result.config_data) # {'key': 'value'}
112
+ print(result.metadata) # 'custom_metadata'
113
+ ```
114
+
115
+ ---
116
+
117
+ ## Custom JSON Parser
118
+
119
+ Configure JSON parsing behavior with `JsonParser`:
120
+
121
+ ### String Output (default)
122
+
123
+ ```python
124
+ from uber_compose import CommonJsonCli, JsonParser
125
+
126
+ parser = JsonParser()
127
+ cli = CommonJsonCli(parse_json_logs=parser.parse_output_to_json)
128
+ ```
129
+
130
+ Output example:
131
+ ```python
132
+ result.stdout = [
133
+ '{"level": "info", "msg": "Started"}',
134
+ '{"level": "debug", "msg": "Processing"}'
135
+ ]
136
+ ```
137
+
138
+ ### Dictionary Output
139
+
140
+ ```python
141
+ parser = JsonParser(dict_output=True)
142
+ cli = CommonJsonCli(parse_json_logs=parser.parse_output_to_json)
143
+ ```
144
+
145
+ Output example:
146
+ ```python
147
+ result.stdout = [
148
+ {'level': 'info', 'msg': 'Started'},
149
+ {'level': 'debug', 'msg': 'Processing'}
150
+ ]
151
+ ```
152
+
153
+ ### Custom Error Levels
154
+
155
+ ```python
156
+ parser = JsonParser(
157
+ stderr_log_levels=['error', 'fatal', 'critical']
158
+ )
159
+ cli = CommonJsonCli(parse_json_logs=parser.parse_output_to_json)
160
+ ```
161
+
162
+ ### Skip Log Lines
163
+
164
+ Skip logs by substring or regex pattern:
165
+
166
+ ```python
167
+ parser = JsonParser(
168
+ skips=['debug_info', r'^\[TRACE\]'],
169
+ skips_warns=True # Warn when skipping
170
+ )
171
+ cli = CommonJsonCli(parse_json_logs=parser.parse_output_to_json)
172
+ ```
173
+
174
+ Skipped logs appear in `stdout` as raw strings (or `{'raw': 'log_line'}` with `dict_output=True`).
175
+
176
+ ### Full Stdout Control
177
+
178
+ ```python
179
+ # Default: errors appear in both stdout and stderr
180
+ parser = JsonParser(full_stdout=True)
181
+
182
+ # Errors only in stderr
183
+ parser = JsonParser(full_stdout=False)
184
+ ```
185
+
186
+ ### Custom Log Level Key
187
+
188
+ ```python
189
+ # Default key is 'level'
190
+ parser = JsonParser(log_level_key='severity')
191
+
192
+ # For logs like: {"severity": "error", "msg": "Failed"}
193
+ ```
194
+
195
+ ### Combined Configuration
196
+
197
+ ```python
198
+ parser = JsonParser(
199
+ log_level_key='level',
200
+ stderr_log_levels=['error', 'fatal', 'panic'],
201
+ full_stdout=True,
202
+ dict_output=True,
203
+ skips=['debug_verbose', r'^\[INTERNAL\]'],
204
+ skips_warns=False
205
+ )
206
+
207
+ cli = CommonJsonCli(parse_json_logs=parser.parse_output_to_json)
208
+ ```
209
+
210
+ ---
211
+
212
+ ## CommandResult
213
+
214
+ ### Fields
215
+
216
+ - **`stdout`**: `list[str | dict]` - Parsed output logs
217
+ - **`stderr`**: `list[str | dict]` - Error logs (based on log level)
218
+ - **`cmd`**: `str` - Executed command
219
+ - **`env`**: `dict[str, str]` - Environment variables used
220
+ - **`exit_code`**: `int | None` - Application exit code; `None` means the process did not finish
221
+
222
+ ### Methods
223
+
224
+ - **`has_no_errors()`**: Returns `True` only if `stderr` is empty and `exit_code` is `0`
225
+
226
+ ### Example
227
+
228
+ ```python
229
+ result = await cli.exec(container='app', command='my-cmd')
230
+
231
+ if result.has_no_errors():
232
+ print("Success!")
233
+ for log in result.stdout:
234
+ print(log)
235
+ else:
236
+ print("Errors occurred:")
237
+ for error in result.stderr:
238
+ print(error)
239
+ ```
240
+
241
+ ---
242
+
243
+ ## JsonParser Configuration
244
+
245
+ ### Parameters
246
+
247
+ | Parameter | Type | Default | Description |
248
+ |-----------|------|---------|-------------|
249
+ | `log_level_key` | `str \| list[str]` | `'level'` | Key name for log level in JSON |
250
+ | `stderr_log_levels` | `list[str]` | `['panic', 'fatal', 'error', 'warning']` | Log levels to route to stderr |
251
+ | `full_stdout` | `bool` | `True` | Include errors in stdout |
252
+ | `dict_output` | `bool` | `False` | Output as dicts instead of strings |
253
+ | `skips` | `list[str]` | `[]` | Patterns to skip (substring or regex) |
254
+ | `skips_warns` | `bool` | `False` | Warn when skipping logs |
255
+
256
+ ### Log Levels
257
+
258
+ Predefined in `LogLevels` class:
259
+ - `TRACE`, `DEBUG`, `INFO`, `WARNING`, `ERROR`, `FATAL`, `PANIC`
260
+
261
+ ### Non-JSON Logs
262
+
263
+ Non-JSON lines are treated as errors and:
264
+ - Added to `stderr`
265
+ - Optionally added to `stdout` (if `full_stdout=True`)
266
+ - Formatted as raw strings or `{'raw': 'line'}` (if `dict_output=True`)
267
+
268
+ ---
269
+
270
+ ## Complete Example
271
+
272
+ ```python
273
+ import time
274
+
275
+ from dataclasses import dataclass
276
+ from uber_compose import CommonJsonCli, CommandResult, JsonParser
277
+
278
+
279
+ @dataclass
280
+ class MyCommandResult(CommandResult):
281
+ start_time: float = 0.0
282
+
283
+ class AppCli(CommonJsonCli[MyCommandResult]):
284
+ def __init__(self):
285
+ # Configure parser
286
+ parser = JsonParser(
287
+ dict_output=True,
288
+ stderr_log_levels=['error', 'fatal'],
289
+ skips=[r'health_check']
290
+ )
291
+
292
+ super().__init__(
293
+ container = 'my_app',
294
+ parse_json_logs=parser.parse_output_to_json,
295
+ result_factory=MyCommandResult
296
+ )
297
+
298
+ async def process_data(self, data_path: str) -> MyCommandResult:
299
+ result = await self.exec(
300
+ command=f'process --file {data_path}',
301
+ extra_env={'LOG_FORMAT': 'json'},
302
+ command_result_extra={
303
+ 'start_time': time.time()
304
+ }
305
+ )
306
+
307
+ return result
308
+
309
+ # Usage
310
+ cli = AppCli()
311
+ result = await cli.process_data('/data/input.csv')
312
+
313
+ assert result.has_no_errors()
314
+ ```
315
+
316
+ ## ExecLifeCyclePolicy
317
+
318
+ `ExecLifeCyclePolicy` controls the execution behavior of commands to optimize performance and resource usage. It allows you to skip certain phases of the command execution lifecycle.
319
+
320
+ ### Parameters
321
+
322
+ | Parameter | Type | Default | Description |
323
+ |-----------|------|---------|-------------|
324
+ | `kill_before_same_old_command_running` | `bool` | `True` | Kill the previous instance of the same command if it is still running before executing a new one |
325
+ | `kill_after_command_still_running` | `bool` | `True` | Kill the command if it is still running after the timeout has elapsed |
326
+ | `break_on_timeout` | `bool` | `True` | Stop waiting and return early if the timeout is reached |
327
+
328
+ ### Basic Usage
329
+
330
+ ```python
331
+ from uber_compose import CommonJsonCli, ExecLifeCyclePolicy
332
+
333
+ class AppCli(CommonJsonCli):
334
+ def __init__(self):
335
+ super().__init__(
336
+ container='app',
337
+ life_cycle_policy=ExecLifeCyclePolicy(
338
+ kill_before_same_old_command_running=True,
339
+ kill_after_command_still_running=True,
340
+ break_on_timeout=True
341
+ )
342
+ )
343
+ ```
344
+
345
+ ### Override Policy Per Command
346
+
347
+ ```python
348
+ from uber_compose import CommonJsonCli, CommandResult, ExecLifeCyclePolicy
349
+
350
+ class AppCli(CommonJsonCli):
351
+ def __init__(self):
352
+ super().__init__(container='app')
353
+
354
+ async def run_quick_command(self) -> CommandResult:
355
+ return await self.exec(
356
+ command='quick-task',
357
+ life_cycle_policy=ExecLifeCyclePolicy(
358
+ kill_before_same_old_command_running=False,
359
+ kill_after_command_still_running=False,
360
+ )
361
+ )
362
+ ```
363
+
364
+ ### Disable Lifecycle Management
365
+
366
+ ```python
367
+ # Disable killing old instances
368
+ policy = ExecLifeCyclePolicy(kill_before_same_old_command_running=False)
369
+
370
+ # Disable all lifecycle management
371
+ policy = ExecLifeCyclePolicy(
372
+ kill_before_same_old_command_running=False,
373
+ kill_after_command_still_running=False,
374
+ break_on_timeout=False
375
+ )
376
+ ```
377
+
378
+ ## Exec Strategies
379
+
380
+ See [Alternative Exec Strategies](EXEC_STRATEGIES.md).
381
+
382
+ ## Timeouts Redefinition
383
+
384
+ By default `CommonJsonCli` uses the following timeouts for command execution:
385
+
386
+ ```python
387
+ from uber_compose import TimeOutCheck
388
+
389
+ timeout = TimeOutCheck(
390
+ attempts=10,
391
+ delay_s=1
392
+ ),
393
+ ```
394
+
395
+ It's possible to redefine these timeouts in the `__init__` method of your CLI class:
396
+
397
+ ```python
398
+ from uber_compose import CommonJsonCli, CommandResult, JsonParser, TimeOutCheck
399
+
400
+ class AppCli(CommonJsonCli):
401
+ def __init__(self):
402
+ super().__init__(
403
+ timeout = TimeOutCheck(
404
+ attempts=10,
405
+ delay_s=1
406
+ ),
407
+ )
408
+ ```
409
+
410
+ Or redefine only for specific command:
411
+
412
+ ```python
413
+ import time
414
+
415
+ from uber_compose import CommonJsonCli, CommandResult, JsonParser, TimeOutCheck
416
+
417
+ class AppCli(CommonJsonCli):
418
+ def __init__(self):
419
+ super().__init__(container='app')
420
+
421
+ async def run_command_with_custom_timeout(self) -> CommandResult:
422
+ return await self.exec(
423
+ command='command',
424
+ timeout = TimeOutCheck(
425
+ attempts=50,
426
+ delay_s=2
427
+ ),
428
+ )
429
+ ```
@@ -0,0 +1,171 @@
1
+ # E2E Test Container Setup
2
+
3
+ This guide explains how to configure your test container for running E2E tests with Uber-Compose.
4
+
5
+ ## Prerequisites
6
+
7
+ Your test container needs Docker Compose CLI to manage services during testing.
8
+
9
+ ## 1. Add Docker Compose CLI to Test Container
10
+
11
+ Add Docker Compose CLI to your test container's **Dockerfile**:
12
+
13
+ ### Alpine
14
+
15
+ ```dockerfile
16
+ RUN apk add docker-cli docker-cli-compose
17
+ ```
18
+
19
+ ### Debian/Ubuntu
20
+
21
+ ```dockerfile
22
+ RUN apt install docker-ce-cli docker-compose-plugin
23
+ ```
24
+
25
+ ### Legacy docker-compose Binary (if needed)
26
+
27
+ ```dockerfile
28
+ # For AMD64
29
+ RUN if [[ "$TARGETPLATFORM" = "linux/amd64" ]] ; then \
30
+ curl -SL https://github.com/docker/compose/releases/download/v2.24.4/docker-compose-linux-x86_64 \
31
+ -o /usr/local/bin/docker-compose ; fi
32
+
33
+ # For ARM64
34
+ RUN if [[ "$TARGETPLATFORM" = "linux/arm64" ]] ; then \
35
+ curl -SL https://github.com/docker/compose/releases/download/v2.24.4/docker-compose-linux-aarch64 \
36
+ -o /usr/local/bin/docker-compose ; fi
37
+
38
+ RUN chmod +x /usr/local/bin/docker-compose
39
+ ```
40
+
41
+ ## 2. Configure Test Container
42
+
43
+ Configure your test container in `docker-compose.yml`:
44
+
45
+ ```yaml
46
+ services:
47
+ e2e-tests:
48
+ volumes:
49
+ - .:/project
50
+ environment:
51
+ # Docker daemon connection
52
+ - DOCKER_HOST=tcp://test-docker-daemon:2375 # Default: dockersock:2375
53
+
54
+ # Containers that should not be stopped by Uber-Compose
55
+ - NON_STOP_CONTAINERS=e2e-tests # Default: e2e,dockersock
56
+
57
+ # Project root directory on host machine
58
+ - HOST_PROJECT_ROOT_DIRECTORY=${PWD} # For project root or test directory
59
+
60
+ # Unique project name for CI isolation
61
+ - COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME} # Setup unique name for CI runs
62
+ ```
63
+
64
+ ### Environment Variables
65
+
66
+ | Variable | Default | Description |
67
+ |----------|---------|-------------|
68
+ | `DOCKER_HOST` | `tcp://dockersock:2375` | Docker daemon connection URL |
69
+ | `NON_STOP_CONTAINERS` | `e2e,dockersock` | Containers excluded from management |
70
+ | `HOST_PROJECT_ROOT_DIRECTORY` | - | Path to docker-compose files on host |
71
+ | `MOUNTED_FILES_DIRECTORY` | - | Used for `mounted_files` in parallel runs; see [Parallel Runs](PARALLELISM.md#mounted-config-templates) |
72
+ | `COMPOSE_PROJECT_NAME` | - | Unique project identifier for CI |
73
+
74
+
75
+ ## Example: Complete Setup
76
+
77
+ ### Dockerfile
78
+
79
+ ```dockerfile
80
+ FROM python:3.10-alpine
81
+
82
+ # Install Docker CLI and Compose
83
+ RUN apk add --no-cache docker-cli docker-cli-compose
84
+
85
+ # Install test dependencies
86
+ COPY requirements.txt .
87
+ RUN pip install -r requirements.txt
88
+
89
+ WORKDIR /project
90
+ ```
91
+
92
+ ### docker-compose.yml
93
+
94
+ ```yaml
95
+ version: "3"
96
+
97
+ services:
98
+ dockersock:
99
+ image: docker:dind
100
+ privileged: true
101
+ environment:
102
+ - DOCKER_TLS_CERTDIR=
103
+ ports:
104
+ - "2375:2375"
105
+
106
+ e2e-tests:
107
+ build: .
108
+ depends_on:
109
+ - dockersock
110
+ volumes:
111
+ - .:/project
112
+ environment:
113
+ - DOCKER_HOST=tcp://dockersock:2375
114
+ - NON_STOP_CONTAINERS=e2e-tests
115
+ - HOST_PROJECT_ROOT_DIRECTORY=${PWD}
116
+ - COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME:-uber-compose-tests}
117
+ command: tail -f /dev/null
118
+ ```
119
+
120
+ ## Troubleshooting
121
+
122
+ ### Cannot connect to Docker daemon
123
+
124
+ Ensure `DOCKER_HOST` points to the correct Docker daemon and it's running:
125
+
126
+ ```bash
127
+ docker-compose exec e2e-tests docker ps
128
+ ```
129
+
130
+ ### Test container stopped unexpectedly
131
+
132
+ Check `NON_STOP_CONTAINERS` includes your test container:
133
+
134
+ ```bash
135
+ echo $NON_STOP_CONTAINERS
136
+ ```
137
+
138
+ ### Volume mounting issues
139
+
140
+ Verify `HOST_PROJECT_ROOT_DIRECTORY` is set correctly:
141
+
142
+ ```bash
143
+ docker-compose exec e2e-tests env | grep HOST_PROJECT_ROOT_DIRECTORY
144
+ ```
145
+
146
+ ## Advanced Configuration
147
+
148
+ Optional environment variables for fine-tuning Uber-Compose behavior.
149
+
150
+ | Variable | Default | Purpose | Use Case |
151
+ |----------|---------|---------|----------|
152
+ | `LOG_POLICY` | `DEFAULT` | Control logging verbosity | Primary control via `--uc-v` parameter at runtime. Set to `VERBOSE` for detailed logs during debugging. |
153
+ | `TMP_ENVS_DIRECTORY` | `/tmp/uc-envs` | Temporary environment files storage | Change if `/tmp` has limited space or specific requirements |
154
+ | `PROJECT_ROOT_DIRECTORY` | `/project` | Container project root path | Set when project mounted to non-standard location |
155
+ | `DOCKER_COMPOSE_FILES_SCAN_DEPTH` | `2` | Directory scan depth for compose files | Increase if compose files nested deeper than 2 levels |
156
+ | `DOCKER_COMPOSE_EXTRA_EXEC_PARAMS` | `-T` | Extra parameters for `docker-compose exec` | Modify to add flags like `--user` or remove `-T` for TTY |
157
+ | `CLI_COMPOSE_UTIL` | `None` | Override compose CLI path | Set when using standalone `docker-compose` binary. Primary uses `docker compose` |
158
+ | `EXEC_PIDS_CHECK_ATTEMPTS_COUNT` | `150` | Process completion check attempts during migrations | Increase for slow systems or long migration times |
159
+ | `EXEC_PIDS_CHECK_RETRY_DELAY` | `1` | Delay (seconds) between process completion checks during migrations | Increase to reduce CPU usage on slow systems |
160
+ | `IGNORE_PIDOF_UNEXISTANCE` | `True` | Ignore missing `pidof` utility | Set to `False` if strict process checking required |
161
+
162
+ **Example:**
163
+ ```yaml
164
+ environment:
165
+ # Deeper directory scanning: only project root directory
166
+ - DOCKER_COMPOSE_FILES_SCAN_DEPTH=1
167
+
168
+ # Extended monitoring for slow systems
169
+ - EXEC_PIDS_CHECK_ATTEMPTS_COUNT=300
170
+ - EXEC_PIDS_CHECK_RETRY_DELAY=2
171
+ ```