Skip to content

Commit

Permalink
feat: add stripe-mock service
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Jul 15, 2024
1 parent a908290 commit 835a4c6
Show file tree
Hide file tree
Showing 15 changed files with 228 additions and 5 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/stripe-mock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: ci
on:
push:
branches:
- main
paths:
- stripe-mock/**
- .github/workflows/stripe-mock.yml
jobs:
stripe-mock-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: stripe-mock
env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Start stripe-mock Server
run: |
fluentci run target/wasm32-unknown-unknown/release/stripe_mock.wasm start
fluentci run target/wasm32-unknown-unknown/release/stripe_mock.wasm stop
working-directory: stripe-mock
env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NIX_CONFIG: extra-access-tokens = github.com=${{ secrets.GH_ACCESS_TOKEN }}
2 changes: 1 addition & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fluentci run --wasm postgres start
| [php-fpm](./php) | PHP FastCGI Process Manager |
| [rabbitmq](./rabbitmq) | An open source multi-protocol messaging broker |
| [redis](./redis) | An in-memory database that persists on disk |
| [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 |
| [typesense](./typesense) | A fast, typo-tolerant search engine for building delightful search experiences |

Expand Down
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.0"
version = "0.1.1"

[lib]
crate-type = [
Expand Down
2 changes: 1 addition & 1 deletion redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use fluentci_pdk::dag;

// ...

dag().call("https://pkg.fluentci.io/[email protected].0?wasm=1", "start", vec![])?;
dag().call("https://pkg.fluentci.io/[email protected].1?wasm=1", "start", vec![])?;
```

## 📚 Examples
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.0"
version = "0.1.1"
8 changes: 7 additions & 1 deletion redis/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ pub fn setup() -> Result<String, Error> {
.with_exec(vec!["mkdir", "-p", ".fluentci"])?
.stdout()?;

let redis_port = dag().get_env("REDIS_PORT")?;

if redis_port.is_empty() {
dag().set_envs(vec![("REDIS_PORT".into(), "6379".into())])?;
}

let stdout = dag()
.pkgx()?
.with_workdir(".fluentci")?
Expand All @@ -16,7 +22,7 @@ pub fn setup() -> Result<String, Error> {
"github.com/tmux/tmux",
])?
.with_exec(vec![
"grep -q redis Procfile || echo -e 'redis: redis-server\\n' >> Procfile",
"grep -q redis Procfile || echo -e 'redis: redis-server --port $REDIS_PORT \\n' >> Procfile",
])?
.stdout()?;

Expand Down
4 changes: 4 additions & 0 deletions redis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ pub mod helpers;
#[plugin_fn]
pub fn start(_args: String) -> FnResult<String> {
helpers::setup()?;

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

let stdout = dag()
.pkgx()?
.with_workdir(".fluentci")?
Expand All @@ -16,6 +19,7 @@ pub fn start(_args: String) -> FnResult<String> {
.with_exec(vec![
"overmind start -f Procfile --daemonize || flox activate -- overmind restart redis",
])?
.wait_on(port.parse()?, None)?
.with_exec(vec!["overmind", "status"])?
.stdout()?;
Ok(stdout)
Expand Down
20 changes: 20 additions & 0 deletions stripe-mock/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 stripe-mock/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 stripe-mock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Stripe Mock Plugin

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

Redis service plugin for FluentCI.

## 🚀 Usage

Add the following command to your CI configuration file:

```bash
fluentci run --wasm stripe-mock start
```

## Functions

| Name | Description |
| ------ | -------------------------------------------------- |
| start | Start Stripe Mock server |
| stop | Stop Stripe Mock 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: stripe-mock
args: |
start
```
11 changes: 11 additions & 0 deletions stripe-mock/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"
28 changes: 28 additions & 0 deletions stripe-mock/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use anyhow::Error;
use fluentci_pdk::dag;

pub fn setup() -> Result<String, Error> {
let path = dag().get_env("PATH")?;
dag().set_envs(vec![(
"PATH".into(),
format!("/home/linuxbrew/.linuxbrew/bin:{}", path),
)])?;

dag()
.pipeline("setup")?
.with_exec(vec!["mkdir", "-p", ".fluentci"])?
.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 stripe-mock > /dev/null 2> /dev/null || brew install stripe/stripe-mock/stripe-mock"])?
.stdout()?;

let stdout = dag()
.pkgx()?
.with_workdir(".fluentci")?
.with_packages(vec!["github.com/darthsim/overmind", "github.com/tmux/tmux"])?
.with_exec(vec![
"grep -q stripe-mock Procfile || echo -e 'stripe-mock: stripe-mock -http-port $STRIPE_HTTP_PORT -https-port $STRIPE_HTTPS_PORT \\n' >> Procfile",
])?
.stdout()?;

Ok(stdout)
}
44 changes: 44 additions & 0 deletions stripe-mock/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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("STRIPE_HTTP_PORT")?;

let stdout = dag()
.pkgx()?
.with_workdir(".fluentci")?
.with_exec(vec!["overmind", "--version"])?
.with_exec(vec!["stripe-mock", "--version"])?
.with_exec(vec!["type", "overmind"])?
.with_exec(vec!["type", "stripe-mock"])?
.with_exec(vec![
"overmind start -f Procfile --daemonize || flox activate -- overmind restart stripe-mock",
])?
.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() {
"stripe-mock".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 stripe-mock/target

0 comments on commit 835a4c6

Please sign in to comment.