Skip to content

Commit

Permalink
feat: add MariaDB service
Browse files Browse the repository at this point in the history
fix typo

install mariadb package
  • Loading branch information
tsirysndr committed Jul 12, 2024
1 parent 52061a1 commit 084a998
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 2 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/mariadb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: ci
on:
push:
branches:
- main
paths:
- mariadb/**
- .github/workflows/mariadb.yml
jobs:
mariadb-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: mariadb
env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Start MariaDB Server
run: |
fluentci run target/wasm32-unknown-unknown/release/mariadb.wasm start
fluentci run target/wasm32-unknown-unknown/release/mariadb.wasm stop mariadb
working-directory: mariadb
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.

24 changes: 22 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
[workspace]
default-members = ["apache", "redis", "dragonflydb", "nginx", "caddy", "httpbin", "php", "mysql"]
members = ["apache", "redis", "dragonflydb", "nginx", "caddy", "httpbin", "php", "mysql"]
default-members = [
"apache",
"redis",
"dragonflydb",
"nginx",
"caddy",
"httpbin",
"php",
"mysql",
"mariadb",
]
members = [
"apache",
"redis",
"dragonflydb",
"nginx",
"caddy",
"httpbin",
"php",
"mysql",
"mariadb",
]
resolver = "2"
20 changes: 20 additions & 0 deletions mariadb/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 = "MariaDB plugin for FluentCI"
edition = "2021"
license = "MIT"
name = "mariadb"
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 mariadb/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.
53 changes: 53 additions & 0 deletions mariadb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# MariaDB Plugin

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

MariaDB service plugin for FluentCI.

## 🚀 Usage

Add the following command to your CI configuration file:

```bash
fluentci run --wasm mariadb start
```

## Functions

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

## 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/mariadb@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: mariadb
args: |
start
```
11 changes: 11 additions & 0 deletions mariadb/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 = "MariaDB Plugin for FluentCI"
keywords = [
"mariadb",
]
license = "MIT"
name = "mariadb"
version = "0.1.0"
57 changes: 57 additions & 0 deletions mariadb/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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"])?
.stdout()?;

let pwd = dag().get_env("PWD")?;
let mysql_home = dag().get_env("MYSQL_HOME")?;
let mysql_data_dir = dag().get_env("MYSQL_DATADIR")?;
let mysql_port = dag().get_env("MYSQL_PORT")?;

if mysql_home.is_empty() {
dag().set_envs(vec![("MYSQL_HOME".into(), format!("{}/mysql", pwd))])?;
}

if mysql_data_dir.is_empty() {
dag().set_envs(vec![(
"MYSQL_DATADIR".into(),
format!("{}/mysql/data", pwd),
)])?;
}

if mysql_port.is_empty() {
dag().set_envs(vec![("MYSQL_PORT".into(), "3306".into())])?;
}

let stdout = dag()
.flox()?
.with_workdir(".fluentci")?
.with_exec(vec![
"flox", "install", "mariadb", "overmind", "tmux"
])?
.with_exec(vec!["[ -d $MYSQL_DATADIR ] || mkdir -p $MYSQL_DATADIR"])?
.with_exec(vec!["[ -f $MYSQL_DATADIR/ca.pem ] || flox activate -- mysql_install_db --auth-root-authentication-method=normal --datadir=$MYSQL_DATADIR --pid-file=$MYSQL_HOME/mysql.pid"])?
.with_exec(vec![
"grep -q mariadb Procfile || echo 'mariadb: mysqld --datadir=$MYSQL_DATADIR --log-error=$MYSQL_HOME/mysql.log --port=$MYSQL_PORT --socket=$MYSQL_HOME/mysql.socket' >> Procfile",
])?
.stdout()?;

Ok(stdout)
}
36 changes: 36 additions & 0 deletions mariadb/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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("MYSQL_PORT")?;
let stdout = dag()
.flox()?
.with_workdir(".fluentci")?
.with_exec(vec!["overmind", "--version"])?
.with_exec(vec!["mysql", "-V"])?
.with_exec(vec!["type", "overmind"])?
.with_exec(vec!["type", "mysql"])?
.with_exec(vec!["echo -e \"MySQL starting on port $MYSQL_PORT\""])?
.with_exec(vec!["overmind", "start", "-f", "Procfile", "--daemonize"])?
.with_exec(vec!["sleep", "2"])?
.with_exec(vec!["cat", "$MYSQL_HOME/mysql.log"])?
.with_exec(vec!["overmind", "status"])?
.wait_on(port.parse()?, None)?
.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 mariadb/target

0 comments on commit 084a998

Please sign in to comment.