-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update README.md fix daemon fix daemon fix daemon fix daemon fix daemon fix daemon
- Loading branch information
Showing
11 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: ci | ||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- daemon/** | ||
- .github/workflows/daemon.yml | ||
jobs: | ||
daemon-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: daemon | ||
env: | ||
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Start daemon | ||
run: | | ||
fluentci run target/wasm32-unknown-unknown/release/daemon.wasm start demo pkgx bunx serve -p 4000 | ||
pkgx deno run -A npm:wait-port 4000 | ||
pkgx http http://localhost:4000 | ||
fluentci run target/wasm32-unknown-unknown/release/daemon.wasm stop demo | ||
curl -s http://localhost:4000 || true | ||
working-directory: daemon | ||
env: | ||
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NIX_CONFIG: extra-access-tokens = github.com=${{ secrets.GH_ACCESS_TOKEN }} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
authors = [ | ||
"Tsiry Sandratraina <tsiry.sndr@fluentci.io>", | ||
] | ||
description = "Service daemon plugin for FluentCI" | ||
edition = "2021" | ||
license = "MIT" | ||
name = "daemon" | ||
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Daemon Plugin | ||
|
||
[![fluentci pipeline](https://shield.fluentci.io/x/daemon)](https://pkg.fluentci.io/daemon) | ||
[![ci](https://github.com/fluentci-io/services/actions/workflows/daemon.yml/badge.svg)](https://github.com/fluentci-io/services/actions/workflows/daemon.yml) | ||
|
||
Daemon service plugin for FluentCI. | ||
|
||
## 🚀 Usage | ||
|
||
Add the following command to your CI configuration file: | ||
|
||
```bash | ||
fluentci run --wasm daemon start | ||
``` | ||
|
||
## Functions | ||
|
||
| Name | Description | | ||
| ------ | ---------------------------------------------- | | ||
| start | Start daemon | | ||
| stop | Stop daemon | | ||
|
||
## 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/daemon@v0.1.0?wasm=1", "start", vec!["demo", "pkgx bunx serve -p 4000"])?; | ||
``` | ||
|
||
## 📚 Examples | ||
|
||
Github Actions: | ||
|
||
```yaml | ||
- name: Setup Fluent CI CLI | ||
uses: fluentci-io/setup-fluentci@v5 | ||
with: | ||
wasm: true | ||
plugin: daemon | ||
args: | | ||
start demo dpkgx bunx serve -p 4000 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
authors = [ | ||
"Tsiry Sandratraina <tsiry.sndr@fluentci.io>", | ||
] | ||
description = "Service daemon Plugin for FluentCI" | ||
keywords = [ | ||
"daemon", | ||
] | ||
license = "MIT" | ||
name = "daemon" | ||
version = "0.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use anyhow::Error; | ||
use fluentci_pdk::dag; | ||
|
||
pub fn setup(name: &str, command: &str) -> Result<String, Error> { | ||
let workdir = format!(".fluentci/{}", name); | ||
|
||
dag() | ||
.pipeline("setup")? | ||
.with_exec(vec!["mkdir", "-p", &workdir])? | ||
.stdout()?; | ||
|
||
let stdout = dag() | ||
.pkgx()? | ||
.with_workdir(&workdir)? | ||
.with_packages(vec!["github.com/darthsim/overmind", "github.com/tmux/tmux"])? | ||
.with_exec(vec![&format!( | ||
"grep -q {}: Procfile || echo -e '{}: {} \\n' >> Procfile", | ||
name, name, command | ||
)])? | ||
.stdout()?; | ||
|
||
Ok(stdout) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use anyhow::Error; | ||
use extism_pdk::*; | ||
use fluentci_pdk::dag; | ||
|
||
pub mod helpers; | ||
|
||
#[plugin_fn] | ||
pub fn start(args: String) -> FnResult<String> { | ||
let mut args = args.split_whitespace(); | ||
let name = args.next().unwrap_or_default(); | ||
let command = args.collect::<Vec<&str>>().join(" "); | ||
helpers::setup(name, &command)?; | ||
|
||
let workdir = format!(".fluentci/{}", name); | ||
|
||
let stdout = dag() | ||
.pkgx()? | ||
.with_workdir(&workdir)? | ||
.with_exec(vec!["overmind", "--version"])? | ||
.with_exec(vec!["type", "overmind"])? | ||
.with_exec(vec![ | ||
"overmind start -f Procfile --daemonize || overmind restart", | ||
&name, | ||
])? | ||
.with_exec(vec!["overmind", "status"])? | ||
.stdout()?; | ||
Ok(stdout) | ||
} | ||
|
||
#[plugin_fn] | ||
pub fn stop(args: String) -> FnResult<String> { | ||
if args.is_empty() { | ||
return Err(Error::msg("Missing argument").into()); | ||
} | ||
if args.split_whitespace().clone().count() != 1 { | ||
return Err(Error::msg("Invalid argument").into()); | ||
} | ||
|
||
let workdir = format!(".fluentci/{}", args); | ||
|
||
let stdout = dag() | ||
.pkgx()? | ||
.with_workdir(&workdir)? | ||
.with_exec(vec!["overmind", "stop", &args])? | ||
.stdout()?; | ||
Ok(stdout) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../target |