Skip to content

Commit

Permalink
fix(influxdb): use pkgx instead of flox
Browse files Browse the repository at this point in the history
feat(influxdb): use pkgx instead of flox
  • Loading branch information
tsirysndr committed Jul 21, 2024
1 parent 1beeddb commit 1fadb59
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 28 deletions.
75 changes: 49 additions & 26 deletions influxdb/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,76 @@
use anyhow::Error;
use fluentci_pdk::dag;

pub fn setup_flox() -> Result<(), Error> {
pub fn install_influxdb() -> Result<(), Error> {
let os = dag().get_os()?;
if os == "macos" {
dag()
.pipeline("setup-flox")?
.with_exec(vec![r#"type brew > /dev/null 2> /dev/null || /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)""#])?
.with_exec(vec!["type flox > /dev/null 2> /dev/null || brew install flox"])?
.stdout()?;
let arch = dag().get_arch()?;

let os = match os.as_str() {
"linux" => "linux",
"macos" => "darwin",
_ => &os,
};
let arch = match arch.as_str() {
"x86_64" => "amd64",
"aarch64" => "arm64",
_ => &arch,
};

dag().set_envs(vec![("OS".into(), os.into()), ("ARCH".into(), arch.into())])?;

let version = dag().get_env("INFLUXDB_VERSION")?;
if version.is_empty() {
dag().set_envs(vec![("INFLUXDB_VERSION".into(), "2-2.7.7".into())])?;
}

let path = dag().get_env("PATH")?;
let home = dag().get_env("HOME")?;
dag().set_envs(vec![
("PATH".into(), format!("$HOME/.local/bin:{}", path)),
("HOME".into(), home),
])?;

dag()
.pkgx()?
.with_exec(vec!["mkdir", "-p", "$HOME/.local/bin"])?
.with_exec(vec!["type influxd > /dev/null 2> /dev/null || pkgx wget https://dl.influxdata.com/influxdb/releases/influxdb$INFLUXDB_VERSION_$OS_$ARCH.tar.gz"])?
.with_exec(vec!["type influxd > /dev/null 2> /dev/null || pkgx tar -xvzf influxdb$INFLUXDB_VERSION_$OS_$ARCH.tar.gz"])?
.with_exec(vec!["type influxd > /dev/null 2> /dev/null || cp influxdb$INFLUXDB_VERSION/usr/bin/influxd $HOME/.local/bin || true"])?
.with_exec(vec!["type influxd > /dev/null 2> /dev/null || cp influxdb$INFLUXDB_VERSION/influxd $HOME/.local/bin || true"])?
.with_exec(vec![
"[ -d influxdb$INFLUXDB_VERSION ] && ",
"rm",
"-rf",
"influxdb$INFLUXDB_VERSION*",
" || true",
])?
.stdout()?;
Ok(())
}

pub fn setup() -> Result<String, Error> {
setup_flox()?;
install_influxdb()?;

dag()
.pipeline("setup")?
.with_exec(vec!["mkdir", "-p", ".fluentci/influxdb"])?
.stdout()?;

let pwd = dag().get_env("PWD")?;
let influxdb_port = dag().get_env("INFLUXDB_PORT")?;
let influxdb_config = dag().get_env("INFLUXDB_CONFIG")?;

if influxdb_port.is_empty() {
dag().set_envs(vec![("INFLUXDB_PORT".into(), "8086".into())])?;
}

if influxdb_config.is_empty() {
dag().set_envs(vec![(
"INFLUXDB_CONFIG".into(),
format!("{}/influxdb.conf", pwd),
)])?;
}

let stdout = dag()
.flox()?
.pkgx()?
.with_workdir(".fluentci/influxdb")?
.with_exec(vec![
"flox",
"install",
"influxdb",
"overmind",
"tmux",
.with_packages(vec![
"github.com/darthsim/overmind",
"github.com/tmux/tmux",
])?
.with_exec(vec!["[ -f $INFLUXDB_CONFIG ] || touch $INFLUXDB_CONFIG"])?
.with_exec(vec![
"grep -q influxdb: Procfile || echo -e 'influxdb: influxd -config $INFLUXDB_CONFIG --http-bind-address $INFLUXDB_PORT \\n' >> Procfile",
"grep -q influxdb: Procfile || echo -e 'influxdb: influxd --http-bind-address $INFLUXDB_PORT $INFLUXDB_ARGS \\n' >> Procfile",
])?
.stdout()?;

Expand Down
4 changes: 2 additions & 2 deletions influxdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn start(_args: String) -> FnResult<String> {
let port = dag().get_env("INFLUXDB_PORT")?;

let stdout = dag()
.flox()?
.pkgx()?
.with_workdir(".fluentci/influxdb")?
.with_exec(vec!["overmind", "--version"])?
.with_exec(vec!["type", "overmind"])?
Expand All @@ -37,7 +37,7 @@ pub fn stop(args: String) -> FnResult<String> {
};

let stdout = dag()
.flox()?
.pkgx()?
.with_workdir(".fluentci/influxdb")?
.with_exec(vec!["overmind", "stop", &args])?
.stdout()?;
Expand Down

0 comments on commit 1fadb59

Please sign in to comment.