From bf0a972ec2c0ba26eb300d04cc9049ffec2a7fc6 Mon Sep 17 00:00:00 2001 From: Maxwell Becker <49575486+mbecker20@users.noreply.github.com> Date: Wed, 13 Nov 2024 23:17:35 -0800 Subject: [PATCH] 1.16.11 (#187) * fix discord stack auto updated link * action only log completion correctly * add containers to omni search * periphery build use --push * use --password-stdin to login * docker login stdin --- bin/core/src/alert/discord.rs | 2 +- bin/core/src/api/execute/action.rs | 7 +- bin/periphery/src/api/build.rs | 8 +-- bin/periphery/src/docker.rs | 19 +++-- frontend/src/components/omnibar.tsx | 103 +++++++++++++++++++++++----- frontend/src/pages/containers.tsx | 8 ++- 6 files changed, 114 insertions(+), 33 deletions(-) diff --git a/bin/core/src/alert/discord.rs b/bin/core/src/alert/discord.rs index 2bf4c804f..e627b5f8c 100644 --- a/bin/core/src/alert/discord.rs +++ b/bin/core/src/alert/discord.rs @@ -140,7 +140,7 @@ pub async fn send_alert( server_name, images, } => { - let link = resource_link(ResourceTargetVariant::Deployment, id); + let link = resource_link(ResourceTargetVariant::Stack, id); let images_label = if images.len() > 1 { "images" } else { "image" }; let images = images.join(", "); diff --git a/bin/core/src/api/execute/action.rs b/bin/core/src/api/execute/action.rs index 3b3732283..05af563cc 100644 --- a/bin/core/src/api/execute/action.rs +++ b/bin/core/src/api/execute/action.rs @@ -226,10 +226,13 @@ const komodo = KomodoClient('{base_url}', {{ params: {{ key: '{key}', secret: '{secret}' }} }}); -async function main() {{{contents}}} +async function main() {{ +{contents} + +console.log('🦎 Action completed successfully 🦎'); +}} main() -.then(() => console.log('🦎 Action completed successfully 🦎')) .catch(error => {{ console.error('🚨 Action exited early with errors 🚨') if (error.status !== undefined && error.result !== undefined) {{ diff --git a/bin/periphery/src/api/build.rs b/bin/periphery/src/api/build.rs index cc0b77cbe..57852525c 100644 --- a/bin/periphery/src/api/build.rs +++ b/bin/periphery/src/api/build.rs @@ -114,15 +114,11 @@ impl Resolve for State { let buildx = if *use_buildx { " buildx" } else { "" }; let image_tags = image_tags(&image_name, image_tag, version, &additional_tags); - let push_command = should_push - .then(|| { - format!(" && docker image push --all-tags {image_name}") - }) - .unwrap_or_default(); + let maybe_push = if should_push { " --push" } else { "" }; // Construct command let command = format!( - "docker{buildx} build{build_args}{command_secret_args}{extra_args}{labels}{image_tags} -f {dockerfile_path} .{push_command}", + "docker{buildx} build{build_args}{command_secret_args}{extra_args}{labels}{image_tags}{maybe_push} -f {dockerfile_path} .", ); if *skip_secret_interp { diff --git a/bin/periphery/src/docker.rs b/bin/periphery/src/docker.rs index a8d264ecd..6ccaa6ddf 100644 --- a/bin/periphery/src/docker.rs +++ b/bin/periphery/src/docker.rs @@ -945,17 +945,24 @@ pub async fn docker_login( None => crate::helpers::registry_token(domain, account)?, }; let log = async_run_command(&format!( - "docker login {domain} -u {account} -p {registry_token}", + "echo {registry_token} | docker login {domain} --username {account} --password-stdin", )) .await; if log.success() { Ok(true) } else { - Err(anyhow!( - "{domain} login error: stdout: {} | stderr: {}", - log.stdout, - log.stderr - )) + let mut e = anyhow!("End of trace"); + for line in + log.stderr.split('\n').filter(|line| !line.is_empty()).rev() + { + e = e.context(line.to_string()); + } + for line in + log.stdout.split('\n').filter(|line| !line.is_empty()).rev() + { + e = e.context(line.to_string()); + } + Err(e.context(format!("Registry {domain} login error"))) } } diff --git a/frontend/src/components/omnibar.tsx b/frontend/src/components/omnibar.tsx index b5fc086fb..dc80b5d65 100644 --- a/frontend/src/components/omnibar.tsx +++ b/frontend/src/components/omnibar.tsx @@ -1,4 +1,4 @@ -import { useAllResources, useUser } from "@lib/hooks"; +import { useAllResources, useLocalStorage, useRead, useUser } from "@lib/hooks"; import { Button } from "@ui/button"; import { CommandDialog, @@ -9,12 +9,14 @@ import { CommandSeparator, CommandItem, } from "@ui/command"; -import { Home, Search, User } from "lucide-react"; +import { Box, Home, Search, User } from "lucide-react"; import { Fragment, ReactNode, useMemo, useState } from "react"; import { useNavigate } from "react-router-dom"; import { cn, RESOURCE_TARGETS, usableResourcePath } from "@lib/utils"; import { Badge } from "@ui/badge"; import { ResourceComponents } from "./resources"; +import { Switch } from "@ui/switch"; +import { DOCKER_LINK_ICONS } from "./util"; export const OmniSearch = ({ className, @@ -67,6 +69,10 @@ export const OmniDialog = ({ navigate(value); }; const items = useOmniItems(nav, search); + const [showContainers, setShowContainers] = useLocalStorage( + "omni-show-containers", + false + ); return ( +
+
Show containers
+ +
No results found. @@ -97,6 +107,10 @@ export const OmniDialog = ({ ))} + + {showContainers && ( + setOpen(false)} /> + )}
); @@ -108,12 +122,12 @@ const useOmniItems = ( ): Record => { const user = useUser().data; const resources = useAllResources(); - const searchTerms = search - .toLowerCase() - .split(" ") - .filter((term) => term); - return useMemo( - () => ({ + return useMemo(() => { + const searchTerms = search + .toLowerCase() + .split(" ") + .filter((term) => term); + return { "": [ { key: "Home", @@ -136,6 +150,12 @@ const useOmniItems = ( onSelect: () => nav(usableResourcePath(_type)), }; }), + { + key: "Containers", + label: "Containers", + icon: , + onSelect: () => nav("/containers"), + }, (user?.admin && { key: "Users", label: "Users", @@ -159,20 +179,21 @@ const useOmniItems = ( : _type === "ServerTemplate" ? "Template" : _type; - const lower = type.toLowerCase(); + const lower_type = type.toLowerCase(); const Components = ResourceComponents[_type]; return [ type + "s", resources[_type] - ?.filter( - (item) => + ?.filter((item) => { + const lower_name = item.name.toLowerCase(); + return ( searchTerms.length === 0 || searchTerms.every( (term) => - item.name.toLowerCase().includes(term) || - lower.includes(term) + lower_name.includes(term) || lower_type.includes(term) ) - ) + ); + }) .map((server) => ({ key: type + "-" + server.name, label: server.name, @@ -183,7 +204,57 @@ const useOmniItems = ( ]; }) ), - }), - [user, resources, search] + }; + }, [user, resources, search]); +}; + +const OmniContainers = ({ + search, + closeSearch, +}: { + search: string; + closeSearch: () => void; +}) => { + const _containers = useRead("ListAllDockerContainers", {}).data; + const containers = useMemo(() => { + return _containers?.filter((c) => { + const searchTerms = search + .toLowerCase() + .split(" ") + .filter((term) => term); + if (searchTerms.length === 0) return true; + const lower = c.name.toLowerCase(); + return searchTerms.every( + (term) => lower.includes(term) || "containers".includes(term) + ); + }); + }, [_containers, search]); + const navigate = useNavigate(); + if ((containers?.length ?? 0) < 1) return null; + return ( + <> + + + {containers?.map((container) => ( + { + closeSearch(); + navigate( + `/servers/${container.server_id!}/container/${container.name}` + ); + }} + > + + {container.name} + + ))} + + ); }; diff --git a/frontend/src/pages/containers.tsx b/frontend/src/pages/containers.tsx index 5aa059653..f2d06fa5f 100644 --- a/frontend/src/pages/containers.tsx +++ b/frontend/src/pages/containers.tsx @@ -10,7 +10,10 @@ import { Fragment, useCallback, useMemo, useState } from "react"; export const ContainersPage = () => { const [search, setSearch] = useState(""); - const searchSplit = search.toLowerCase().split(" "); + const searchSplit = search + .toLowerCase() + .split(" ") + .filter((term) => term); const servers = useRead("ListServers", {}).data; const serverName = useCallback( (id: string) => servers?.find((server) => server.id === id)?.name, @@ -21,7 +24,8 @@ export const ContainersPage = () => { () => _containers?.filter((c) => { if (searchSplit.length === 0) return true; - return searchSplit.every((search) => c.name.includes(search)); + const lower = c.name.toLowerCase(); + return searchSplit.every((search) => lower.includes(search)); }), [_containers, searchSplit] );