Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package deploy

import (
"fmt"
"os"
"time"

"github.com/deviantony/pctl/internal/build"
"github.com/deviantony/pctl/internal/compose"
Expand All @@ -12,6 +14,7 @@ import (

"github.com/charmbracelet/lipgloss"
"github.com/spf13/cobra"
"golang.org/x/term"
)

var (
Expand Down Expand Up @@ -98,16 +101,43 @@ func runDeploy(cmd *cobra.Command, args []string) error {
// Create Portainer client
client := portainer.NewClientWithTLS(cfg.PortainerURL, cfg.APIToken, cfg.SkipTLSVerify)

// Create build logger (use dashboard if interactive terminal with multiple services)
var logger build.BuildLogger = build.NewStyledBuildLogger("BUILD")
var dashboard *build.BuildDashboard

if term.IsTerminal(int(os.Stdout.Fd())) && len(servicesWithBuild) > 1 {
// Extract service names for dashboard
serviceNames := make([]string, len(servicesWithBuild))
for i, svc := range servicesWithBuild {
serviceNames[i] = svc.ServiceName
}

// Create and start passive TUI dashboard
dashboard = build.NewBuildDashboard(serviceNames)
logger = build.NewDashboardBuildLogger(dashboard)
dashboard.Start()
}

// Create build orchestrator
logger := build.NewStyledBuildLogger("BUILD")
orchestrator := build.NewBuildOrchestrator(client, buildConfig, cfg.EnvironmentID, cfg.StackName, logger)

// Build services
imageTags, err := orchestrator.BuildServices(servicesWithBuild)
if err != nil {
// Stop dashboard before returning error
if dashboard != nil {
time.Sleep(build.DashboardErrorDisplayDuration)
dashboard.Stop()
}
return fmt.Errorf("build failed: %w", err)
}

// Keep dashboard visible for a moment before stopping
if dashboard != nil {
time.Sleep(build.DashboardSuccessDisplayDuration)
dashboard.Stop()
}
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dashboard initialization and lifecycle management logic (lines 104-139) is duplicated between cmd/deploy/deploy.go and cmd/redeploy/redeploy.go. Consider extracting this logic into a shared helper function in the internal/build package to reduce code duplication and improve maintainability. For example:

// In internal/build/dashboard.go
func CreateDashboardLogger(servicesWithBuild []compose.ServiceBuildInfo) (BuildLogger, *BuildDashboard) {
    if term.IsTerminal(int(os.Stdout.Fd())) && len(servicesWithBuild) > 1 {
        serviceNames := make([]string, len(servicesWithBuild))
        for i, svc := range servicesWithBuild {
            serviceNames[i] = svc.ServiceName
        }
        dashboard := NewBuildDashboard(serviceNames)
        logger := NewDashboardBuildLogger(dashboard)
        dashboard.Start()
        return logger, dashboard
    }
    return NewStyledBuildLogger("BUILD"), nil
}

Copilot uses AI. Check for mistakes.

// Transform compose file
transformer, err := compose.TransformComposeFile(composeContent, imageTags)
if err != nil {
Expand Down
32 changes: 31 additions & 1 deletion cmd/redeploy/redeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package redeploy

import (
"fmt"
"os"
"time"

"github.com/deviantony/pctl/internal/build"
"github.com/deviantony/pctl/internal/compose"
Expand All @@ -12,6 +14,7 @@ import (

"github.com/charmbracelet/lipgloss"
"github.com/spf13/cobra"
"golang.org/x/term"
)

var (
Expand Down Expand Up @@ -111,16 +114,43 @@ func runRedeploy(cmd *cobra.Command, args []string) error {
// Create Portainer client
client := portainer.NewClientWithTLS(cfg.PortainerURL, cfg.APIToken, cfg.SkipTLSVerify)

// Create build logger (use dashboard if interactive terminal with multiple services)
var logger build.BuildLogger = build.NewStyledBuildLogger("BUILD")
var dashboard *build.BuildDashboard

if term.IsTerminal(int(os.Stdout.Fd())) && len(servicesWithBuild) > 1 {
// Extract service names for dashboard
serviceNames := make([]string, len(servicesWithBuild))
for i, svc := range servicesWithBuild {
serviceNames[i] = svc.ServiceName
}

// Create and start passive TUI dashboard
dashboard = build.NewBuildDashboard(serviceNames)
logger = build.NewDashboardBuildLogger(dashboard)
dashboard.Start()
}

// Create build orchestrator
logger := build.NewStyledBuildLogger("BUILD")
orchestrator := build.NewBuildOrchestrator(client, buildConfig, cfg.EnvironmentID, cfg.StackName, logger)

// Build services
imageTags, err := orchestrator.BuildServices(servicesWithBuild)
if err != nil {
// Stop dashboard before returning error
if dashboard != nil {
time.Sleep(build.DashboardErrorDisplayDuration)
dashboard.Stop()
}
return fmt.Errorf("build failed: %w", err)
}

// Keep dashboard visible for a moment before stopping
if dashboard != nil {
time.Sleep(build.DashboardSuccessDisplayDuration)
dashboard.Stop()
}

// Transform compose file
transformer, err := compose.TransformComposeFile(composeContent, imageTags)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/charmbracelet/lipgloss v1.1.0
github.com/spf13/cobra v1.10.1
github.com/stretchr/testify v1.11.1
golang.org/x/term v0.28.0
gopkg.in/yaml.v3 v3.0.1
)

Expand Down
Loading
Loading