From 6589af08181bf9786d4d776294849febd58c0618 Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Fri, 12 Jan 2024 07:49:09 +0000 Subject: [PATCH] feat: show `pid`, `version` and `dagger version` in `agent list` --- README.md | 2 +- deno.lock | 1 + main.ts | 3 ++- src/cmd/agent.ts | 38 +++++++++++++++++++++++++++++--------- src/consts.ts | 2 ++ src/types.ts | 5 ++++- src/utils.ts | 11 +++++++++++ 7 files changed, 50 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index ec656fd..36d2cd5 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ fluentci # Run the pipeline fluentci --help Usage: fluentci [pipeline] [jobs...] -Version: 0.10.7 +Version: 0.10.8 Description: diff --git a/deno.lock b/deno.lock index c49d020..31ca1e0 100644 --- a/deno.lock +++ b/deno.lock @@ -547,6 +547,7 @@ "https://esm.sh/v128/graphql-request@6.1.0": "17f00c323eb825811ce14e2b0e88a0c873acb666c382ac963d1edeb03e01f372", "https://esm.sh/v128/graphql-request@6.1.0/denonext/graphql-request.mjs": "0b15f49d44489423ae6f06004725b6d050b6359da4969e6569bd6ad45065bd94", "https://esm.sh/v128/graphql@16.7.1/denonext/graphql.mjs": "418ad7c07b0f2d687f33b6275d3b5f317f4afbef1f462f318229f458dff45416", + "https://esm.sh/v133/mimic-fn@4.0.0/denonext/mimic-fn.mjs": "10bcf0f2f20cbbba0c289ef7bf4d2422639bbc1c36c247be876afd6fe2d67138", "https://esm.sh/v135/@dagger.io/dagger@0.9.3/denonext/dagger.mjs": "998e8e63729621141c0a9b74128db8f81ab7446d1a5d4ff41a6a6b0944db4ddf", "https://esm.sh/v135/adm-zip@0.5.10/denonext/adm-zip.mjs": "9441de5c60a276046d55945f45775d674a319e8e5fd3a8ab7131d8d192d9abb3", "https://esm.sh/v135/chownr@2.0.0/denonext/chownr.mjs": "d7282b2612a9f13c62084c76fc72cdfb20503bccce959178b77b6def14d3ffd2", diff --git a/main.ts b/main.ts index c7cc902..ecaa42b 100644 --- a/main.ts +++ b/main.ts @@ -18,11 +18,12 @@ import publish from "./src/cmd/publish.ts"; import startAgent, { listAgents } from "./src/cmd/agent.ts"; import whoami from "./src/cmd/whoami.ts"; import { brightGreen } from "./deps.ts"; +import { VERSION } from "./src/consts.ts"; export async function main() { await new Command() .name("fluentci") - .version("0.10.7") + .version(VERSION) .description( ` . diff --git a/src/cmd/agent.ts b/src/cmd/agent.ts index 2eefd2c..cd6e91f 100644 --- a/src/cmd/agent.ts +++ b/src/cmd/agent.ts @@ -13,10 +13,17 @@ import { RUNNER_URL, FLUENTCI_EVENTS_URL, BUILD_DIR, + VERSION, } from "../consts.ts"; -import { formatBytes, getAccessToken, isLogged } from "../utils.ts"; +import { + formatBytes, + getAccessToken, + getDaggerVersion, + isLogged, +} from "../utils.ts"; import { hostname, release, cpus, arch, totalmem, platform } from "node:os"; import { Agent } from "../types.ts"; +import O from "https://esm.sh/v133/mimic-fn@4.0.0/denonext/mimic-fn.mjs"; async function startAgent() { console.log(` @@ -201,10 +208,13 @@ async function spawnFluentCI( async function getWebSocketUuid(agentId: string) { const accessToken = await getAccessToken(); + const daggerVersion = await getDaggerVersion(); const uuid = await fetch( `${FLUENTCI_EVENTS_URL}/auth?agent_id=${agentId}&hostname=${hostname()}&release=${release()}&cpus=${ cpus().length - }&arch=${arch()}&totalmem=${totalmem()}&platform=${platform()}`, + }&arch=${arch()}&totalmem=${totalmem()}&platform=${platform()}&version=${VERSION}&pid=${ + Deno.pid + }&daggerversion=${daggerVersion}`, { method: "GET", headers: { @@ -221,7 +231,7 @@ export async function listAgents() { `https://api.fluentci.io/validate?token=${accessToken}` ).then((res) => res.text()); const agents: Agent[] = await fetch( - `${FLUENTCI_EVENTS_URL}?id=${userId}` + `${FLUENTCI_EVENTS_URL}/agents?id=${userId}` ).then((res) => res.json()); if (!agents.length) { @@ -233,19 +243,29 @@ export async function listAgents() { table.header([ "NAME", "HOSTNAME", - "RELEASE", "CPUs", "ARCH", "RAM", "OS", + "VERSION", + "PID", + "DAGGER", "STARTED AT", ]); - for (const agent of agents) { - const rows = Object.values(agent); - rows[5] = formatBytes(rows[5] as number); - rows[7] = dayjs(rows[7]).fromNow(); - table.push(rows.map((x) => (x === 0 || x === "0 Bytes" ? "" : x))); + const totalmem = agent.totalmem === 0 ? "" : formatBytes(agent.totalmem); + table.push([ + agent.agent_id, + agent.hostname, + agent.cpus, + agent.arch, + totalmem, + agent.platform, + agent.version, + agent.pid, + agent.daggerVersion, + dayjs(agent.startedAt).fromNow(), + ]); } table.render(); diff --git a/src/consts.ts b/src/consts.ts index cf0df6e..d299531 100644 --- a/src/consts.ts +++ b/src/consts.ts @@ -1,5 +1,7 @@ import { dir } from "../deps.ts"; +export const VERSION = "0.10.8"; + export const BASE_URL = "https://api.fluentci.io/v1"; const FLUENTCI_HOST = Deno.env.get("FLUENTCI_HOST") || "vm.fluentci.io"; diff --git a/src/types.ts b/src/types.ts index ec6f9a5..40d1d8e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -32,11 +32,14 @@ export const LogEventSchema = z.object({ export const AgentSchema = z.object({ agent_id: z.string(), hostname: z.string(), - release: z.string(), cpus: z.number(), arch: z.string(), totalmem: z.number(), platform: z.string(), + release: z.string(), + version: z.string(), + pid: z.number(), + daggerVersion: z.string(), startedAt: z.string(), }); diff --git a/src/utils.ts b/src/utils.ts index 295b316..d20c835 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -63,3 +63,14 @@ export function extractVersion(name: string): string { } return "latest"; } + +export async function getDaggerVersion(): Promise { + const command = new Deno.Command("dagger", { + args: ["version"], + stdout: "piped", + stderr: "piped", + }); + const { stdout } = await command.output(); + const version = new TextDecoder().decode(stdout).trim().split(" ")[1]; + return version; +}