GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support selecting the container engine (docker or Apple Container) (#… · stellar/stellar-cli@902eeb0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • FULL_HELP_DOCS.md
  • cmd
    • crates/soroban-test/tests/it
      • container.rs
      • main.rs
    • soroban-cli/src
      • commands
        • container
          • logs.rs
          • mod.rs
          • shared.rs
          • start.rs
          • stop.rs
        • doctor.rs
      • env_vars.rs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎FULL_HELP_DOCS.md‎

Copy file name to clipboardExpand all lines: FULL_HELP_DOCS.md
+16Lines changed: 16 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,11 @@ Get logs from a running network container
16761676
###### **Options:**
16771677

16781678
- `-d`, `--docker-host <DOCKER_HOST>` — Optional argument to override the default docker host. This is useful when you are using a non-standard docker host path for your Docker-compatible container runtime, e.g. Docker Desktop defaults to $HOME/.docker/run/docker.sock instead of /var/run/docker.sock
1679+
- `--engine <ENGINE>` — Container engine to use [default: docker]
1680+
1681+
Possible values:
1682+
- `docker`: Docker, or any Docker-compatible CLI
1683+
- `apple-container`: Apple's `container` CLI (macOS 26+, Apple silicon)
16791684

16801685
## `stellar container start`
16811686

@@ -1698,6 +1703,12 @@ By default, when starting a testnet container, without any optional arguments, i
16981703
###### **Options:**
16991704

17001705
- `-d`, `--docker-host <DOCKER_HOST>` — Optional argument to override the default docker host. This is useful when you are using a non-standard docker host path for your Docker-compatible container runtime, e.g. Docker Desktop defaults to $HOME/.docker/run/docker.sock instead of /var/run/docker.sock
1706+
- `--engine <ENGINE>` — Container engine to use [default: docker]
1707+
1708+
Possible values:
1709+
- `docker`: Docker, or any Docker-compatible CLI
1710+
- `apple-container`: Apple's `container` CLI (macOS 26+, Apple silicon)
1711+
17011712
- `--name <NAME>` — Optional argument to specify the container name
17021713
- `-l`, `--limits <LIMITS>` — Optional argument to specify the limits for the local network only
17031714
- `-p`, `--ports-mapping <PORTS_MAPPING>` — Argument to specify the `HOST_PORT:CONTAINER_PORT` mapping
@@ -1722,6 +1733,11 @@ Stop a network container started with `stellar container start`
17221733
###### **Options:**
17231734

17241735
- `-d`, `--docker-host <DOCKER_HOST>` — Optional argument to override the default docker host. This is useful when you are using a non-standard docker host path for your Docker-compatible container runtime, e.g. Docker Desktop defaults to $HOME/.docker/run/docker.sock instead of /var/run/docker.sock
1736+
- `--engine <ENGINE>` — Container engine to use [default: docker]
1737+
1738+
Possible values:
1739+
- `docker`: Docker, or any Docker-compatible CLI
1740+
- `apple-container`: Apple's `container` CLI (macOS 26+, Apple silicon)
17251741

17261742
## `stellar config`
17271743

Collapse file

‎cmd/crates/soroban-test/tests/it/container.rs‎

Copy file name to clipboard
+281Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
//! End-to-end tests for `stellar container start|stop|logs`.
2+
//!
3+
//! These never touch a real container runtime. Instead they drop a fake `docker`
4+
//! / `container` executable into a temp dir, point `PATH` at it, and assert on
5+
//! both the CLI's behavior and the exact argv the fake was invoked with. This
6+
//! exercises the real spawn path and stderr classification that the unit tests in
7+
//! `shared.rs` can't reach.
8+
9+
use std::fs;
10+
use std::os::unix::fs::PermissionsExt;
11+
use std::path::PathBuf;
12+
13+
use assert_cmd::Command;
14+
use predicates::prelude::predicate;
15+
use soroban_test::TestEnv;
16+
17+
/// A sandbox with an isolated `PATH` that only contains the fake engines we
18+
/// explicitly install, so the real `docker`/`container` on the host is never hit.
19+
struct EngineSandbox {
20+
env: TestEnv,
21+
bin_dir: PathBuf,
22+
log: PathBuf,
23+
}
24+
25+
impl EngineSandbox {
26+
fn new() -> Self {
27+
let env = TestEnv::default();
28+
let bin_dir = env.dir().join("fake-bin");
29+
fs::create_dir_all(&bin_dir).unwrap();
30+
let log = env.dir().join("engine-invocations.log");
31+
Self { env, bin_dir, log }
32+
}
33+
34+
/// Installs a fake engine binary named `name` (e.g. `docker` or `container`).
35+
/// Each invocation appends its argv to the shared log; behavior is driven by
36+
/// the `FAKE_ENGINE_MODE` env var (`ok`, `already_running`, `not_found`). The
37+
/// stderr wording matches the real engine the binary is impersonating so the
38+
/// CLI's per-engine classifiers are exercised end-to-end.
39+
fn install_engine(&self, name: &str) {
40+
// Real-world stderr strings the CLI classifies, per engine.
41+
let (already_running, not_found) = if name == "container" {
42+
(
43+
"Error: container with id stellar-local already exists",
44+
r#"Error: internalError: "failed to stop container" (cause: "notFound: "container with ID stellar-local not found"")"#,
45+
)
46+
} else {
47+
(
48+
r#"docker: Error response from daemon: Conflict. The container name "/stellar-local" is already in use."#,
49+
"Error response from daemon: No such container: stellar-local",
50+
)
51+
};
52+
let script = format!(
53+
r#"#!/bin/sh
54+
echo "{name} $@" >> "{log}"
55+
case " $* " in
56+
*" pull "*) exit 0 ;;
57+
*" run "*)
58+
case "$FAKE_ENGINE_MODE" in
59+
already_running)
60+
echo '{already_running}' >&2
61+
exit 1 ;;
62+
*) exit 0 ;;
63+
esac ;;
64+
*" stop "*)
65+
case "$FAKE_ENGINE_MODE" in
66+
not_found)
67+
echo '{not_found}' >&2
68+
exit 1 ;;
69+
*) exit 0 ;;
70+
esac ;;
71+
*) exit 0 ;;
72+
esac
73+
"#,
74+
name = name,
75+
log = self.log.display(),
76+
);
77+
let path = self.bin_dir.join(name);
78+
fs::write(&path, script).unwrap();
79+
fs::set_permissions(&path, fs::Permissions::from_mode(0o755)).unwrap();
80+
}
81+
82+
/// Builds a `container` subcommand whose `PATH` is only the fake bin dir.
83+
fn cmd(&self, mode: &str) -> Command {
84+
let mut cmd = self.env.new_assert_cmd("container");
85+
cmd.env("PATH", &self.bin_dir)
86+
.env("FAKE_ENGINE_MODE", mode)
87+
// Don't inherit a real DOCKER_HOST/engine from the developer's shell.
88+
.env_remove("DOCKER_HOST")
89+
.env_remove("STELLAR_CONTAINER_ENGINE");
90+
cmd
91+
}
92+
93+
fn invocations(&self) -> String {
94+
fs::read_to_string(&self.log).unwrap_or_default()
95+
}
96+
}
97+
98+
fn line_for(log: &str, needle: &str) -> String {
99+
log.lines()
100+
.find(|l| l.contains(needle))
101+
.unwrap_or_else(|| panic!("no invocation containing {needle:?} in:\n{log}"))
102+
.to_string()
103+
}
104+
105+
#[test]
106+
fn start_defaults_to_docker_and_passes_expected_args() {
107+
let s = EngineSandbox::new();
108+
s.install_engine("docker");
109+
110+
s.cmd("ok")
111+
.args(["start", "local"])
112+
.assert()
113+
.success()
114+
.stderr(predicate::str::contains("Started container"));
115+
116+
let log = s.invocations();
117+
// Pulled and ran via docker (not the apple `image pull` form).
118+
assert!(line_for(&log, "pull").starts_with("docker pull "));
119+
let run = line_for(&log, " run ");
120+
assert!(run.starts_with("docker "), "expected docker binary: {run}");
121+
assert!(run.contains("--name stellar-local"), "run line: {run}");
122+
assert!(run.contains("-p 8000:8000"), "run line: {run}");
123+
// No host override unless requested.
124+
assert!(!run.contains("-H "), "unexpected -H: {run}");
125+
}
126+
127+
#[test]
128+
fn start_passes_docker_host_as_h_flag() {
129+
let s = EngineSandbox::new();
130+
s.install_engine("docker");
131+
132+
s.cmd("ok")
133+
.args(["start", "local", "--docker-host", "ssh://me@host"])
134+
.assert()
135+
.success();
136+
137+
let run = line_for(&s.invocations(), " run ");
138+
assert!(run.contains("-H ssh://me@host"), "run line: {run}");
139+
}
140+
141+
#[test]
142+
fn start_reports_already_running_from_stderr() {
143+
let s = EngineSandbox::new();
144+
s.install_engine("docker");
145+
146+
s.cmd("already_running")
147+
.args(["start", "local"])
148+
.assert()
149+
.failure()
150+
.stderr(predicate::str::contains("already running"));
151+
}
152+
153+
#[test]
154+
fn stop_success() {
155+
let s = EngineSandbox::new();
156+
s.install_engine("docker");
157+
158+
s.cmd("ok")
159+
.args(["stop", "local"])
160+
.assert()
161+
.success()
162+
.stderr(predicate::str::contains("Container stopped"));
163+
164+
assert!(line_for(&s.invocations(), " stop ").contains("stop stellar-local"));
165+
}
166+
167+
#[test]
168+
fn stop_reports_not_found_from_stderr() {
169+
let s = EngineSandbox::new();
170+
s.install_engine("docker");
171+
172+
s.cmd("not_found")
173+
.args(["stop", "local"])
174+
.assert()
175+
.failure()
176+
.stderr(predicate::str::contains("container local not found"));
177+
}
178+
179+
#[test]
180+
fn apple_engine_uses_container_binary_and_image_pull() {
181+
let s = EngineSandbox::new();
182+
// Only the apple engine exists on PATH; if the CLI shelled out to docker it
183+
// would fail with a not-found error instead.
184+
s.install_engine("container");
185+
186+
s.cmd("ok")
187+
.args(["start", "local", "--engine", "apple-container"])
188+
.assert()
189+
.success();
190+
191+
let log = s.invocations();
192+
// Apple groups image ops under `image` (singular) and takes no `--tail`.
193+
assert!(line_for(&log, "pull").starts_with("container image pull "));
194+
let run = line_for(&log, " run ");
195+
assert!(
196+
run.starts_with("container "),
197+
"expected container binary: {run}"
198+
);
199+
}
200+
201+
#[test]
202+
fn apple_engine_reports_already_running_from_stderr() {
203+
let s = EngineSandbox::new();
204+
s.install_engine("container");
205+
206+
// The fake `container` emits Apple's `already exists` wording, so this only
207+
// passes if the CLI classifies stderr with the apple-container matcher.
208+
s.cmd("already_running")
209+
.args(["start", "local", "--engine", "apple-container"])
210+
.assert()
211+
.failure()
212+
.stderr(predicate::str::contains("already running"));
213+
}
214+
215+
#[test]
216+
fn apple_engine_reports_not_found_from_stderr() {
217+
let s = EngineSandbox::new();
218+
s.install_engine("container");
219+
220+
// The fake `container` emits Apple's `not found` wording here.
221+
s.cmd("not_found")
222+
.args(["stop", "local", "--engine", "apple-container"])
223+
.assert()
224+
.failure()
225+
.stderr(predicate::str::contains("container local not found"));
226+
}
227+
228+
#[test]
229+
fn apple_engine_selectable_via_env_var() {
230+
let s = EngineSandbox::new();
231+
s.install_engine("container");
232+
233+
s.cmd("ok")
234+
.env("STELLAR_CONTAINER_ENGINE", "apple-container")
235+
.args(["start", "local"])
236+
.assert()
237+
.success();
238+
239+
assert!(line_for(&s.invocations(), " run ").starts_with("container "));
240+
}
241+
242+
#[test]
243+
fn warns_and_drops_docker_host_for_apple_engine() {
244+
let s = EngineSandbox::new();
245+
s.install_engine("container");
246+
247+
s.cmd("ok")
248+
.args([
249+
"start",
250+
"local",
251+
"--engine",
252+
"apple-container",
253+
"--docker-host",
254+
"ssh://me@host",
255+
])
256+
.assert()
257+
.success()
258+
.stderr(predicate::str::contains(
259+
"is ignored because the `apple-container` engine",
260+
));
261+
262+
// The ignored host must not reach the container binary.
263+
assert!(
264+
!s.invocations().contains("-H "),
265+
"host leaked to container CLI"
266+
);
267+
}
268+
269+
#[test]
270+
fn errors_when_engine_binary_is_missing() {
271+
// No engine installed on the isolated PATH.
272+
let s = EngineSandbox::new();
273+
274+
s.cmd("ok")
275+
.args(["stop", "local"])
276+
.assert()
277+
.failure()
278+
.stderr(predicate::str::contains(
279+
"is docker installed and on your PATH?",
280+
));
281+
}
Collapse file

‎cmd/crates/soroban-test/tests/it/main.rs‎

Copy file name to clipboardExpand all lines: cmd/crates/soroban-test/tests/it/main.rs
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
mod build;
22
mod config;
3+
#[cfg(unix)]
4+
mod container;
35
#[cfg(feature = "emulator-tests")]
46
mod emulator;
57
mod help;
Collapse file

‎cmd/soroban-cli/src/commands/container/logs.rs‎

Copy file name to clipboardExpand all lines: cmd/soroban-cli/src/commands/container/logs.rs
+7-4Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::commands::{container::shared::Error as ConnectionError, global};
2+
use crate::print;
23

34
use super::shared::{Args, Name};
45

@@ -22,17 +23,19 @@ pub struct Cmd {
2223
}
2324

2425
impl Cmd {
25-
pub async fn run(&self, _global_args: &global::Args) -> Result<(), Error> {
26+
pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
27+
let print = print::Print::new(global_args.quiet);
2628
let container_name = Name(self.name.clone()).get_internal_container_name();
2729

30+
self.container_args.warn_if_host_ignored(&print);
31+
2832
// Stream logs straight to the terminal by inheriting stdio.
2933
let status = self
3034
.container_args
31-
.docker_command()
32-
.args(["logs", "-f", "--tail", "all", &container_name])
35+
.logs_command(&container_name)
3336
.status()
3437
.await
35-
.map_err(ConnectionError::from)?;
38+
.map_err(|e| self.container_args.io_error(e))?;
3639

3740
if !status.success() {
3841
return Err(Error::TailContainerError);
Collapse file

‎cmd/soroban-cli/src/commands/container/mod.rs‎

Copy file name to clipboardExpand all lines: cmd/soroban-cli/src/commands/container/mod.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::commands::global;
22

33
pub(crate) mod logs;
4-
mod shared;
4+
pub(crate) mod shared;
55
pub(crate) mod start;
66
pub(crate) mod stop;
77

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.