Skip to content

Commit

Permalink
feat(consul): use pkgx instead of flox
Browse files Browse the repository at this point in the history
feat(consul): use pkgx instead of flox

feat(consul): use pkgx instead of flox
  • Loading branch information
tsirysndr committed Jul 16, 2024
1 parent 6d52a4e commit c481548
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/consul.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
consul-test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-12]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/envconsul.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
envconsul-test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-12]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down
34 changes: 12 additions & 22 deletions consul/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
use anyhow::Error;
use fluentci_pdk::dag;

pub fn setup_flox() -> 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()?;
}
Ok(())
}

pub fn setup() -> Result<String, Error> {
setup_flox()?;
dag()
.pipeline("setup")?
.with_exec(vec!["mkdir", "-p", ".fluentci"])?
.with_exec(vec!["mkdir", "-p", ".fluentci/consul"])?
.stdout()?;

let consul_config = dag().get_env("CONSUL_CONFIG")?;
Expand All @@ -30,7 +17,7 @@ pub fn setup() -> Result<String, Error> {
}

if consul_data_dir.is_empty() {
dag().set_envs(vec![("CONSUL_DATA_DIR".into(), "../consul-data".into())])?;
dag().set_envs(vec![("CONSUL_DATA_DIR".into(), "../../consul-data".into())])?;
}

if consul_bind_addr.is_empty() {
Expand All @@ -40,18 +27,21 @@ pub fn setup() -> Result<String, Error> {
if consul_config.is_empty() {
dag().set_envs(vec![(
"CONSUL_CONFIG".into(),
"../consul-config.json".into(),
"../../consul-config.json".into(),
)])?;
}

let stdout = dag()
.flox()?
.with_workdir(".fluentci")?
.with_exec(vec![
"flox", "install", "consul", "overmind", "tmux", "wget", "gettext"
.pkgx()?
.with_workdir(".fluentci/consul")?
.with_packages(vec![
"consul.io",
"hashicorp.com/envconsul",
"github.com/darthsim/overmind",
"github.com/tmux/tmux",
])?
.with_exec(vec!["[ -f consul-config.json.template ] || flox activate -- wget https://raw.githubusercontent.com/fluentci-io/services/main/consul/consul-config.json.template"])?
.with_exec(vec!["[ -f $CONSUL_CONFIG ] || flox activate -- sh -c \"envsubst < consul-config.json.template\" > $CONSUL_CONFIG "])?
.with_exec(vec!["[ -f consul-config.json.template ] || pkgx wget https://raw.githubusercontent.com/fluentci-io/services/main/consul/consul-config.json.template"])?
.with_exec(vec!["[ -f $CONSUL_CONFIG ] || pkgx envsubst < consul-config.json.template > $CONSUL_CONFIG "])?
.with_exec(vec![
"grep -q consul: Procfile || echo -e 'consul: consul agent -config-file=$CONSUL_CONFIG \\n' >> Procfile",
])?
Expand Down
10 changes: 5 additions & 5 deletions consul/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ pub fn start(_args: String) -> FnResult<String> {
let port = dag().get_env("CONSUL_HTTP_PORT")?;

let stdout = dag()
.flox()?
.with_workdir(".fluentci")?
.pkgx()?
.with_workdir(".fluentci/consul")?
.with_exec(vec!["overmind", "--version"])?
.with_exec(vec!["consul", "version"])?
.with_exec(vec!["type", "overmind"])?
.with_exec(vec!["type", "consul"])?
.with_exec(vec![
"overmind start -f Procfile --daemonize || flox activate -- overmind restart consul",
"overmind start -f Procfile --daemonize || overmind restart consul",
])?
.wait_on(port.parse()?, None)?
.with_exec(vec!["overmind", "status"])?
Expand All @@ -39,8 +39,8 @@ pub fn stop(args: String) -> FnResult<String> {
};

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

0 comments on commit c481548

Please sign in to comment.