Skip to content

Commit

Permalink
feat: add rethinkdb service
Browse files Browse the repository at this point in the history
feat: add rethinkdb service

feat: add rethinkdb service

feat: add rethinkdb service

feat: add rethinkdb service

feat: add rethinkdb service

feat: add rethinkdb service
  • Loading branch information
tsirysndr committed Jul 20, 2024
1 parent 5d50119 commit d536b99
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/rethinkdb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: ci
on:
push:
branches:
- main
paths:
- rethinkdb/**
- .github/workflows/rethinkdb.yml
jobs:
rethinkdb-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: rethinkdb
env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Start rethinkdb
run: |
fluentci run target/wasm32-unknown-unknown/release/rethinkdb.wasm start
fluentci run target/wasm32-unknown-unknown/release/rethinkdb.wasm stop
working-directory: rethinkdb
env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NIX_CONFIG: extra-access-tokens = github.com=${{ secrets.GH_ACCESS_TOKEN }}
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ default-members = [
"quickwit",
"rabbitmq",
"redis",
"rethinkdb",
"stripe-mock",
"temporal",
"tidb",
Expand Down Expand Up @@ -67,6 +68,7 @@ members = [
"quickwit",
"rabbitmq",
"redis",
"rethinkdb",
"stripe-mock",
"temporal",
"tidb",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ fluentci run --wasm postgres start
| [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 |
| [rethinkdb](./rethinkdb) | An open-source, distributed database built with love |
| [stripe-mock](./stripe-mock/) | A mock HTTP server that responds like the real Stripe API. |
| [temporal](./temporal) | A distributed, scalable, durable, and highly available orchestration engine |
| [tidb](./tidb) | A distributed SQL database |
Expand Down
20 changes: 20 additions & 0 deletions rethinkdb/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
authors = [
"Tsiry Sandratraina <tsiry.sndr@fluentci.io>",
]
description = "RethinkDB plugin for FluentCI"
edition = "2021"
license = "MIT"
name = "rethinkdb"
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"
19 changes: 19 additions & 0 deletions rethinkdb/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2024 Tsiry Sandratraina <tsiry.sndr@fluentci.io>

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.
54 changes: 54 additions & 0 deletions rethinkdb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# RethinkDB Plugin

[![fluentci pipeline](https://shield.fluentci.io/x/rethinkdb)](https://pkg.fluentci.io/rethinkdb)
[![ci](https://github.com/fluentci-io/services/actions/workflows/rethinkdb.yml/badge.svg)](https://github.com/fluentci-io/services/actions/workflows/rethinkdb.yml)

RethinkDB service plugin for FluentCI.

## 🚀 Usage

Add the following command to your CI configuration file:

```bash
fluentci run --wasm rethinkdb start
```

## Functions

| Name | Description |
| ------ | ------------------------------------- |
| start | Start RethinkDB |
| stop | Stop RethinkDB |

## 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/rethinkdb@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: rethinkdb
args: |
start
```
11 changes: 11 additions & 0 deletions rethinkdb/fluentci.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
authors = [
"Tsiry Sandratraina <tsiry.sndr@fluentci.io>",
]
description = "RethinkDB Plugin for FluentCI"
keywords = [
"rethinkdb",
]
license = "MIT"
name = "rethinkdb"
version = "0.1.0"
64 changes: 64 additions & 0 deletions rethinkdb/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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/rethinkdb"])?
.stdout()?;

let pwd = dag().get_env("PWD")?;
let rethinkdb_port = dag().get_env("RETHINKDB_PORT")?;
let rethinkdb_http_port = dag().get_env("RETHINKDB_HTTP_PORT")?;
let cluster_port = dag().get_env("RETHINKDB_CLUSTER_PORT")?;
let data_dir = dag().get_env("RETHINKDB_DATADIR")?;

if rethinkdb_port.is_empty() {
dag().set_envs(vec![("RETHINKDB_PORT".into(), "28015".into())])?;
}

if rethinkdb_http_port.is_empty() {
dag().set_envs(vec![("RETHINKDB_HTTP_PORT".into(), "8080".into())])?;
}

if cluster_port.is_empty() {
dag().set_envs(vec![("RETHINKDB_CLUSTER_PORT".into(), "29015".into())])?;
}

if data_dir.is_empty() {
dag().set_envs(vec![(
"RETHINKDB_DATADIR".into(),
format!("{}/rethinkdb-data", pwd),
)])?;
}

let stdout = dag()
.flox()?
.with_workdir(".fluentci/rethinkdb")?
.with_exec(vec![
"flox",
"install",
"rethinkdb",
"overmind",
"tmux",
])?
.with_exec(vec![
"grep -q rethinkdb: Procfile || echo -e 'rethinkdb: rethinkdb --driver-port $RETHINKDB_PORT --directory $RETHINKDB_DATADIR --http-port $RETHINKDB_HTTP_PORT --cluster-port $RETHINKDB_CLUSTER_PORT $RETHINKDB_ARGS \\n' >> Procfile",
])?
.stdout()?;

Ok(stdout)
}
47 changes: 47 additions & 0 deletions rethinkdb/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use extism_pdk::*;
use fluentci_pdk::dag;

pub mod helpers;

#[plugin_fn]
pub fn start(_args: String) -> FnResult<String> {
helpers::setup()?;

let port = dag().get_env("RETHINKDB_PORT")?;

let stdout = dag()
.flox()?
.with_workdir(".fluentci/rethinkdb")?
.with_exec(vec!["overmind", "--version"])?
.with_exec(vec!["type", "overmind"])?
.with_exec(vec!["type", "rethinkdb"])?
.with_exec(vec!["rethinkdb", "--version"])?
.with_exec(vec![
"echo -e \"RethinkDB starting on port $RETHINKDB_PORT\"",
])?
.with_exec(vec![
"overmind start -f Procfile --daemonize || flox activate -- overmind restart rethinkdb",
])?
.wait_on(port.parse()?, None)?
.with_exec(vec!["overmind", "status"])?
.stdout()?;
Ok(stdout)
}

#[plugin_fn]
pub fn stop(args: String) -> FnResult<String> {
helpers::setup()?;

let args = if args.is_empty() {
"rethinkdb".to_string()
} else {
args
};

let stdout = dag()
.flox()?
.with_workdir(".fluentci/rethinkdb")?
.with_exec(vec!["overmind", "stop", &args])?
.stdout()?;
Ok(stdout)
}
1 change: 1 addition & 0 deletions rethinkdb/target

0 comments on commit d536b99

Please sign in to comment.