diff --git a/README.md b/README.md index c8210f9..99ecd45 100644 --- a/README.md +++ b/README.md @@ -86,8 +86,8 @@ Requirements: **Latest (CLI):** -- `Mac`: arm64: [fluentci_v0.15.4_aarch64-apple-darwin.tar.gz](https://github.com/fluentci-io/fluentci/releases/download/v0.15.4/fluentci_v0.15.4_aarch64-apple-darwin.tar.gz) intel: [fluentci_v0.15.4_x86_64-apple-darwin.tar.gz](https://github.com/fluentci-io/fluentci/releases/download/v0.15.4/fluentci_v0.15.4_x86_64-apple-darwin.tar.gz) -- `Linux`: intel: [fluentci_v0.15.4_x86_64-unknown-linux-gnu.tar.gz](https://github.com/fluentci-io/fluentci/releases/download/v0.15.4/fluentci_v0.15.4_x86_64-unknown-linux-gnu.tar.gz) arm64: [fluentci_v0.15.4_aarch64-unknown-linux-gnu.tar.gz](https://github.com/fluentci-io/fluentci/releases/download/v0.15.4/fluentci_v0.15.4_aarch64-unknown-linux-gnu.tar.gz) +- `Mac`: arm64: [fluentci_v0.15.5_aarch64-apple-darwin.tar.gz](https://github.com/fluentci-io/fluentci/releases/download/v0.15.5/fluentci_v0.15.5_aarch64-apple-darwin.tar.gz) intel: [fluentci_v0.15.5_x86_64-apple-darwin.tar.gz](https://github.com/fluentci-io/fluentci/releases/download/v0.15.5/fluentci_v0.15.5_x86_64-apple-darwin.tar.gz) +- `Linux`: intel: [fluentci_v0.15.5_x86_64-unknown-linux-gnu.tar.gz](https://github.com/fluentci-io/fluentci/releases/download/v0.15.5/fluentci_v0.15.5_x86_64-unknown-linux-gnu.tar.gz) arm64: [fluentci_v0.15.5_aarch64-unknown-linux-gnu.tar.gz](https://github.com/fluentci-io/fluentci/releases/download/v0.15.5/fluentci_v0.15.5_aarch64-unknown-linux-gnu.tar.gz) ## ✨ Quick Start @@ -110,7 +110,7 @@ fluentci studio fluentci --help Usage: fluentci [pipeline] [jobs...] -Version: 0.15.4 +Version: 0.15.5 Description: diff --git a/src/cmd/agent.ts b/src/cmd/agent.ts index 94a0a3b..e7c9d5d 100644 --- a/src/cmd/agent.ts +++ b/src/cmd/agent.ts @@ -22,6 +22,7 @@ import { getAccessToken, getDaggerVersion, isLogged, + stopServices, } from "../utils.ts"; import { hostname, release, cpus, arch, totalmem, platform } from "node:os"; import { Action, Agent, Log, Run } from "../types.ts"; @@ -399,6 +400,11 @@ async function executeActions( body: `fluentci_exit=1`, headers, }).catch((e) => logger.error(e.message)); + + if (actions.some((x) => x.use_wasm)) { + await stopServices(cwd); + } + return; } } @@ -447,6 +453,10 @@ async function executeActions( (e) => logger.error(e.message) ); + if (actions.some((x) => x.use_wasm)) { + await stopServices(cwd); + } + fetch(`${FLUENTCI_EVENTS_URL}?client_id=${clientId}`, { method: "POST", body: `fluentci_exit=0`, diff --git a/src/consts.ts b/src/consts.ts index 25aebc8..6d18e6b 100644 --- a/src/consts.ts +++ b/src/consts.ts @@ -1,5 +1,5 @@ import { dir } from "../deps.ts"; -export const VERSION = "0.15.4"; +export const VERSION = "0.15.5"; export const BASE_URL = "https://api.fluentci.io/v1"; diff --git a/src/server/executor.ts b/src/server/executor.ts index 3675bd7..ca7627c 100644 --- a/src/server/executor.ts +++ b/src/server/executor.ts @@ -3,7 +3,7 @@ import { Action } from "./graphql/objects/action.ts"; import { Run } from "./graphql/objects/run.ts"; import { createId, dayjs } from "../../deps.ts"; import { Log } from "./graphql/objects/log.ts"; -import { sendSocketMessage } from "../utils.ts"; +import { sendSocketMessage, stopServices } from "../utils.ts"; export default async function run(ctx: Context, actions: Action[], data: Run) { let currentActionIndex = 0; @@ -114,6 +114,11 @@ export default async function run(ctx: Context, actions: Action[], data: Run) { duration, }); await ctx.kv.projects.updateStats(data.projectId); + + if (actions.some((x) => x.useWasm)) { + await stopServices(project?.path!); + } + return; } } @@ -159,6 +164,10 @@ export default async function run(ctx: Context, actions: Action[], data: Run) { }) ) ); + + if (actions.some((x) => x.useWasm)) { + await stopServices(project?.path!); + } } async function spawn( diff --git a/src/utils.ts b/src/utils.ts index cb079f2..142a815 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -import { dir, brightGreen, wait } from "../deps.ts"; +import { dir, brightGreen, wait, green, procfile } from "../deps.ts"; export async function isLogged(): Promise { if (Deno.env.get("FLUENTCI_ACCESS_TOKEN")) { @@ -404,23 +404,28 @@ export async function bash( } } -export async function getProcfiles() { +export async function getProcfiles(cwd = ".", exit = true): Promise { const command = new Deno.Command("bash", { - args: ["-c", "ls .fluentci/*/Procfile"], + args: ["-c", "ls .fluentci/*/Procfile 2> /dev/null"], stdout: "piped", + cwd, }); const process = await command.spawn(); const { stdout, success } = await process.output(); if (!success) { console.log("No services running"); - Deno.exit(0); + if (exit) Deno.exit(0); + return []; } const decoder = new TextDecoder(); return decoder.decode(stdout).trim().split("\n"); } -export async function getServicePid(name: string, socket: string) { +export async function getServicePid( + name: string, + socket: string +): Promise { try { const response = await writeToSocket(socket, "status\n"); const lines = response.replaceAll("\x00", "").trim().split("\n"); @@ -467,3 +472,32 @@ export async function writeToSocket( conn.close(); return data; } + +export async function stopServices(cwd: string) { + const files = await getProcfiles(cwd, false); + const services = []; + // deno-lint-ignore no-explicit-any + let infos: Record = {}; + + for (const file of files) { + const manifest = procfile.parse(Deno.readTextFileSync(file)); + services.push(...Object.keys(manifest)); + infos = { + ...infos, + ...manifest, + }; + + for (const service of Object.keys(manifest)) { + const socket = file.replace("Procfile", ".overmind.sock"); + + try { + await writeToSocket(cwd + "/" + socket, "stop\n"); + } catch (_e) { + console.log(`Failed to stop ${green(service)}`); + continue; + } + + console.log(`Successfully stopped ${green(service)}`); + } + } +}