diff --git a/.github/workflows/clickhouse.yml b/.github/workflows/clickhouse.yml new file mode 100644 index 0000000..0813564 --- /dev/null +++ b/.github/workflows/clickhouse.yml @@ -0,0 +1,35 @@ +name: ci +on: + push: + branches: + - main + paths: + - clickhouse/** + - .github/workflows/clickhouse.yml +jobs: + clickhouse-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: clickhouse + env: + GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Start clickhouse server + run: | + fluentci run target/wasm32-unknown-unknown/release/clickhouse.wasm start + fluentci run target/wasm32-unknown-unknown/release/clickhouse.wasm stop + working-directory: clickhouse + 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 c7ed231..8f6d39d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,6 +58,16 @@ dependencies = [ "fluentci-types", ] +[[package]] +name = "clickhouse" +version = "0.1.0" +dependencies = [ + "anyhow", + "extism-pdk", + "fluentci-pdk", + "fluentci-types", +] + [[package]] name = "cockroachdb" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index edd1c08..81073ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ default-members = [ "apache", "caddy", + "clickhouse", "cockroachdb", "consul", "consul-template", @@ -34,6 +35,7 @@ default-members = [ members = [ "apache", "caddy", + "clickhouse", "cockroachdb", "consul", "consul-template", diff --git a/README.md b/README.md index 21b22c2..dcb2183 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ fluentci run --wasm postgres start |------------------------------|--------------------| | [apache](./apache) | A powerful and flexible HTTP/1.1 compliant web server | | [caddy](./caddy) | Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS | +| [clickhouse](./clickhouse) | An open-source column-oriented database management system | | [cockroachdb](./cockroachdb) | A distributed SQL database built on a transactional and strongly-consistent key-value store | | [consul](./consul) | A distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure | | [consul-template](./consul-template) | A tool for generating files based on Consul data | diff --git a/clickhouse/Cargo.toml b/clickhouse/Cargo.toml new file mode 100644 index 0000000..fe4a73f --- /dev/null +++ b/clickhouse/Cargo.toml @@ -0,0 +1,20 @@ +[package] +authors = [ + "Tsiry Sandratraina ", +] +description = "Clickhouse plugin for FluentCI" +edition = "2021" +license = "MIT" +name = "clickhouse" +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/clickhouse/LICENSE b/clickhouse/LICENSE new file mode 100644 index 0000000..515dd5f --- /dev/null +++ b/clickhouse/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/clickhouse/README.md b/clickhouse/README.md new file mode 100644 index 0000000..abf0ebc --- /dev/null +++ b/clickhouse/README.md @@ -0,0 +1,54 @@ +# Clickhouse Plugin + +[![fluentci pipeline](https://shield.fluentci.io/x/clickhouse)](https://pkg.fluentci.io/clickhouse) +[![ci](https://github.com/fluentci-io/services/actions/workflows/clickhouse.yml/badge.svg)](https://github.com/fluentci-io/services/actions/workflows/clickhouse.yml) + +Clickhouse service plugin for FluentCI. + +## 🚀 Usage + +Add the following command to your CI configuration file: + +```bash +fluentci run --wasm clickhouse start +``` + +## Functions + +| Name | Description | +| ------ | --------------------------------------------| +| start | Start Clickhouse server | +| stop | Stop Clickhouse 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/clickhouse@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: clickhouse + args: | + start +``` diff --git a/clickhouse/clickhouse-config.yaml.template b/clickhouse/clickhouse-config.yaml.template new file mode 100644 index 0000000..7fe499e --- /dev/null +++ b/clickhouse/clickhouse-config.yaml.template @@ -0,0 +1,14 @@ +logger: + level: warning + console: 1 +tcp_port: $CLICKHOUSE_PORT +http_port: $CLICKHOUSE_HTTP_PORT +default_profile: default +default_database: default +path: $CLICKHOUSE_DATADIR +tmp_path: $CLICKHOUSE_DATADIR/tmp +user_files_path: $CLICKHOUSE_DATADIR/user_files +format_schema_path: $CLICKHOUSE_DATADIR/format_schemas +user_directories: + users_xml: + path: $CLICKHOUSE_CONFIG_DIR/clickhouse-server/users.xml diff --git a/clickhouse/fluentci.toml b/clickhouse/fluentci.toml new file mode 100644 index 0000000..66fd03a --- /dev/null +++ b/clickhouse/fluentci.toml @@ -0,0 +1,11 @@ +[package] +authors = [ + "Tsiry Sandratraina ", +] +description = "Clickhouse Plugin for FluentCI" +keywords = [ + "clickhouse", +] +license = "MIT" +name = "clickhouse" +version = "0.1.0" diff --git a/clickhouse/src/helpers.rs b/clickhouse/src/helpers.rs new file mode 100644 index 0000000..d2d7e8d --- /dev/null +++ b/clickhouse/src/helpers.rs @@ -0,0 +1,73 @@ +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 { + setup_flox()?; + dag() + .pkgx()? + .with_exec(vec!["mkdir", "-p", ".fluentci/clickhouse"])? + .stdout()?; + + let clickhouse_port = dag().get_env("CLICKHOUSE_PORT")?; + let clickhouse_http_port = dag().get_env("CLICKHOUSE_HTTP_PORT")?; + let clickhouse_config = dag().get_env("CLICKHOUSE_CONFIG")?; + let data_dir = dag().get_env("CLICKHOUSE_DATADIR")?; + + if clickhouse_port.is_empty() { + dag().set_envs(vec![("CLICKHOUSE_PORT".into(), "9000".into())])?; + } + + if clickhouse_http_port.is_empty() { + dag().set_envs(vec![("CLICKHOUSE_HTTP_PORT".into(), "8123".into())])?; + } + + if clickhouse_config.is_empty() { + dag().set_envs(vec![( + "CLICKHOUSE_CONFIG".into(), + "../../clickhouse-config.yaml".into(), + )])?; + } + + if data_dir.is_empty() { + dag().set_envs(vec![( + "CLICKHOUSE_DATADIR".into(), + "../../clickhouse-data".into(), + )])?; + } + + let stdout = dag() + .flox()? + .with_workdir(".fluentci/clickhouse")? + .with_exec(vec![ + "[ -d $CLICKHOUSE_DATADIR ] || mkdir -p $CLICKHOUSE_DATADIR", + ])? + .with_exec(vec![ + "flox", + "install", + "clickhouse", + "overmind", + "tmux", + ])? + .with_exec(vec!["[ -f clickhouse-config.yaml.template ] || pkgx wget https://raw.githubusercontent.com/fluentci-io/services/main/clickhouse/clickhouse-config.yaml.template"])? + .with_exec(vec![ + "CLICKHOUSE_CONFIG_DIR=$(ls -d .flox/run/*/etc); ", + "[ -f $CLICKHOUSE_CONFIG ] || pkgx envsubst < clickhouse-config.yaml.template > $CLICKHOUSE_CONFIG "])? + .with_exec(vec![ + "grep -q clickhouse: Procfile || echo -e 'clickhouse: clickhouse-server --config-file=$CLICKHOUSE_CONFIG \\n' >> Procfile", + ])? + .stdout()?; + + Ok(stdout) +} diff --git a/clickhouse/src/lib.rs b/clickhouse/src/lib.rs new file mode 100644 index 0000000..88c4e50 --- /dev/null +++ b/clickhouse/src/lib.rs @@ -0,0 +1,49 @@ +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("CLICKHOUSE_PORT")?; + let http_port = dag().get_env("CLICKHOUSE_HTTP_PORT")?; + + let stdout = dag() + .flox()? + .with_workdir(".fluentci/clickhouse")? + .with_exec(vec!["overmind", "--version"])? + .with_exec(vec!["type", "overmind"])? + .with_exec(vec!["type", "clickhouse-server"])? + .with_exec(vec!["clickhouse-server", "--version"])? + .with_exec(vec![ + "echo -e \"Clickhouse starting on port $CLICKHOUSE_PORT\"", + ])? + .with_exec(vec![ + "overmind start -f Procfile --daemonize || flox activate -- overmind restart clickhouse", + ])? + .wait_on(port.parse()?, None)? + .wait_on(http_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() { + "clickhouse".to_string() + } else { + args + }; + + let stdout = dag() + .flox()? + .with_workdir(".fluentci/clickhouse")? + .with_exec(vec!["overmind", "stop", &args])? + .stdout()?; + Ok(stdout) +} diff --git a/clickhouse/target b/clickhouse/target new file mode 120000 index 0000000..78bc337 --- /dev/null +++ b/clickhouse/target @@ -0,0 +1 @@ +../target \ No newline at end of file diff --git a/cockroachdb/README.md b/cockroachdb/README.md index 2c6af58..9b77e82 100644 --- a/cockroachdb/README.md +++ b/cockroachdb/README.md @@ -10,7 +10,7 @@ CockroachDB service plugin for FluentCI. Add the following command to your CI configuration file: ```bash -fluentci run --wasm memcached start +fluentci run --wasm cockroachdb start ``` ## Functions