Skip to content

Commit

Permalink
feat: add minikube service
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Jul 16, 2024
1 parent a4391d6 commit 676701e
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 5 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/minikube.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: ci
on:
push:
branches:
- main
paths:
- minikube/**
- .github/workflows/minikube.yml
jobs:
minikube-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: minikube
env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Start minikube server
run: |
fluentci run target/wasm32-unknown-unknown/release/minikube.wasm start
fluentci run target/wasm32-unknown-unknown/release/minikube.wasm stop
working-directory: minikube
env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NIX_CONFIG: extra-access-tokens = github.com=${{ secrets.GH_ACCESS_TOKEN }}
14 changes: 12 additions & 2 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 @@ -10,6 +10,7 @@ default-members = [
"mariadb",
"meilisearch",
"memcached",
"minikube",
"minio",
"mongodb",
"mysql",
Expand All @@ -35,6 +36,7 @@ members = [
"mariadb",
"meilisearch",
"memcached",
"minikube",
"minio",
"mongodb",
"mysql",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fluentci run --wasm postgres start
| [mariadb](./mariadb) | The open source relational database |
| [meilisearch](./meilisearch) | A powerful, fast, open-source, easy to use search engine |
| [memcached](./memcached) | A high-performance, distributed memory object caching system |
| [minikube](./minikube) | A tool that makes it easy to run Kubernetes locally |
| [minio](./minio) | A high performance distributed object storage server |
| [mongodb](./mongodb) | A general purpose, document-based, distributed database |
| [mysql](./mysql) | The world's most popular open source database |
Expand Down
20 changes: 20 additions & 0 deletions minikube/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
authors = [
"Tsiry Sandratraina <[email protected]>",
]
description = "Minikube plugin for FluentCI"
edition = "2021"
license = "MIT"
name = "minikube"
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 minikube/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.
54 changes: 54 additions & 0 deletions minikube/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Minikube Plugin

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

Minikube service plugin for FluentCI.

## 🚀 Usage

Add the following command to your CI configuration file:

```bash
fluentci run --wasm minikube start
```

## Functions

| Name | Description |
| ------ | -------------------------------------------- |
| start | Start Minikube |
| stop | Stop Minikub |

## 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: minikube
args: |
start
```
11 changes: 11 additions & 0 deletions minikube/fluentci.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
authors = [
"Tsiry Sandratraina <[email protected]>",
]
description = "Minikube Plugin for FluentCI"
keywords = [
"minikube",
]
license = "MIT"
name = "minikube"
version = "0.1.0"
24 changes: 24 additions & 0 deletions minikube/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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()
.pkgx()?
.with_workdir(".fluentci")?
.with_packages(vec![
"kubernetes.io/minikube",
"github.com/darthsim/overmind",
"github.com/tmux/tmux",
])?
.with_exec(vec![
"grep -q minikube Procfile || echo -e 'minikube: minikube start --force $MINIKUBE_ARGS && minikube logs -f \\n' >> Procfile",
])?
.stdout()?;

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

pub mod helpers;

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

let stdout = dag()
.pkgx()?
.with_workdir(".fluentci")?
.with_exec(vec!["overmind", "--version"])?
.with_exec(vec!["minikube", "version"])?
.with_exec(vec!["type", "overmind"])?
.with_exec(vec!["type", "minikube"])?
.with_exec(vec![
"overmind start -f Procfile --daemonize || overmind restart minikube",
])?
.wait_on(32768, None)?
.wait_on(32769, None)?
.wait_on(32770, None)?
.wait_on(32771, None)?
.wait_on(32772, 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() {
"minikube".to_string()
} else {
args
};

let stdout = dag()
.pkgx()?
.with_workdir(".fluentci")?
.with_exec(vec!["overmind", "stop", &args])?
.stdout()?;
Ok(stdout)
}
1 change: 1 addition & 0 deletions minikube/target
2 changes: 1 addition & 1 deletion redis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description = "Redis plugin for FluentCI"
edition = "2021"
license = "MIT"
name = "redis"
version = "0.1.1"
version = "0.1.2"

[lib]
crate-type = [
Expand Down
2 changes: 1 addition & 1 deletion redis/fluentci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ keywords = [
]
license = "MIT"
name = "redis"
version = "0.1.1"
version = "0.1.2"
2 changes: 1 addition & 1 deletion redis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn start(_args: String) -> FnResult<String> {
.with_exec(vec!["type", "overmind"])?
.with_exec(vec!["type", "redis-server"])?
.with_exec(vec![
"overmind start -f Procfile --daemonize || flox activate -- overmind restart redis",
"overmind start -f Procfile --daemonize || overmind restart redis",
])?
.wait_on(port.parse()?, None)?
.with_exec(vec!["overmind", "status"])?
Expand Down

0 comments on commit 676701e

Please sign in to comment.