diff --git a/.github/workflows/quickwit.yml b/.github/workflows/quickwit.yml new file mode 100644 index 0000000..d1532dc --- /dev/null +++ b/.github/workflows/quickwit.yml @@ -0,0 +1,35 @@ +name: ci +on: + push: + branches: + - main + paths: + - quickwit/** + - .github/workflows/quickwit.yml +jobs: + quickwit-test: + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + - name: Setup Fluent CI + uses: fluentci-io/setup-fluentci@v5 + with: + wasm: true + plugin: rust + args: | + target_add wasm32-unknown-unknown + build --release --target wasm32-unknown-unknown + working-directory: quickwit + env: + GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Start quickwit Server + run: | + fluentci run target/wasm32-unknown-unknown/release/quickwit.wasm start + fluentci run target/wasm32-unknown-unknown/release/quickwit.wasm stop + working-directory: quickwit + env: + GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NIX_CONFIG: extra-access-tokens = github.com=${{ secrets.GH_ACCESS_TOKEN }} diff --git a/Cargo.lock b/Cargo.lock index 61fab32..448c295 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -524,6 +524,16 @@ dependencies = [ "syn", ] +[[package]] +name = "quickwit" +version = "0.1.0" +dependencies = [ + "anyhow", + "extism-pdk", + "fluentci-pdk", + "fluentci-types", +] + [[package]] name = "quote" version = "1.0.36" diff --git a/Cargo.toml b/Cargo.toml index 691c034..ed5e499 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ default-members = [ "nsq", "php", "postgres", + "quickwit", "rabbitmq", "redis", "stripe-mock", @@ -60,6 +61,7 @@ members = [ "nsq", "php", "postgres", + "quickwit", "rabbitmq", "redis", "stripe-mock", diff --git a/README.md b/README.md index dd6d0b1..6340d40 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ fluentci run --wasm postgres start | [nsq](./nsq) | A realtime distributed messaging platform | | [postgres](./postgres) | A database management system that is object-relational | | [php-fpm](./php) | PHP FastCGI Process Manager | +| [quickwit](./quickwit) | A distributed search engine | | [rabbitmq](./rabbitmq) | An open source multi-protocol messaging broker | | [redis](./redis) | An in-memory database that persists on disk | | [stripe-mock](./stripe-mock/) | A mock HTTP server that responds like the real Stripe API. | diff --git a/quickwit/Cargo.toml b/quickwit/Cargo.toml new file mode 100644 index 0000000..fa00970 --- /dev/null +++ b/quickwit/Cargo.toml @@ -0,0 +1,20 @@ +[package] +authors = [ + "Tsiry Sandratraina ", +] +description = "Quickwit plugin for FluentCI" +edition = "2021" +license = "MIT" +name = "quickwit" +version = "0.1.0" + +[lib] +crate-type = [ + "cdylib", +] + +[dependencies] +anyhow = "1.0.82" +extism-pdk = "1.1.0" +fluentci-pdk = "0.2.1" +fluentci-types = "0.1.7" diff --git a/quickwit/LICENSE b/quickwit/LICENSE new file mode 100644 index 0000000..515dd5f --- /dev/null +++ b/quickwit/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2024 Tsiry Sandratraina + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/quickwit/README.md b/quickwit/README.md new file mode 100644 index 0000000..aaed1f8 --- /dev/null +++ b/quickwit/README.md @@ -0,0 +1,54 @@ +# Quickwit Plugin + +[![fluentci pipeline](https://shield.fluentci.io/x/quickwit)](https://pkg.fluentci.io/quickwit) +[![ci](https://github.com/fluentci-io/services/actions/workflows/quickwit.yml/badge.svg)](https://github.com/fluentci-io/services/actions/workflows/quickwit.yml) + +Quickwit service plugin for FluentCI. + +## 🚀 Usage + +Add the following command to your CI configuration file: + +```bash +fluentci run --wasm quickwit start +``` + +## Functions + +| Name | Description | +| ------ | -------------------------------------------------- | +| start | Start quickwit server | +| stop | Stop quickwit server | + +## Code Usage + +Add `fluentci-pdk` crate to your `Cargo.toml`: + +```toml +[dependencies] +fluentci-pdk = "0.2.1" +``` + +Use the following code to call the plugin: + +```rust +use fluentci_pdk::dag; + +// ... + +dag().call("https://pkg.fluentci.io/quickwit@v0.1.0?wasm=1", "start", vec![])?; +``` + +## 📚 Examples + +Github Actions: + +```yaml +- name: Setup Fluent CI CLI + uses: fluentci-io/setup-fluentci@v5 + with: + wasm: true + plugin: quickwit + args: | + start +``` diff --git a/quickwit/fluentci.toml b/quickwit/fluentci.toml new file mode 100644 index 0000000..54803ff --- /dev/null +++ b/quickwit/fluentci.toml @@ -0,0 +1,11 @@ +[package] +authors = [ + "Tsiry Sandratraina ", +] +description = "Quickwit Plugin for FluentCI" +keywords = [ + "redis", +] +license = "MIT" +name = "quickwit" +version = "0.1.0" diff --git a/quickwit/quickwit.yaml.template b/quickwit/quickwit.yaml.template new file mode 100644 index 0000000..4923dd3 --- /dev/null +++ b/quickwit/quickwit.yaml.template @@ -0,0 +1,3 @@ +version: 0.8 +rest: + listen_port: $QUICKWIT_PORT \ No newline at end of file diff --git a/quickwit/src/helpers.rs b/quickwit/src/helpers.rs new file mode 100644 index 0000000..758d092 --- /dev/null +++ b/quickwit/src/helpers.rs @@ -0,0 +1,77 @@ +use anyhow::Error; +use fluentci_pdk::dag; + +pub fn setup() -> Result { + let path = dag().get_env("PATH")?; + let home = dag().get_env("HOME")?; + dag().set_envs(vec![( + "PATH".into(), + format!("{}/.local/bin:{}", home, path), + )])?; + + let os = dag().get_os()?; + let arch = dag().get_arch()?; + + let os = match os.as_str() { + "linux" => "unknown-linux-gnu", + "macos" => "apple-darwin", + _ => &os, + }; + + dag().set_envs(vec![("OS".into(), os.into()), ("ARCH".into(), arch.into())])?; + + let version = dag().get_env("QUICKWIT_VERSION")?; + if version.is_empty() { + dag().set_envs(vec![("QUICKWIT_VERSION".into(), "v0.8.2".into())])?; + } + + dag() + .pkgx()? + .with_exec(vec!["mkdir", "-p", ".fluentci/quickwit", "$HOME/.local/bin"])? + .with_exec(vec!["type quickwit || pkgx wget https://github.com/quickwit-oss/quickwit/releases/download/$QUICKWIT_VERSION/quickwit-$QUICKWIT_VERSION-$ARCH-$OS.tar.gz"])? + .with_exec(vec!["type quickwit || pkgx tar -xvzf quickwit-$QUICKWIT_VERSION-$ARCH-$OS.tar.gz"])? + .with_exec(vec!["type quickwit || cp quickwit-$QUICKWIT_VERSION/quickwit $HOME/.local/bin"])? + .with_exec(vec!["[ -d quickwit-$QUICKWIT_VERSION ] && rm -rf quickwit-$QUICKWIT_VERSION* || true"])? + .stdout()?; + + let pwd = dag().get_env("PWD")?; + let quick_port = dag().get_env("QUICKWIT_PORT")?; + let data_dir = dag().get_env("QUICKWIT_DATA_DIR")?; + let quickwit_config = dag().get_env("QUICKWIT_CONFIG")?; + + if quick_port.is_empty() { + dag().set_envs(vec![("QUICKWIT_PORT".into(), "7280".into())])?; + } + + if data_dir.is_empty() { + dag().set_envs(vec![( + "QUICKWIT_DATA_DIR".into(), + format!("{}/qwdata", pwd), + )])?; + } + + if quickwit_config.is_empty() { + dag().set_envs(vec![( + "QUICKWIT_CONFIG".into(), + format!("{}/config/quickwit.yaml", pwd), + )])?; + } + + let stdout = dag() + .pkgx()? + .with_workdir(".fluentci/quickwit")? + .with_packages(vec![ + "github.com/darthsim/overmind", + "github.com/tmux/tmux", + ])? + .with_exec(vec!["mkdir -p $QUICKWIT_DATA_DIR"])? + .with_exec(vec!["mkdir -p ../../config"])? + .with_exec(vec!["[ -f quickwit.yaml.template ] || pkgx wget https://raw.githubusercontent.com/fluentci-io/services/main/quickwit/quickwit.yaml.template"])? + .with_exec(vec!["[ -f $QUICKWIT_CONFIG ] || pkgx envsubst < quickwit.yaml.template > $QUICKWIT_CONFIG "])? + .with_exec(vec![ + "grep -q quickwit: Procfile || echo -e 'quickwit: cd ../.. && quickwit run \\n' >> Procfile", + ])? + .stdout()?; + + Ok(stdout) +} diff --git a/quickwit/src/lib.rs b/quickwit/src/lib.rs new file mode 100644 index 0000000..19d267c --- /dev/null +++ b/quickwit/src/lib.rs @@ -0,0 +1,44 @@ +use extism_pdk::*; +use fluentci_pdk::dag; + +pub mod helpers; + +#[plugin_fn] +pub fn start(_args: String) -> FnResult { + helpers::setup()?; + + let port = dag().get_env("QUICKWIT_PORT")?; + + let stdout = dag() + .pkgx()? + .with_workdir(".fluentci/quickwit")? + .with_exec(vec!["overmind", "--version"])? + .with_exec(vec!["quickwit", "--version"])? + .with_exec(vec!["type", "overmind"])? + .with_exec(vec!["type", "quickwit"])? + .with_exec(vec![ + "overmind start -f Procfile --daemonize || overmind restart quickwit", + ])? + .wait_on(port.parse()?, None)? + .with_exec(vec!["overmind", "status"])? + .stdout()?; + Ok(stdout) +} + +#[plugin_fn] +pub fn stop(args: String) -> FnResult { + helpers::setup()?; + + let args = if args.is_empty() { + "quickwit".to_string() + } else { + args + }; + + let stdout = dag() + .pkgx()? + .with_workdir(".fluentci/quickwit")? + .with_exec(vec!["overmind", "stop", &args])? + .stdout()?; + Ok(stdout) +} diff --git a/quickwit/target b/quickwit/target new file mode 120000 index 0000000..78bc337 --- /dev/null +++ b/quickwit/target @@ -0,0 +1 @@ +../target \ No newline at end of file