Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: projects page wont load if no stacks are found
Kyle Mendell320edc9596ef
diff --git a/backend/internal/api/stack_handler.go b/backend/internal/api/stack_handler.goindex fb1c53ab1..303c05480 100644--- a/backend/internal/api/stack_handler.go+++ b/backend/internal/api/stack_handler.go@@ -62,6 +62,11 @@ func (h *StackHandler) ListStacks(c *gin.Context) {return}+ // Ensure data is never null - always return empty array if no stacks+ if stacks == nil {+ stacks = []map[string]interface{}{}+ }+c.JSON(http.StatusOK, gin.H{"success": true,"data": stacks,diff --git a/backend/internal/services/stack_service.go b/backend/internal/services/stack_service.goindex 99abf8f05..4d1142409 100644--- a/backend/internal/services/stack_service.go+++ b/backend/internal/services/stack_service.go@@ -446,22 +446,37 @@ processResult:return result, pagination, nil}-// SyncAllStacksFromFilesystem scans the stacks directory and ensures database is in syncfunc (s *StackService) SyncAllStacksFromFilesystem(ctx context.Context) error {- stacksDir, err := s.getStacksDirectory(ctx)- if err != nil {- return fmt.Errorf("failed to get stacks directory: %w", err)+ stacksDir, dirErr := s.getStacksDirectory(ctx)+ if dirErr != nil {+ fmt.Printf("Warning: failed to get stacks directory from settings, falling back to default: %v\n", dirErr)+ }+ if strings.TrimSpace(stacksDir) == "" {+ stacksDir = "data/projects"+ }+ stacksDir = filepath.Clean(stacksDir)++ // If the stacks directory doesn't exist, create it and treat as empty.+ if _, statErr := os.Stat(stacksDir); os.IsNotExist(statErr) {+ if mkErr := os.MkdirAll(stacksDir, 0755); mkErr != nil {+ fmt.Printf("Warning: failed to create stacks directory %q: %v\n", stacksDir, mkErr)+ return nil // treat as empty+ }+ return nil // created; nothing to sync+ } else if statErr != nil {+ fmt.Printf("Warning: unable to access stacks directory %q: %v\n", stacksDir, statErr)+ return nil // treat as empty}entries, err := os.ReadDir(stacksDir)if err != nil {- return fmt.Errorf("failed to read stacks directory: %w", err)+ fmt.Printf("Warning: failed to read stacks directory %q: %v\n", stacksDir, err)+ return nil // treat as empty}// Track which directories we've seen- seenDirs := make(map[string]bool)+ seenDirs := utils.NewEmptyStructMap[string]()- // Process each directory in the stacks folderfor _, entry := range entries {if !entry.IsDir() {continue@@ -469,7 +484,7 @@ func (s *StackService) SyncAllStacksFromFilesystem(ctx context.Context) error {dirName := entry.Name()dirPath := filepath.Join(stacksDir, dirName)- seenDirs[dirPath] = true+ seenDirs[dirPath] = struct{}{}// Skip if no compose fileif s.findComposeFile(dirPath) == "" {@@ -481,26 +496,60 @@ func (s *StackService) SyncAllStacksFromFilesystem(ctx context.Context) error {err := s.db.WithContext(ctx).Where("path = ? OR dir_name = ?", dirPath, dirName).First(&existingStack).Errorif errors.Is(err, gorm.ErrRecordNotFound) {- // Auto-import external stackif _, importErr := s.importExternalStack(ctx, dirName, dirName, systemUser); importErr != nil {fmt.Printf("Warning: failed to auto-import stack %s: %v\n", dirName, importErr)}} else if err == nil {- // Update existing stack with live datas.syncStackWithFilesystem(ctx, &existingStack)}}- // Mark stacks as "not found" if their directories no longer exist+ // Remove stacks whose directories or compose files no longer existvar allStacks []models.Stacks.db.WithContext(ctx).Find(&allStacks)for _, stack := range allStacks {- if !seenDirs[stack.Path] {- stack.Status = "unknown"- stack.ServiceCount = 0- stack.RunningCount = 0- s.updateStackInDB(ctx, &stack)+ // Directory missing+ if _, err := os.Stat(stack.Path); os.IsNotExist(err) {+ if err := s.db.WithContext(ctx).Where("stack_id = ?", stack.ID).Delete(&models.ProjectCache{}).Error; err != nil {+ fmt.Printf("Warning: failed to delete cache for removed stack %s: %v\n", stack.ID, err)+ }+ if err := s.db.WithContext(ctx).Delete(&models.Stack{}, "id = ?", stack.ID).Error; err != nil {+ fmt.Printf("Warning: failed to delete removed stack %s: %v\n", stack.ID, err)+ } else {+ metadata := models.JSON{+ "action": "auto-delete",+ "stackId": stack.ID,+ "stackName": stack.Name,+ "path": stack.Path,+ "reason": "missing_directory",+ }+ if logErr := s.eventService.LogStackEvent(ctx, models.EventTypeStackDelete, stack.ID, stack.Name, systemUser.ID, systemUser.Username, "0", metadata); logErr != nil {+ fmt.Printf("Could not log auto-delete action: %s\n", logErr)+ }+ }+ continue+ }++ if s.findComposeFile(stack.Path) == "" {+ if err := s.db.WithContext(ctx).Where("stack_id = ?", stack.ID).Delete(&models.ProjectCache{}).Error; err != nil {+ fmt.Printf("Warning: failed to delete cache for removed stack %s: %v\n", stack.ID, err)+ }+ if err := s.db.WithContext(ctx).Delete(&models.Stack{}, "id = ?", stack.ID).Error; err != nil {+ fmt.Printf("Warning: failed to delete removed stack %s: %v\n", stack.ID, err)+ } else {+ metadata := models.JSON{+ "action": "auto-delete",+ "stackId": stack.ID,+ "stackName": stack.Name,+ "path": stack.Path,+ "reason": "missing_compose_file",+ }+ if logErr := s.eventService.LogStackEvent(ctx, models.EventTypeStackDelete, stack.ID, stack.Name, systemUser.ID, systemUser.Username, "0", metadata); logErr != nil {+ fmt.Printf("Could not log auto-delete action: %s\n", logErr)+ }+ }+ continue}}diff --git a/backend/internal/utils/struct_map_util.go b/backend/internal/utils/struct_map_util.gonew file mode 100644index 000000000..66ddf5bbd--- /dev/null+++ b/backend/internal/utils/struct_map_util.go@@ -0,0 +1,41 @@+package utils++type Set[T comparable] map[T]struct{}++func NewSet[T comparable](vals ...T) Set[T] {+ s := make(Set[T])+ for _, v := range vals {+ s[v] = struct{}{}+ }+ return s+}++func (s Set[T]) Add(vals ...T) {+ for _, v := range vals {+ s[v] = struct{}{}+ }+}++func (s Set[T]) Has(v T) bool {+ _, ok := s[v]+ return ok+}++func (s Set[T]) Remove(vals ...T) {+ for _, v := range vals {+ delete(s, v)+ }+}++func (s Set[T]) Items() []T {+ out := make([]T, 0, len(s))+ for v := range s {+ out = append(out, v)+ }+ return out+}++// NewEmptyStructMap returns map[K]struct{}{}+func NewEmptyStructMap[K comparable]() map[K]struct{} {+ return make(map[K]struct{})+}diff --git a/frontend/src/lib/constants.ts b/frontend/src/lib/constants.tsindex 4379b7e35..1c75b6897 100644--- a/frontend/src/lib/constants.ts+++ b/frontend/src/lib/constants.ts@@ -19,9 +19,4 @@ volumes:driver: local`;-/* The line `const DEFAULT_NETWORK_NAMES = new Set(['host', 'bridge', 'none', 'ingress']);` is creating-a Set named `DEFAULT_NETWORK_NAMES` that contains the default network names managed by Docker. These-default network names are 'host', 'bridge', 'none', and 'ingress'. The purpose of this set is to-provide a quick and efficient way to check if a given network name is one of the default networks-when needed in the code. */export const DEFAULT_NETWORK_NAMES = new Set(['host', 'bridge', 'none', 'ingress']);diff --git a/frontend/src/lib/dto/user-dto.ts b/frontend/src/lib/dto/user-dto.tsdeleted file mode 100644index aef334364..000000000--- a/frontend/src/lib/dto/user-dto.ts+++ /dev/null@@ -1,18 +0,0 @@-import type { UserRole } from '../types/user.type';--export interface UserDto {- username: string;- email?: string;- password: string;- displayName?: string;- role: UserRole;- permissions?: string[];-}--export interface UpdateUserDto {- email?: string;- displayName?: string;- role?: UserRole;- permissions?: string[];- isActive?: boolean;-}diff --git a/frontend/src/lib/types/user.type.ts b/frontend/src/lib/types/user.type.tsindex 12fa119a5..c93fe25f5 100644--- a/frontend/src/lib/types/user.type.ts+++ b/frontend/src/lib/types/user.type.ts@@ -27,24 +27,21 @@ export interface Permission {description?: string;}-export interface UserProfile {- avatar?: string;- bio?: string;- preferences: UserPreferences;-}--export interface UserPreferences {- theme: 'light' | 'dark' | 'auto';- language: string;- timezone: string;- notifications: NotificationPreferences;+export interface UserDto {+ username: string;+ email?: string;+ password: string;+ displayName?: string;+ role: UserRole;+ permissions?: string[];}-export interface NotificationPreferences {- email: boolean;- browser: boolean;- deployments: boolean;- systemAlerts: boolean;+export interface UpdateUserDto {+ email?: string;+ displayName?: string;+ role?: UserRole;+ permissions?: string[];+ isActive?: boolean;}export type CreateUser = Omit<