From 3ce3de876880046076edcac8f4ef48b2fafe55c3 Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Sun, 9 Jun 2024 19:34:49 -0700 Subject: [PATCH] configure registry --- frontend/src/components/config/util.tsx | 193 +++++++++++++++--- .../src/components/resources/build/config.tsx | 61 ++---- .../resources/deployment/config/index.tsx | 39 ++-- .../src/components/resources/repo/config.tsx | 4 +- .../resources/resource-sync/config.tsx | 4 +- 5 files changed, 203 insertions(+), 98 deletions(-) diff --git a/frontend/src/components/config/util.tsx b/frontend/src/components/config/util.tsx index 63127e0d3..c00ef1d45 100644 --- a/frontend/src/components/config/util.tsx +++ b/frontend/src/components/config/util.tsx @@ -184,6 +184,22 @@ export const DoubleInput = < ); }; +export const AccountSelectorConfig = (params: { + disabled: boolean; + id?: string; + type: "Server" | "None" | "Builder"; + account_type: keyof Types.GetBuilderAvailableAccountsResponse; + selected: string | undefined; + onSelect: (id: string) => void; + placeholder: string; +}) => { + return ( + + + + ); +}; + export const AccountSelector = ({ disabled, id, @@ -207,30 +223,28 @@ export const AccountSelector = ({ : ["GetBuilderAvailableAccounts", { builder: id }]; const accounts = useRead(request as any, params).data; return ( - - { + onSelect(value === "Empty" ? "" : value); + }} + disabled={disabled} + > + - - - - - {placeholder} - {(accounts as any)?.[account_type]?.map((account: string) => ( - - {account} - - ))} - - - + + + + {placeholder} + {(accounts as any)?.[account_type]?.map((account: string) => ( + + {account} + + ))} + + ); }; @@ -440,19 +454,74 @@ export const ImageRegistryConfig = ({ registry, setRegistry, disabled, + type, + resource_id, + registry_types, }: { registry: Types.ImageRegistry | undefined; setRegistry: (registry: Types.ImageRegistry) => void; disabled: boolean; + type: "Build" | "Deployment"; + // For builds, its builder id. For servers, its server id. + resource_id?: string; + registry_types?: Types.ImageRegistry["type"][]; }) => { const _registry = registry ?? default_registry_config("None"); + const cloud_params = + _registry.type === "DockerHub" || _registry.type === "Ghcr" + ? _registry.params + : undefined; + if (_registry.type === "None" || _registry.type === "Custom") { + return ( + + + + ); + } return ( - +
+ {type === "Build" && ( + + setRegistry({ + ..._registry, + params: { ..._registry.params, organization }, + }) + } + disabled={disabled} + type={_registry.type === "DockerHub" ? "Docker" : "Github"} + /> + )} + + setRegistry({ + ..._registry, + params: { ..._registry.params, account }, + }) + } + disabled={disabled} + placeholder="None" + /> + +
); }; @@ -466,17 +535,23 @@ const REGISTRY_TYPES: Types.ImageRegistry["type"][] = [ const RegistryTypeSelector = ({ registry, setRegistry, + registry_types = REGISTRY_TYPES, disabled, + deployment, }: { registry: Types.ImageRegistry; setRegistry: (registry: Types.ImageRegistry) => void; + registry_types?: Types.ImageRegistry["type"][]; disabled: boolean; + deployment?: boolean; }) => { return ( + ); +}; + +const OrganizationSelector = ({ + value, + set, + disabled, + type, +}: { + value?: string; + set: (org: string) => void; + disabled: boolean; + type: "Docker" | "Github"; +}) => { + const organizations = useRead(`List${type}Organizations`, {}).data; + if (!organizations || organizations.length === 0) return null; + return ( + -// set({ docker_organization: value === "Empty" ? "" : value }) -// } -// disabled={disabled} -// > -// -// -// -// -// None -// {docker_organizations?.map((org) => ( -// -// {org} -// -// ))} -// -// -// -// ); -// }; diff --git a/frontend/src/components/resources/deployment/config/index.tsx b/frontend/src/components/resources/deployment/config/index.tsx index dcf75074b..e2252783d 100644 --- a/frontend/src/components/resources/deployment/config/index.tsx +++ b/frontend/src/components/resources/deployment/config/index.tsx @@ -4,6 +4,7 @@ import { ReactNode, useState } from "react"; import { AddExtraArgMenu, ConfigItem, + ImageRegistryConfig, InputList, } from "@components/config/util"; import { ImageConfig } from "./components/image"; @@ -81,21 +82,29 @@ export const DeploymentConfig = ({ image: (value, set) => ( ), - // docker_account: (value, set) => ( - // set({ docker_account })} - // disabled={disabled} - // placeholder={ - // (update.image?.type || config.image?.type) === "Build" - // ? "Same as build" - // : "None" - // } - // /> - // ), + image_registry: (registry, set) => { + const image_type = update.image?.type ?? config.image?.type; + const build_id: string | undefined = + (image_type === "Build" && + (update.image?.params as any).build_id) ?? + (config.image?.params as any).build_id; + const build_registry_type = useRead("GetBuild", { + build: build_id!, + }).data?.config.image_registry?.type; + const server_id = update.server_id ?? config.server_id; + return ( + set({ image_registry })} + type="Deployment" + resource_id={server_id} + disabled={disabled} + registry_types={ + build_registry_type && ["None", build_registry_type] + } + /> + ); + }, restart: (value, set) => ( { github_account: (value, set) => { const server_id = update.server_id || config.server_id; return ( - { return ( -