Skip to content

Commit e7243f2

Browse files
committed
add --release arg to stacks
1 parent 26e387a commit e7243f2

File tree

3 files changed

+59
-9
lines changed

3 files changed

+59
-9
lines changed

rust/stackablectl/src/cli/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use crate::{
1919
cmds::{cache, completions, debug, demo, operator, release, stack, stacklet},
2020
constants::{
2121
DEMOS_REPOSITORY_URL_BASE, ENV_KEY_DEMO_FILES, ENV_KEY_RELEASE_FILES, ENV_KEY_STACK_FILES,
22-
REMOTE_RELEASE_FILE, REMOTE_STACK_FILE, USER_DIR_APPLICATION_NAME,
23-
USER_DIR_ORGANIZATION_NAME, USER_DIR_QUALIFIER,
22+
REMOTE_RELEASE_FILE, USER_DIR_APPLICATION_NAME, USER_DIR_ORGANIZATION_NAME,
23+
USER_DIR_QUALIFIER,
2424
},
2525
output::{ErrorContext, Output, ResultContext},
2626
};
@@ -104,8 +104,13 @@ impl Cli {
104104
/// Returns a list of stack files, consisting of entries which are either a path or URL. The list of files combines
105105
/// the default stack file URL, [`REMOTE_STACK_FILE`], files provided by the ENV variable [`ENV_KEY_STACK_FILES`],
106106
/// and lastly, files provided by the CLI argument `--stack-file`.
107-
pub fn get_stack_files(&self) -> Result<Vec<PathOrUrl>, PathOrUrlParseError> {
108-
let mut files = get_files(REMOTE_STACK_FILE, ENV_KEY_STACK_FILES)?;
107+
pub fn get_stack_files(&self, branch: &str) -> Result<Vec<PathOrUrl>, PathOrUrlParseError> {
108+
let branch_url = format!(
109+
"{base}/{branch}/stacks/stacks-v2.yaml",
110+
base = DEMOS_REPOSITORY_URL_BASE
111+
);
112+
113+
let mut files = get_files(&branch_url, ENV_KEY_STACK_FILES)?;
109114

110115
let arg_files = self.files.stack_files.clone().into_paths_or_urls()?;
111116
files.extend(arg_files);

rust/stackablectl/src/cmds/demo.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,13 @@ impl DemoArgs {
171171
.context(BuildListSnafu)?;
172172

173173
let release_branch = match &self.release {
174-
Some(release) => format!("release-{release}"),
174+
Some(release) => {
175+
if release == "dev" {
176+
"main".to_string()
177+
} else {
178+
format!("release-{release}")
179+
}
180+
}
175181
None => {
176182
let release = release_list
177183
.inner()
@@ -196,7 +202,9 @@ impl DemoArgs {
196202
match &self.subcommand {
197203
DemoCommands::List(args) => list_cmd(args, cli, list).await,
198204
DemoCommands::Describe(args) => describe_cmd(args, cli, list).await,
199-
DemoCommands::Install(args) => install_cmd(args, cli, list, &transfer_client).await,
205+
DemoCommands::Install(args) => {
206+
install_cmd(args, cli, list, &transfer_client, &release_branch).await
207+
}
200208
}
201209
}
202210
}
@@ -308,6 +316,7 @@ async fn install_cmd(
308316
cli: &Cli,
309317
list: demo::List,
310318
transfer_client: &xfer::Client,
319+
release_branch: &str,
311320
) -> Result<String, CmdError> {
312321
info!("Installing demo {}", args.demo_name);
313322

@@ -319,7 +328,9 @@ async fn install_cmd(
319328
})?;
320329

321330
// TODO (Techassi): Try to move all this boilerplate code to build the lists out of here
322-
let files = cli.get_stack_files().context(PathOrUrlParseSnafu)?;
331+
let files = cli
332+
.get_stack_files(release_branch)
333+
.context(PathOrUrlParseSnafu)?;
323334
let stack_list = stack::StackList::build(&files, transfer_client)
324335
.await
325336
.context(BuildListSnafu)?;

rust/stackablectl/src/cmds/stack.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use comfy_table::{
33
presets::{NOTHING, UTF8_FULL},
44
ContentArrangement, Table,
55
};
6-
use snafu::{ResultExt, Snafu};
6+
use snafu::{OptionExt, ResultExt, Snafu};
77
use stackable_operator::kvp::{LabelError, Labels};
88
use tracing::{debug, info, instrument};
99

@@ -30,6 +30,10 @@ use crate::{
3030
pub struct StackArgs {
3131
#[command(subcommand)]
3232
subcommand: StackCommands,
33+
34+
/// Target a specific Stackable release
35+
#[arg(long, global = true)]
36+
release: Option<String>,
3337
}
3438

3539
#[derive(Debug, Subcommand)]
@@ -116,6 +120,9 @@ pub enum CmdError {
116120
#[snafu(display("failed to serialize JSON output"))]
117121
SerializeJsonOutput { source: serde_json::Error },
118122

123+
#[snafu(display("empty release list"))]
124+
EmptyReleaseList,
125+
119126
#[snafu(display("failed to build stack/release list"))]
120127
BuildList { source: list::Error },
121128

@@ -140,7 +147,34 @@ impl StackArgs {
140147
debug!("Handle stack args");
141148

142149
let transfer_client = xfer::Client::new_with(cache);
143-
let files = cli.get_stack_files().context(PathOrUrlParseSnafu)?;
150+
151+
let release_files = cli.get_release_files().context(PathOrUrlParseSnafu)?;
152+
let release_list = release::ReleaseList::build(&release_files, &transfer_client)
153+
.await
154+
.context(BuildListSnafu)?;
155+
156+
let release_branch = match &self.release {
157+
Some(release) => {
158+
if release == "dev" {
159+
"main".to_string()
160+
} else {
161+
format!("release-{release}")
162+
}
163+
}
164+
None => {
165+
let release = release_list
166+
.inner()
167+
.first()
168+
.context(EmptyReleaseListSnafu)?
169+
.0;
170+
171+
format!("release-{release}")
172+
}
173+
};
174+
175+
let files = cli
176+
.get_stack_files(&release_branch)
177+
.context(PathOrUrlParseSnafu)?;
144178
let stack_list = stack::StackList::build(&files, &transfer_client)
145179
.await
146180
.context(BuildListSnafu)?;

0 commit comments

Comments
 (0)