Skip to content

Commit

Permalink
Support using subcommand as Docker CLI plugin for tighter integration
Browse files Browse the repository at this point in the history
See docker/cli#1534 for CLI plugin design.
  • Loading branch information
evolutics committed Sep 30, 2023
1 parent 564a14b commit 8562828
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ The built executable is installed into the folder `~/.cargo/bin` by default.

### Docker CLI plugin

Coming soon for integration with the familiar Docker CLI.
Optionally, Wheelsticks can be set up as a Docker CLI plugin. With that, calls
to `wheelsticks deploy` can be replaced by `docker deploy`, which some people
prefer. Example [setup](https://github.com/docker/cli/issues/1534):

```bash
mkdir --parents ~/.docker/cli-plugins
ln --symbolic "$(which wheelsticks)" ~/.docker/cli-plugins/docker-deploy
```

## Usage

Expand Down
46 changes: 46 additions & 0 deletions src/docker_cli_plugin_metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
pub fn go() -> anyhow::Result<String> {
let authors = env!("CARGO_PKG_AUTHORS");
let first_author_name = authors
.split_once(" <")
.ok_or(anyhow::anyhow!("{authors}"))?
.0;
Ok(serde_json::to_string_pretty(&Metadata {
schema_version: "0.1.0".into(),
short_description: env!("CARGO_PKG_DESCRIPTION").into(),
url: env!("CARGO_PKG_HOMEPAGE").into(),
vendor: first_author_name.into(),
version: env!("CARGO_PKG_VERSION").into(),
})?)
}

#[derive(serde::Serialize)]
#[serde(rename_all = "PascalCase")]
struct Metadata {
schema_version: String,
short_description: String,
#[serde(rename = "URL")]
url: String,
vendor: String,
version: String,
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn handles() -> anyhow::Result<()> {
let metadata = go()?;
assert_eq!(
metadata,
r#"{
"SchemaVersion": "0.1.0",
"ShortDescription": "Zero-downtime deployments for Docker Compose",
"URL": "https://github.com/evolutics/wheelsticks",
"Vendor": "Benjamin Fischer",
"Version": "1.0.0"
}"#,
);
Ok(())
}
}
13 changes: 11 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod command;
mod deploy;
mod docker;
mod docker_cli_plugin_metadata;
mod log;

use clap::Parser;
Expand Down Expand Up @@ -116,6 +117,12 @@ fn main() -> anyhow::Result<()> {
wait_timeout: wait_timeout.map(|wait_timeout| wait_timeout.to_string()),
})
}

Subcommand::DockerCliPluginMetadata => {
let metadata = docker_cli_plugin_metadata::go()?;
println!("{metadata}");
Ok(())
}
}
}

Expand Down Expand Up @@ -278,8 +285,7 @@ enum ComposeEngine {
enum Subcommand {
// Source for some arguments:
// https://docs.docker.com/engine/reference/commandline/compose_up/

// TODO: Support use as plugin (https://github.com/docker/cli/issues/1534).
//
/// Create or update services
///
/// Builds, (re)creates, and starts containers for a service.
Expand Down Expand Up @@ -351,6 +357,9 @@ enum Subcommand {

service_names: Vec<String>,
},

#[command(hide = true)]
DockerCliPluginMetadata,
}

#[derive(Clone, ValueEnum)]
Expand Down

0 comments on commit 8562828

Please sign in to comment.