From 94ad142edf69459663d6a99396ce9af53d4fdf83 Mon Sep 17 00:00:00 2001 From: Noste <83548733+Noooste@users.noreply.github.com> Date: Sat, 7 Mar 2026 11:13:33 +0100 Subject: [PATCH] feat: add health API to retrieve application version and display in sidebar Signed-off-by: Noste <83548733+Noooste@users.noreply.github.com> --- .github/workflows/build.yml | 1 + Dockerfile | 4 +++- backend/main.go | 2 +- frontend/src/components/layout/sidebar.tsx | 27 ++++++++++++++++++++++ frontend/src/lib/api.ts | 8 +++++++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8b44dcc..94b5e92 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -51,6 +51,7 @@ jobs: context: . platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} + build-args: VERSION=${{ steps.meta.outputs.version }} cache-from: type=gha,scope=build-${{ matrix.platform }} cache-to: type=gha,mode=max,scope=build-${{ matrix.platform }} outputs: type=image,name=${{ secrets.DOCKER_REGISTRY }},push-by-digest=true,name-canonical=true,push=true diff --git a/Dockerfile b/Dockerfile index 74e356a..4dbbd9b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,12 +29,14 @@ RUN --mount=type=cache,target=/go/pkg/mod \ COPY backend . +ARG VERSION=dev + RUN --mount=type=cache,target=/root/.cache/go-build \ swag init RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ - CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -installsuffix cgo -o garage-ui . + CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -installsuffix cgo -ldflags "-X main.version=${VERSION}" -o garage-ui . FROM alpine:3.23.3 diff --git a/backend/main.go b/backend/main.go index 126325a..300270f 100644 --- a/backend/main.go +++ b/backend/main.go @@ -54,7 +54,7 @@ import ( // @name Authorization // @description Type "Bearer" followed by a space and JWT token. -const version = "0.1.0" +var version = "dev" func main() { // Parse command-line flags diff --git a/frontend/src/components/layout/sidebar.tsx b/frontend/src/components/layout/sidebar.tsx index 2cdd40a..c7b846f 100644 --- a/frontend/src/components/layout/sidebar.tsx +++ b/frontend/src/components/layout/sidebar.tsx @@ -3,6 +3,8 @@ import {cn} from '@/lib/utils'; import {Database, Key, LayoutDashboard, LogOut, Server, User} from 'lucide-react'; import {useAuthStore} from '@/store/auth-store'; import {Button} from '@/components/ui/button'; +import { useQuery } from '@tanstack/react-query'; +import { healthApi, garageApi } from '@/lib/api'; interface NavItem { title: string; @@ -46,6 +48,24 @@ export function Sidebar({ isOpen, onClose }: SidebarProps) { logout(); }; + const { data: uiVersion } = useQuery({ + queryKey: ['ui-version'], + queryFn: healthApi.getVersion, + staleTime: 5 * 60 * 1000, + retry: false, + }); + + const { data: nodeInfo } = useQuery({ + queryKey: ['garage-version'], + queryFn: () => garageApi.getNodeInfo('self'), + staleTime: 5 * 60 * 1000, + retry: false, + }); + + const garageVersion = nodeInfo + ? Object.values(nodeInfo.success)[0]?.garageVersion + : undefined; + return (