From c7ce80c5e3e58671a9b633200e6551298371d1d4 Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Mon, 25 Mar 2024 04:41:47 -0700 Subject: [PATCH] cancel build --- .vscode/resolver.code-snippets | 4 +- bin/core/src/api/execute/mod.rs | 1 + bin/core/src/api/read/build.rs | 24 +++- bin/core/src/api/read/mod.rs | 2 + client/core/rs/src/api/read/build.rs | 13 ++ client/core/ts/generate_types.mjs | 2 +- client/core/ts/src/responses.ts | 2 + client/core/ts/src/types.ts | 18 ++- frontend/src/components/omnibar.tsx | 3 + .../src/components/resources/build/index.tsx | 115 +++++++++++++++--- .../resources/deployment/config/index.tsx | 2 +- runfile.toml | 2 +- 12 files changed, 159 insertions(+), 29 deletions(-) diff --git a/.vscode/resolver.code-snippets b/.vscode/resolver.code-snippets index 3d47f4086..724485fbe 100644 --- a/.vscode/resolver.code-snippets +++ b/.vscode/resolver.code-snippets @@ -4,8 +4,8 @@ "prefix": "resolve", "body": [ "#[async_trait]", - "impl Resolve<${1}, ResolverArgs> for State {", - "\tasync fn resolve(&self, ${1} { ${0} }: ${1}, _: ResolverArgs) -> anyhow::Result<${2}> {", + "impl Resolve<${1}, User> for State {", + "\tasync fn resolve(&self, ${1} { ${0} }: ${1}, _: User) -> anyhow::Result<${2}> {", "\t\ttodo!()", "\t}", "}" diff --git a/bin/core/src/api/execute/mod.rs b/bin/core/src/api/execute/mod.rs index 854cc19b2..dd52eba10 100644 --- a/bin/core/src/api/execute/mod.rs +++ b/bin/core/src/api/execute/mod.rs @@ -38,6 +38,7 @@ enum ExecuteRequest { // ==== BUILD ==== RunBuild(RunBuild), + CancelBuild(CancelBuild), // ==== REPO ==== CloneRepo(CloneRepo), diff --git a/bin/core/src/api/read/build.rs b/bin/core/src/api/read/build.rs index bdd464c15..9ebcf120d 100644 --- a/bin/core/src/api/read/build.rs +++ b/bin/core/src/api/read/build.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::{collections::HashMap, sync::OnceLock}; use anyhow::Context; use async_timing_util::unix_timestamp_ms; @@ -21,9 +21,10 @@ use mungos::{ options::FindOptions, }, }; -use resolver_api::Resolve; +use resolver_api::{Resolve, ResolveToString}; use crate::{ + config::core_config, db::db_client, helpers::resource::StateResource, state::{action_states, State}, @@ -235,3 +236,22 @@ impl Resolve for State { Ok(versions) } } + +fn docker_organizations() -> &'static String { + static DOCKER_ORGANIZATIONS: OnceLock = OnceLock::new(); + DOCKER_ORGANIZATIONS.get_or_init(|| { + serde_json::to_string(&core_config().docker_organizations) + .expect("failed to serialize docker organizations") + }) +} + +#[async_trait] +impl ResolveToString for State { + async fn resolve_to_string( + &self, + ListDockerOrganizations {}: ListDockerOrganizations, + _: User, + ) -> anyhow::Result { + Ok(docker_organizations().clone()) + } +} diff --git a/bin/core/src/api/read/mod.rs b/bin/core/src/api/read/mod.rs index 37b99d793..b4f4467cc 100644 --- a/bin/core/src/api/read/mod.rs +++ b/bin/core/src/api/read/mod.rs @@ -82,6 +82,8 @@ enum ReadRequest { GetBuildActionState(GetBuildActionState), GetBuildMonthlyStats(GetBuildMonthlyStats), GetBuildVersions(GetBuildVersions), + #[to_string_resolver] + ListDockerOrganizations(ListDockerOrganizations), // ==== REPO ==== GetReposSummary(GetReposSummary), diff --git a/client/core/rs/src/api/read/build.rs b/client/core/rs/src/api/read/build.rs index c3039cff6..a5fa264d4 100644 --- a/client/core/rs/src/api/read/build.rs +++ b/client/core/rs/src/api/read/build.rs @@ -154,3 +154,16 @@ pub struct BuildVersionResponseItem { pub version: Version, pub ts: I64, } + +// + +#[typeshare] +#[derive( + Serialize, Deserialize, Debug, Clone, Default, Request, EmptyTraits, +)] +#[empty_traits(MonitorReadRequest)] +#[response(ListDockerOrganizationsResponse)] +pub struct ListDockerOrganizations {} + +#[typeshare] +pub type ListDockerOrganizationsResponse = Vec; diff --git a/client/core/ts/generate_types.mjs b/client/core/ts/generate_types.mjs index e490b20ef..845356cbc 100644 --- a/client/core/ts/generate_types.mjs +++ b/client/core/ts/generate_types.mjs @@ -8,7 +8,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); console.log("generating typescript types..."); const gen_command = - "RUST_BACKTRACE=1 typeshare . --lang=typescript --output-file=./client/ts/src/types.ts"; + "RUST_BACKTRACE=1 typeshare . --lang=typescript --output-file=./client/core/ts/src/types.ts"; exec(gen_command, (error, stdout, stderr) => { if (error) { diff --git a/client/core/ts/src/responses.ts b/client/core/ts/src/responses.ts index b0494de87..800c6962b 100644 --- a/client/core/ts/src/responses.ts +++ b/client/core/ts/src/responses.ts @@ -57,6 +57,7 @@ export type ReadResponses = { GetBuildActionState: Types.GetBuildActionStateResponse; GetBuildMonthlyStats: Types.GetBuildMonthlyStatsResponse; GetBuildVersions: Types.GetBuildVersionsResponse; + ListDockerOrganizations: Types.ListDockerOrganizationsResponse; // ==== REPO ==== GetReposSummary: Types.GetReposSummaryResponse; @@ -180,6 +181,7 @@ export type ExecuteResponses = { // ==== BUILD ==== RunBuild: Types.Update; + CancelBuild: Types.CancelBuildResponse; // ==== REPO ==== CloneRepo: Types.Update; diff --git a/client/core/ts/src/types.ts b/client/core/ts/src/types.ts index 26f1a8063..63e3502e2 100644 --- a/client/core/ts/src/types.ts +++ b/client/core/ts/src/types.ts @@ -124,6 +124,8 @@ export interface BuildVersionResponseItem { export type GetBuildVersionsResponse = BuildVersionResponseItem[]; +export type ListDockerOrganizationsResponse = string[]; + export type BuilderConfig = | { type: "Server", params: ServerBuilderConfig } | { type: "Aws", params: AwsBuilderConfig }; @@ -308,9 +310,9 @@ export type GetUsersResponse = User[]; export type ProcedureConfig = | { type: "Execution", data: Execution } /** Vec */ - | { type: "Sequence", data: string[] } + | { type: "Sequence", data: EnabledId[] } /** Vec */ - | { type: "Parallel", data: string[] }; + | { type: "Parallel", data: EnabledId[] }; export type Procedure = Resource; @@ -729,6 +731,7 @@ export type _PartialSlackAlerterConfig = Partial; /** Passing empty Vec is the same as not filtering by that field */ export interface ResourceQuery { names?: string[]; + /** Pass Vec of tag ids */ tags?: string[]; specific?: T; } @@ -1032,6 +1035,9 @@ export interface GetBuildVersions { patch?: number; } +export interface ListDockerOrganizations { +} + export interface GetBuilder { id: string; } @@ -1642,6 +1648,12 @@ export interface CloneArgs { github_account?: string; } +/** Allows to enable / disabled procedures in the sequence / parallel vec on the fly */ +export interface EnabledId { + id: string; + enabled: boolean; +} + export interface ServerHealth { cpu: SeverityLevel; mem: SeverityLevel; @@ -1666,6 +1678,7 @@ export type ExecuteRequest = | { type: "StopAllContainers", params: StopAllContainers } | { type: "RemoveContainer", params: RemoveContainer } | { type: "RunBuild", params: RunBuild } + | { type: "CancelBuild", params: CancelBuild } | { type: "CloneRepo", params: CloneRepo } | { type: "PullRepo", params: PullRepo } | { type: "RunProcedure", params: RunProcedure }; @@ -1710,6 +1723,7 @@ export type ReadRequest = | { type: "GetBuildActionState", params: GetBuildActionState } | { type: "GetBuildMonthlyStats", params: GetBuildMonthlyStats } | { type: "GetBuildVersions", params: GetBuildVersions } + | { type: "ListDockerOrganizations", params: ListDockerOrganizations } | { type: "GetReposSummary", params: GetReposSummary } | { type: "GetRepo", params: GetRepo } | { type: "ListRepos", params: ListRepos } diff --git a/frontend/src/components/omnibar.tsx b/frontend/src/components/omnibar.tsx index ca64416a8..e597b8566 100644 --- a/frontend/src/components/omnibar.tsx +++ b/frontend/src/components/omnibar.tsx @@ -54,6 +54,9 @@ export const Omnibar = () => { useEffect(() => { const down = (e: KeyboardEvent) => { + console.log(e); + const target = e.target as any; + if (target.matches("input") || target.matches("textarea")) return; if (e.shiftKey && e.key === "S") { e.preventDefault(); set(true); diff --git a/frontend/src/components/resources/build/index.tsx b/frontend/src/components/resources/build/index.tsx index 09a2e031f..753549664 100644 --- a/frontend/src/components/resources/build/index.tsx +++ b/frontend/src/components/resources/build/index.tsx @@ -1,19 +1,30 @@ import { ConfigInner } from "@components/config"; -import { ResourceSelector, AccountSelector } from "@components/config/util"; +import { + ResourceSelector, + AccountSelector, + ConfigItem, +} from "@components/config/util"; import { NewResource } from "@components/layouts"; import { ConfirmButton } from "@components/util"; import { useExecute, useRead, useWrite } from "@lib/hooks"; -import { fmt_date_with_minutes, fmt_version } from "@lib/utils"; +import { + env_to_text, + fmt_date_with_minutes, + fmt_version, + text_to_env, +} from "@lib/utils"; import { Types } from "@monitor/client"; import { RequiredResourceComponents } from "@types"; import { DataTable } from "@ui/data-table"; import { Input } from "@ui/input"; -import { Hammer, History, Loader2 } from "lucide-react"; -import { useState } from "react"; +import { Ban, Hammer, History, Loader2 } from "lucide-react"; +import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import { ResourceComponents } from ".."; import { BuildChart } from "@components/dashboard/builds-chart"; import { useTagsFilter } from "@components/tags"; +import { Textarea } from "@ui/textarea"; +import { useToast } from "@ui/use-toast"; const useBuild = (id?: string) => useRead("ListBuilds", {}).data?.find((d) => d.id === id); @@ -39,8 +50,33 @@ const NewBuild = () => { ); }; +export const BuildArgs = ({ + vars, + set, +}: { + vars: Types.EnvironmentVar[]; + set: (input: Partial) => void; +}) => { + const [args, setArgs] = useState(env_to_text(vars)); + useEffect(() => { + !!args && set({ build_args: text_to_env(args) }); + }, [args, set]); + + return ( + +