Skip to content

Commit

Permalink
add --release arg to stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
labrenbe committed Dec 5, 2024
1 parent 26e387a commit e7243f2
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 9 deletions.
13 changes: 9 additions & 4 deletions rust/stackablectl/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::{
cmds::{cache, completions, debug, demo, operator, release, stack, stacklet},
constants::{
DEMOS_REPOSITORY_URL_BASE, ENV_KEY_DEMO_FILES, ENV_KEY_RELEASE_FILES, ENV_KEY_STACK_FILES,
REMOTE_RELEASE_FILE, REMOTE_STACK_FILE, USER_DIR_APPLICATION_NAME,
USER_DIR_ORGANIZATION_NAME, USER_DIR_QUALIFIER,
REMOTE_RELEASE_FILE, USER_DIR_APPLICATION_NAME, USER_DIR_ORGANIZATION_NAME,
USER_DIR_QUALIFIER,
},
output::{ErrorContext, Output, ResultContext},
};
Expand Down Expand Up @@ -104,8 +104,13 @@ impl Cli {
/// Returns a list of stack files, consisting of entries which are either a path or URL. The list of files combines
/// the default stack file URL, [`REMOTE_STACK_FILE`], files provided by the ENV variable [`ENV_KEY_STACK_FILES`],
/// and lastly, files provided by the CLI argument `--stack-file`.
pub fn get_stack_files(&self) -> Result<Vec<PathOrUrl>, PathOrUrlParseError> {
let mut files = get_files(REMOTE_STACK_FILE, ENV_KEY_STACK_FILES)?;
pub fn get_stack_files(&self, branch: &str) -> Result<Vec<PathOrUrl>, PathOrUrlParseError> {
let branch_url = format!(
"{base}/{branch}/stacks/stacks-v2.yaml",
base = DEMOS_REPOSITORY_URL_BASE
);

let mut files = get_files(&branch_url, ENV_KEY_STACK_FILES)?;

let arg_files = self.files.stack_files.clone().into_paths_or_urls()?;
files.extend(arg_files);
Expand Down
17 changes: 14 additions & 3 deletions rust/stackablectl/src/cmds/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,13 @@ impl DemoArgs {
.context(BuildListSnafu)?;

let release_branch = match &self.release {
Some(release) => format!("release-{release}"),
Some(release) => {
if release == "dev" {
"main".to_string()
} else {
format!("release-{release}")
}
}
None => {
let release = release_list
.inner()
Expand All @@ -196,7 +202,9 @@ impl DemoArgs {
match &self.subcommand {
DemoCommands::List(args) => list_cmd(args, cli, list).await,
DemoCommands::Describe(args) => describe_cmd(args, cli, list).await,
DemoCommands::Install(args) => install_cmd(args, cli, list, &transfer_client).await,
DemoCommands::Install(args) => {
install_cmd(args, cli, list, &transfer_client, &release_branch).await
}
}
}
}
Expand Down Expand Up @@ -308,6 +316,7 @@ async fn install_cmd(
cli: &Cli,
list: demo::List,
transfer_client: &xfer::Client,
release_branch: &str,
) -> Result<String, CmdError> {
info!("Installing demo {}", args.demo_name);

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

// TODO (Techassi): Try to move all this boilerplate code to build the lists out of here
let files = cli.get_stack_files().context(PathOrUrlParseSnafu)?;
let files = cli
.get_stack_files(release_branch)
.context(PathOrUrlParseSnafu)?;
let stack_list = stack::StackList::build(&files, transfer_client)
.await
.context(BuildListSnafu)?;
Expand Down
38 changes: 36 additions & 2 deletions rust/stackablectl/src/cmds/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use comfy_table::{
presets::{NOTHING, UTF8_FULL},
ContentArrangement, Table,
};
use snafu::{ResultExt, Snafu};
use snafu::{OptionExt, ResultExt, Snafu};
use stackable_operator::kvp::{LabelError, Labels};
use tracing::{debug, info, instrument};

Expand All @@ -30,6 +30,10 @@ use crate::{
pub struct StackArgs {
#[command(subcommand)]
subcommand: StackCommands,

/// Target a specific Stackable release
#[arg(long, global = true)]
release: Option<String>,
}

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

#[snafu(display("empty release list"))]
EmptyReleaseList,

#[snafu(display("failed to build stack/release list"))]
BuildList { source: list::Error },

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

let transfer_client = xfer::Client::new_with(cache);
let files = cli.get_stack_files().context(PathOrUrlParseSnafu)?;

let release_files = cli.get_release_files().context(PathOrUrlParseSnafu)?;
let release_list = release::ReleaseList::build(&release_files, &transfer_client)
.await
.context(BuildListSnafu)?;

let release_branch = match &self.release {
Some(release) => {
if release == "dev" {
"main".to_string()
} else {
format!("release-{release}")
}
}
None => {
let release = release_list
.inner()
.first()
.context(EmptyReleaseListSnafu)?
.0;

format!("release-{release}")
}
};

let files = cli
.get_stack_files(&release_branch)
.context(PathOrUrlParseSnafu)?;
let stack_list = stack::StackList::build(&files, &transfer_client)
.await
.context(BuildListSnafu)?;
Expand Down

0 comments on commit e7243f2

Please sign in to comment.