Skip to content

Commit

Permalink
merge: #2632
Browse files Browse the repository at this point in the history
2632: fix(si): Allow a user to pass a custom location to a docker.sock file r=stack72 a=stack72

Fixes: #2629

```
SI_DOCKER_SOCK=/var/run/docker.sock buck2 run //bin/si check
Checking for user supplied docker.sock
System Initiative Launcher is in "local" mode


Launcher update found, please run `si update` to install it

Checking that the system is able to interact with the docker engine to control System Initiative...
```


Co-authored-by: stack72 <[email protected]>
  • Loading branch information
si-bors-ng[bot] and stack72 authored Aug 17, 2023
2 parents 5aa23f0 + 9f3ba0d commit c60f76d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
5 changes: 5 additions & 0 deletions bin/si/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ pub(crate) struct Args {
#[arg(value_parser = PossibleValuesParser::new(Engine::variants()))]
#[arg(long, short, env = "SI_CONTAINER_ENGINE", default_value = "docker")]
engine: String,
/// A path to a docker.sock file. The default paths checked are `/var/run/docker.sock`
/// and `$HOME/.docker/run/docker.sock"`. Passing a value here will be an explicit
/// usage of that location.
#[arg(long, env = "SI_DOCKER_SOCK")]
pub docker_sock: Option<String>,
#[command(subcommand)]
pub(crate) command: Commands,
}
Expand Down
27 changes: 20 additions & 7 deletions bin/si/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ async fn main() -> Result<()> {
let mode = args.mode();
let is_preview = args.is_preview;

let docker_sock = if let Some(sock) = args.docker_sock.clone() {
sock
} else {
"".to_string()
};

let current_version = VERSION.trim();

debug!(arguments =?args, "parsed cli arguments");
Expand All @@ -41,14 +47,21 @@ async fn main() -> Result<()> {
std::path::Path::new("/var/run/docker.sock").to_path_buf(),
];

let docker_socket = docker_socket_candidates
.iter()
.find(|candidate| candidate.exists())
.ok_or(eyre!(
"failed to determine Docker socket location; candidates={docker_socket_candidates:?}"
let docker: DockerClient;
if let "" = docker_sock.as_str() {
let socket = docker_socket_candidates
.iter()
.find(|candidate| candidate.exists())
.ok_or(eyre!(
"failed to determine Docker socket location. Set a custom location using `--docker-sock` \
or `SI_DOCKER_SOCK`; candidates={docker_socket_candidates:?}"
))?;

let docker = DockerClient::unix(docker_socket);
docker = DockerClient::unix(socket)
} else {
println!("Checking for user supplied docker.sock");
let path = std::path::Path::new(docker_sock.as_str()).to_path_buf();
docker = DockerClient::unix(path);
}

let state = AppState::new(
ph_client,
Expand Down

0 comments on commit c60f76d

Please sign in to comment.