Skip to content

Commit

Permalink
feat: add redis service
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Jul 10, 2024
1 parent bed8d20 commit d1606a5
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/apache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ on:
push:
branches:
- main
paths:
- apache/**
jobs:
apache-test:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/duckdb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ on:
push:
branches:
- main
paths:
- duckdb/**
jobs:
duckdb-test:
runs-on: ubuntu-latest
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/redis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: ci
on:
push:
branches:
- main
paths:
- redis/**
jobs:
redis-test:
runs-on: ubuntu-latest
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: redis
env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Start Redis
run: |
fluentci run target/wasm32-unknown-unknown/release/redis.wasm start
fluentci run target/wasm32-unknown-unknown/release/redis.wasm stop redis
working-directory: redis
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.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[workspace]
default-members = ["apache", "duckdb"]
members = ["apache", "duckdb"]
default-members = ["apache", "duckdb", "redis"]
members = ["apache", "duckdb", "redis"]
resolver = "2"
2 changes: 1 addition & 1 deletion duckdb/fluentci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ keywords = [
"duckdb",
]
license = "MIT"
name = "apache"
name = "duckdb"
version = "0.1.0"
20 changes: 20 additions & 0 deletions redis/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
authors = [
"Tsiry Sandratraina <[email protected]>",
]
description = "Redis plugin for FluentCI"
edition = "2021"
license = "MIT"
name = "redis"
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 redis/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2024 Tsiry Sandratraina <[email protected]>

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

[![ci](https://github.com/fluentci-io/services/actions/workflows/redis.yml/badge.svg)](https://github.com/fluentci-io/services/actions/workflows/redis.yml)

Redis service plugin for FluentCI.

## 🚀 Usage

Add the following command to your CI configuration file:

```bash
fluentci run --wasm redis start
```

## Functions

| Name | Description |
| ------ | -------------------------------------------------- |
| start | Start Redis server |
| stop | Stop Redis 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/[email protected]?wasm=1", "start", vec![])?;
```

## 📚 Examples

Github Actions:

```yaml
- name: Setup Fluent CI CLI
uses: fluentci-io/setup-fluentci@v5
with:
wasm: true
plugin: redis
args: |
start
```
11 changes: 11 additions & 0 deletions redis/fluentci.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
authors = [
"Tsiry Sandratraina <[email protected]>",
]
description = "Redis Plugin for FluentCI"
keywords = [
"redis",
]
license = "MIT"
name = "redis"
version = "0.1.0"
20 changes: 20 additions & 0 deletions redis/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use anyhow::Error;
use fluentci_pdk::dag;

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

let stdout = dag()
.flox()?
.with_workdir(".fluentci")?
.with_exec(vec!["flox", "install", "redis", "overmind", "tmux"])?
.with_exec(vec![
"grep -q redis Procfile || echo 'redis: redis >> Procfile",
])?
.stdout()?;

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

pub mod helpers;

#[plugin_fn]
pub fn start(_args: String) -> FnResult<String> {
helpers::setup()?;
let stdout = dag()
.flox()?
.with_workdir(".fluentci")?
.with_exec(vec!["overmind", "--version"])?
.with_exec(vec!["redis-server", "--version"])?
.with_exec(vec!["type", "overmind"])?
.with_exec(vec!["type", "redis-server"])?
.with_exec(vec!["overmind", "start", "-f", "Procfile", "--daemonize"])?
.with_exec(vec!["overmind", "status"])?
.stdout()?;
Ok(stdout)
}

#[plugin_fn]
pub fn stop(args: String) -> FnResult<String> {
helpers::setup()?;
let stdout = dag()
.flox()?
.with_workdir(".fluentci")?
.with_exec(vec!["overmind", "stop", &args])?
.stdout()?;
Ok(stdout)
}
1 change: 1 addition & 0 deletions redis/target

0 comments on commit d1606a5

Please sign in to comment.