Skip to content

Commit

Permalink
refactor: Improve deployment and setup processes with enhanced consol…
Browse files Browse the repository at this point in the history
…e output
  • Loading branch information
yarlson committed Dec 2, 2024
1 parent 447877d commit 9fd83be
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
12 changes: 4 additions & 8 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func runDeploy(cmd *cobra.Command, args []string) {
console.Error("Deployment failed:", err)
return
}

sm.Stop()

console.Success("Deployment completed successfully.")
}

func parseConfig(filename string) (*config.Config, error) {
Expand All @@ -62,14 +66,9 @@ func parseConfig(filename string) (*config.Config, error) {

func deployToServers(cfg *config.Config, sm *console.SpinnerManager) error {
for _, server := range cfg.Servers {
spinner := sm.AddSpinner(fmt.Sprintf("deploy-%s", server.Host), fmt.Sprintf("Deploying to server %s", server.Host))

if err := deployToServer(cfg.Project.Name, cfg, server, sm); err != nil {
spinner.ErrorWithMessagef("Failed to deploy to server %s: %v", server.Host, err)
return fmt.Errorf("failed to deploy to server %s: %w", server.Host, err)
}

spinner.Complete()
}

return nil
Expand Down Expand Up @@ -105,16 +104,13 @@ func deployToServer(project string, cfg *config.Config, server config.Server, sm
spinner.Complete()

// Start deployment
spinner = sm.AddSpinner(fmt.Sprintf("deploy-%s", hostname), fmt.Sprintf("[%s] Starting deployment", hostname))
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

if err := deploy.Deploy(ctx, project, cfg); err != nil {
spinner.ErrorWithMessagef("Deployment failed: %v", err)
return err
}

spinner.Complete()
return nil
}

Expand Down
15 changes: 12 additions & 3 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func init() {

func runSetup(cmd *cobra.Command, args []string) {
sm := console.NewSpinnerManager()
sm.Start()
defer sm.Stop()

spinner := sm.AddSpinner("config", "Parsing configuration")

cfg, err := parseConfig("ftl.yaml")
Expand All @@ -44,26 +47,32 @@ func runSetup(cmd *cobra.Command, args []string) {
return
}
spinner.Complete()
sm.Stop()

// Get user password
newUserPassword, err := getUserPassword()
if err != nil {
console.Error("Failed to read password:", err)
return
}
console.ClearPreviousLine()
console.Success("Password set successfully")

sm = console.NewSpinnerManager()
sm.Start()
defer sm.Stop()

// Start server setup
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()

sm.Start()
defer sm.Stop()

if err := server.SetupServers(ctx, cfg, dockerCreds, newUserPassword, sm); err != nil {
console.Error("Setup failed:", err)
return
}

sm.Stop()

console.Success("Server setup completed successfully.")
}

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,5 @@ require (
google.golang.org/grpc v1.68.0 // indirect
google.golang.org/protobuf v1.35.2 // indirect
)

replace github.com/chelnak/ysmrr => github.com/yarlson/ysmrr v0.0.0-20241202064507-f51ced3b0b88
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ github.com/bramvdbogaerde/go-scp v1.5.0 h1:a9BinAjTfQh273eh7vd3qUgmBC+bx+3TRDtkZ
github.com/bramvdbogaerde/go-scp v1.5.0/go.mod h1:on2aH5AxaFb2G0N5Vsdy6B0Ml7k9HuHSwfo1y0QzAbQ=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/chelnak/ysmrr v0.4.0 h1:WMvLGPlBK0kb6wHf5z9FfNvpM6sB9765jy2ajYc1Sfs=
github.com/chelnak/ysmrr v0.4.0/go.mod h1:8vCna4PJsPCb6eevtoG7Tljzfx3twpsO203Qj2gafLM=
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A=
Expand All @@ -33,8 +31,6 @@ github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
Expand Down Expand Up @@ -141,6 +137,8 @@ github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZ
github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY=
github.com/tklauser/numcpus v0.9.0 h1:lmyCHtANi8aRUgkckBgoDk1nHCux3n2cgkJLXdQGPDo=
github.com/tklauser/numcpus v0.9.0/go.mod h1:SN6Nq1O3VychhC1npsWostA+oW+VOQTxZrS604NSRyI=
github.com/yarlson/ysmrr v0.0.0-20241202064507-f51ced3b0b88 h1:UjKkS1MFlrJF515VWjzZOTKhpPBSBT2EYJYLKlS0dho=
github.com/yarlson/ysmrr v0.0.0-20241202064507-f51ced3b0b88/go.mod h1:Eg/IrbWqE3hOD5itwl2GlekRD7um93ap4gHOsxe+KvQ=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package main

import (
"fmt"
"github.com/yarlson/ftl/pkg/console"
"os"
"os/signal"
"syscall"

"github.com/yarlson/ftl/cmd"
"github.com/yarlson/ftl/pkg/console"
)

func main() {
Expand Down
12 changes: 8 additions & 4 deletions pkg/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (

var (
colorReset = "\033[0m"
colorRed = "\033[31m"
colorGreen = "\033[32m"
colorYellow = "\033[33m"
colorRed = "\033[91m" // Bright Red
colorGreen = "\033[92m" // Bright Green
colorYellow = "\033[93m" // Bright Yellow
)

func init() {
Expand All @@ -34,7 +34,7 @@ func Info(a ...interface{}) {
// Success prints a success message.
func Success(a ...interface{}) {
message := fmt.Sprint(a...)
fmt.Printf("%s%s %s\n", colorGreen, colorReset, message)
fmt.Printf("%s%s %s\n", colorGreen, colorReset, message)
}

// Warning prints a warning message.
Expand Down Expand Up @@ -84,3 +84,7 @@ func Print(a ...interface{}) {
func Reset() {
_ = os.Stdout.Sync()
}

func ClearPreviousLine() {
fmt.Print("\033[1A\033[K")
}

0 comments on commit 9fd83be

Please sign in to comment.