Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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(1 * time.Second)
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.

[nitpick] The hardcoded sleep durations (1 second on error, 2 seconds on success) are magic numbers that make the code less maintainable. Consider:

  1. Defining these as named constants at the package level (e.g., dashboardErrorDisplayDuration, dashboardSuccessDisplayDuration)
  2. Making them configurable if user experience feedback suggests different timing would be better

This would improve code readability and make it easier to adjust these values in the future.

Copilot uses AI. Check for mistakes.
dashboard.Stop()
}
return fmt.Errorf("build failed: %w", err)
}

// Keep dashboard visible for a moment before stopping
if dashboard != nil {
time.Sleep(2 * time.Second)
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.

[nitpick] The hardcoded sleep durations (1 second on error, 2 seconds on success) are magic numbers that make the code less maintainable. Consider:

  1. Defining these as named constants at the package level (e.g., dashboardErrorDisplayDuration, dashboardSuccessDisplayDuration)
  2. Making them configurable if user experience feedback suggests different timing would be better

This would improve code readability and make it easier to adjust these values in the future.

Copilot uses AI. Check for mistakes.
dashboard.Stop()
}

// 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(1 * time.Second)
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.

[nitpick] The hardcoded sleep durations (1 second on error, 2 seconds on success) are magic numbers that make the code less maintainable. Consider:

  1. Defining these as named constants at the package level (e.g., dashboardErrorDisplayDuration, dashboardSuccessDisplayDuration)
  2. Making them configurable if user experience feedback suggests different timing would be better

This would improve code readability and make it easier to adjust these values in the future.

Copilot uses AI. Check for mistakes.
dashboard.Stop()
}
return fmt.Errorf("build failed: %w", err)
}

// Keep dashboard visible for a moment before stopping
if dashboard != nil {
time.Sleep(2 * time.Second)
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.

[nitpick] The hardcoded sleep durations (1 second on error, 2 seconds on success) are magic numbers that make the code less maintainable. Consider:

  1. Defining these as named constants at the package level (e.g., dashboardErrorDisplayDuration, dashboardSuccessDisplayDuration)
  2. Making them configurable if user experience feedback suggests different timing would be better

This would improve code readability and make it easier to adjust these values in the future.

Copilot uses AI. Check for mistakes.
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