1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
//! Command dispatch: map a parsed `Commands` to engine calls.
//!
//! Split out of `main.rs` to keep that file within the source line limit as the
//! CLI surface grows. The match consumes the `Commands` value (arms move their
//! fields); `Config`/`Generate`/`Ls`/`Update`/`Completions` are handled earlier
//! in `main` and reached here only as `unreachable!` guards.
mod rest;
use podup::Engine;
use crate::cli::*;
/// Clone the compose file keeping only services in an active profile, plus any
/// named on the command line (which activates their profile). Used by the
/// per-service subcommands so they target exactly the set `up`/`create` would
/// bring up — never a service hidden behind an inactive profile.
fn profile_filtered(
file: &podup::compose::types::ComposeFile,
profile: &[String],
targets: &[String],
) -> podup::compose::types::ComposeFile {
let mut filtered = file.clone();
podup::retain_active_profiles_with_targets(&mut filtered, profile, targets);
filtered
}
/// Run the command against an already-built engine and parsed compose file.
pub(crate) async fn dispatch(
engine: &Engine,
file: &podup::compose::types::ComposeFile,
command: Commands,
profile: &[String],
) -> podup::Result<()> {
match command {
Commands::Up {
detach,
build,
watch,
remove_orphans,
no_recreate,
force_recreate,
no_deps,
timeout: _,
scale: _,
pull: _,
no_build: _,
quiet_pull: _,
wait,
wait_timeout,
no_start,
timestamps,
renew_anon_volumes: _,
services,
} => {
if remove_orphans {
engine.remove_orphans(file).await?;
} else {
engine.warn_orphans(file).await?;
}
if build {
engine.build_all(file, &services).await?;
}
// `--no-start` creates the containers but never starts them, so the
// wait/watch/attach steps below do not apply.
if no_start {
engine
.create_with_options(
file,
profile,
&services,
no_recreate,
force_recreate,
no_deps,
)
.await?;
return Ok(());
}
engine
.up_with_options(
file,
detach,
profile,
&services,
no_recreate,
force_recreate,
no_deps,
)
.await?;
if wait {
// `--wait-timeout` bounds the health wait, like `start --wait`.
let fut = engine.wait_services_healthy(file, &services);
match wait_timeout {
Some(secs) => tokio::time::timeout(std::time::Duration::from_secs(secs), fut)
.await
.map_err(|_| podup::ComposeError::WaitTimeout { secs })??,
None => fut.await?,
}
}
// `--wait` implies detach, as it does in docker compose: the flag
// means "return once the services are up", so attaching afterwards
// would block forever on a command whose whole point is to finish.
// Measured against v5.1.3 on the same socket: `docker compose up
// --wait` exits 0, and `podup up --wait` hung until killed — which is
// the canonical health-gated CI idiom, so it hung the job.
if watch {
engine.watch(file).await?;
} else if !detach && !wait {
let outcome = engine.attach_logs_with_options(file, timestamps).await?;
// A failed teardown must surface as a non-zero exit, not be
// swallowed after the log streams end.
engine.stop(file, &[]).await?;
// Reported after the teardown, never instead of it: returning the
// interrupt straight from `attach` would short-circuit the `?`
// above and leave the project running, which is a worse bug than
// the exit code.
if outcome == podup::AttachOutcome::Interrupted {
return Err(podup::ComposeError::Interrupted);
}
// Same ordering rule as the interrupt above: reported after the
// teardown, never instead of it. docker compose exits 1 when an
// attached stream dies with the container still running, and we
// exited 0 — measured on 5.4.2 by restarting the libpod socket
// underneath an attached `up`.
if outcome == podup::AttachOutcome::StreamBroke {
return Err(podup::ComposeError::StreamTruncated(
"log stream ended while the container was still running: output is incomplete"
.to_string(),
));
}
}
}
Commands::Down {
volumes,
remove_orphans,
rmi,
timeout: _,
} => {
if remove_orphans {
engine.remove_orphans(file).await?;
}
engine.down_with_options(file, volumes).await?;
if let Some(scope) = rmi {
engine
.remove_service_images(file, scope == RmiScope::Local)
.await?;
}
}
Commands::Start {
wait,
wait_timeout,
services,
} => {
let file = &profile_filtered(file, profile, &services);
engine.start(file, &services).await?;
if wait {
match wait_timeout {
// `--wait-timeout` both extends the per-service poll budget (so a
// short healthcheck plan does not give up early) and caps the
// whole wait, so exhaustion surfaces as a clear WaitTimeout rather
// than a misleading per-container health-check timeout.
Some(secs) => {
let budget = std::time::Duration::from_secs(secs);
let fut =
engine.wait_services_healthy_within(file, &services, Some(budget));
tokio::time::timeout(budget, fut)
.await
.map_err(|_| podup::ComposeError::WaitTimeout { secs })??;
}
None => engine.wait_services_healthy(file, &services).await?,
}
}
}
Commands::Stop {
services,
timeout: _,
} => {
let file = &profile_filtered(file, profile, &services);
engine.stop(file, &services).await?
}
Commands::Scale { pairs } => engine.scale(file, &pairs).await?,
Commands::Create {
build,
force_recreate,
no_recreate,
// `--pull` is applied via the engine's pull-policy override, set in
// `main` (see `with_up_overrides`).
pull: _,
no_deps,
services,
} => {
if build {
engine.build_all(file, &services).await?;
}
engine
.create_with_options(
file,
profile,
&services,
no_recreate,
force_recreate,
no_deps,
)
.await?
}
Commands::Build {
no_cache,
pull,
build_arg,
// `--progress` selects a progress renderer in docker compose; accepted
// for compatibility but has no effect on podup's tracing output.
progress: _,
push,
quiet,
services,
} => {
let file = &profile_filtered(file, profile, &services);
engine
.build_all_with_options(
file,
&services,
&podup::BuildOptions {
no_cache,
pull,
build_args: build_arg,
quiet,
},
)
.await?;
// `--push` pushes each freshly built image to its registry.
if push {
engine
.push_with_quiet(file, &services, podup::PushOptions::default(), quiet)
.await?;
}
}
Commands::Rm {
force,
volumes,
stop,
services,
} => {
// `-s/--stop` gracefully stops the targets first so they can be
// removed without `--force`.
// A paused container cannot be stopped (Podman rejects it with a raw
// state error), so resume it first — matching `docker compose rm
// -s`. `unpause` is idempotent, so this is a no-op when not paused.
if stop {
engine.unpause(file, &services).await?;
engine.stop(file, &services).await?;
}
engine
.rm_with_options(file, &services, force, volumes)
.await?
}
Commands::Kill {
signal,
remove_orphans,
services,
} => {
let filtered = profile_filtered(file, profile, &services);
engine.kill(&filtered, &services, &signal).await?;
if remove_orphans {
engine.remove_orphans(file).await?;
}
}
Commands::Pause { services } => {
let file = &profile_filtered(file, profile, &services);
engine.pause(file, &services).await?
}
Commands::Unpause { services } => {
let file = &profile_filtered(file, profile, &services);
engine.unpause(file, &services).await?
}
other => rest::dispatch_rest(engine, file, other, profile).await?,
}
Ok(())
}