Skip to content

Commit

Permalink
feat: add cassandra service
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Jul 20, 2024
1 parent 332a361 commit a42c6a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions cassandra/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub fn setup() -> Result<String, Error> {
let pwd = dag().get_env("PWD")?;
let cassandra_port = dag().get_env("CASSANDRA_PORT")?;
let data_dir = dag().get_env("CASSANDRA_DATADIR")?;
let cluster_name = dag().get_env("CASSANDRA_CLUSTER_NAME")?;

if cassandra_port.is_empty() {
dag().set_envs(vec![("CASSANDRA_PORT".into(), "7000".into())])?;
Expand All @@ -37,17 +38,31 @@ pub fn setup() -> Result<String, Error> {
)])?;
}

if cluster_name.is_empty() {
dag().set_envs(vec![(
"CASSANDRA_CLUSTER_NAME".into(),
"Test Cluster".into(),
)])?;
}

dag().set_envs(vec![(
"CASSANDRA_CONFIG".into(),
format!("{}/cassandra.yaml", pwd),
)])?;

let data_dir = dag().get_env("CASSANDRA_DATADIR")?;
dag().set_envs(vec![(
"CASSANDRA_LOG_DIR".into(),
format!("{}/logs", data_dir),
)])?;

let stdout = dag()
.flox()?
.with_workdir(".fluentci/cassandra")?
.with_exec(vec![
"[ -d $CASSANDRA_DATADIR ] || mkdir -p $CASSANDRA_DATADIR",
])?
.with_exec(vec!["mkdir", "-p", "$CASSANDRA_LOG_DIR"])?
.with_exec(vec!["flox", "install", "cassandra_4", "overmind", "tmux"])?
.with_exec(vec!["[ -f cassandra.yaml.template ] || pkgx wget https://raw.githubusercontent.com/fluentci-io/services/main/cassandra/cassandra.yaml.template"])?
.with_exec(vec!["[ -f $CASSANDRA_CONFIG ] || pkgx envsubst < cassandra.yaml.template > $CASSANDRA_CONFIG "])?
Expand Down
2 changes: 1 addition & 1 deletion cassandra/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn start(_args: String) -> FnResult<String> {
"echo -e \"Cassandra starting on port $CASSANDRA_PORT\"",
])?
.with_exec(vec![
"overmind start -f Procfile --daemonize || flox activate -- overmind restart cassandra",
"overmind start -f Procfile || flox activate -- overmind restart cassandra",
])?
.wait_on(port.parse()?, None)?
.with_exec(vec!["overmind", "status"])?
Expand Down

0 comments on commit a42c6a7

Please sign in to comment.