From 4e323559239511f5c3e914b21ab0215b5c376935 Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Wed, 17 Apr 2024 20:27:46 -0700 Subject: [PATCH] allow overriding docker repo and image tag Signed-off-by: Ava Hahn --- Readme.md | 9 ++++++--- src/main.rs | 25 +++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Readme.md b/Readme.md index 7fb0c76..28bc9f2 100644 --- a/Readme.md +++ b/Readme.md @@ -34,13 +34,16 @@ Unitctl has many functions. ### Starting a running Unit instance ``` -λ target/debug/unitctl start +λ unitctl start -Usage: unitctl start --socket +Usage: unitctl start [OPTIONS] --socket Options: -s, --socket path to desired control socket + -i, --image image tag for the unit container [default: latest] + -r, --repo alternate docker repository for custom unit images [default: nginx/unit] -h, --help Print help + ``` Unitctl will load and start a local Unit container. @@ -202,4 +205,4 @@ Example of a search for endpoints: - /config/listeners/{listenerName}/forwarded/recursive - /config/listeners/{listenerName}/forwarded/source - /config/listeners/{listenerName}/forwarded/source/{arrayIndex} -``` \ No newline at end of file +``` diff --git a/src/main.rs b/src/main.rs index a1efd03..d5241aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,7 +41,21 @@ struct StartArgs { required = true, help = "path to desired control socket" )] - socket: String + socket: String, + + #[arg( + short, long, + help = "image tag for the unit container", + default_value = "latest", // TODO : change to hardcoded git tag passed at build time + )] + image: String, + + #[arg( + short, long, + help = "alternate docker repository for custom unit images", + default_value = "nginx/unit" + )] + repo: String, } #[derive(Args, Clone)] @@ -110,8 +124,9 @@ struct SchemaArgs { } fn do_start(args: StartArgs) { + let image = format!("{}:{}", args.repo, args.image); Command::new("docker") - .args(["pull", "unit"]) + .args(["pull", image.as_str()]) .spawn() .expect("failed to call Docker") .wait() @@ -171,6 +186,12 @@ fn do_api_call(args: APIArgs, mut curl: Easy) { curl.post_fields_copy(data.as_bytes()); if args.put { + // do not actually use a put request + // it will not use the copied post field + // as of April 2024 there is a bug in the libcurl binding + // where the data buffer gets sent multiple times when using + // the read function callback. + // this is simpler and safer. curl.custom_request("PUT"); }