From 989854a5eda21e254088589879ddff79faf76dc3 Mon Sep 17 00:00:00 2001 From: Ebtasam Faridy Date: Fri, 18 Jul 2025 23:26:10 +0530 Subject: [PATCH 1/4] feat: [CI-18088]: adding some changes removing not needed ones --- engine/exec/exec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/exec/exec.go b/engine/exec/exec.go index 6b97d686..25549f35 100644 --- a/engine/exec/exec.go +++ b/engine/exec/exec.go @@ -45,7 +45,7 @@ func Run(ctx context.Context, step *spec.Step, output io.Writer) (*runtime.State cmd.Stdout = output startTime := time.Now() - logrus.WithContext(ctx).Infoln(fmt.Sprintf("Starting command on host for step %s %s", step.ID, step.Name)) + logrus.WithContext(ctx).Infoln(fmt.Sprintf("Starting command on host for step please get ready %s %s", step.ID, step.Name)) if err := cmd.Start(); err != nil { return nil, err } From 7af4b706fc415256d09466da9c55717d34ef84d5 Mon Sep 17 00:00:00 2001 From: Ebtasam Faridy Date: Fri, 8 Aug 2025 21:07:31 +0530 Subject: [PATCH 2/4] feat: [CI-18088]: adding netrc file in lite engine as home is not set earlier --- engine/exec/exec.go | 2 +- handler/setup.go | 55 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/engine/exec/exec.go b/engine/exec/exec.go index 25549f35..6b97d686 100644 --- a/engine/exec/exec.go +++ b/engine/exec/exec.go @@ -45,7 +45,7 @@ func Run(ctx context.Context, step *spec.Step, output io.Writer) (*runtime.State cmd.Stdout = output startTime := time.Now() - logrus.WithContext(ctx).Infoln(fmt.Sprintf("Starting command on host for step please get ready %s %s", step.ID, step.Name)) + logrus.WithContext(ctx).Infoln(fmt.Sprintf("Starting command on host for step %s %s", step.ID, step.Name)) if err := cmd.Start(); err != nil { return nil, err } diff --git a/handler/setup.go b/handler/setup.go index f9be62d1..a0f38be9 100644 --- a/handler/setup.go +++ b/handler/setup.go @@ -7,8 +7,10 @@ package handler import ( "context" "encoding/json" + "fmt" "net/http" "os" + "path/filepath" "runtime" "time" @@ -26,7 +28,45 @@ var ( harnessEnableDebugLogs = "HARNESS_ENABLE_DEBUG_LOGS" ) +const OSWindows = "windows" +const OSLinux = "linux" +const OSMac = "darwin" +const ArchAMD64 = "amd64" +const ArchARM64 = "arm64" + // HandleExecuteStep returns an http.HandlerFunc that executes a step + +func GetNetrc(os string) string { + switch os { + case OSWindows: + return "_netrc" + default: + return ".netrc" + } +} + +func GetNetrcFile(goOS string, env map[string]string) (*spec.File, error) { + netrcName := GetNetrc(goOS) + homeDir, err := os.UserHomeDir() + if err != nil { + // Log error but return nil so caller can skip adding the file + fmt.Printf("Error getting home directory: %v\n", err) + return nil, err + } + + path := filepath.Join(homeDir, netrcName) + fmt.Printf("home path: %s", path) + + data := fmt.Sprintf("machine %s\nlogin %s\npassword %s\n", env["DRONE_NETRC_MACHINE"], env["DRONE_NETRC_USERNAME"], env["DRONE_NETRC_PASSWORD"]) + + return &spec.File{ + Path: path, + Mode: 777, + IsDir: false, + Data: data, + }, nil +} + func HandleSetup(engine *engine.Engine) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { st := time.Now() @@ -51,6 +91,21 @@ func HandleSetup(engine *engine.Engine) http.HandlerFunc { s.Volumes = append(s.Volumes, getDockerSockVolume()) } s.Volumes = append(s.Volumes, getSharedVolume()) + + + netrcFile, err := GetNetrcFile(OSLinux, s.Envs) + if err != nil { + fmt.Printf("Skipping netrc file creation: %v\n", err) + } else { + s.Files = append(s.Files, netrcFile) + } + + b, _ := json.MarshalIndent(s, "", " ") + + logger.FromRequest(r). + WithField("request: ", string(b)). + Infoln("here1: request after appending shared volume") + cfg := &spec.PipelineConfig{ Envs: s.Envs, Network: s.Network, From 6809f969570a897396111d7f66c373d78695fa36 Mon Sep 17 00:00:00 2001 From: Ebtasam Faridy Date: Fri, 8 Aug 2025 21:18:55 +0530 Subject: [PATCH 3/4] feat: [CI-18088]: removing logs --- handler/setup.go | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/handler/setup.go b/handler/setup.go index a0f38be9..25135f86 100644 --- a/handler/setup.go +++ b/handler/setup.go @@ -49,13 +49,11 @@ func GetNetrcFile(goOS string, env map[string]string) (*spec.File, error) { netrcName := GetNetrc(goOS) homeDir, err := os.UserHomeDir() if err != nil { - // Log error but return nil so caller can skip adding the file fmt.Printf("Error getting home directory: %v\n", err) return nil, err } path := filepath.Join(homeDir, netrcName) - fmt.Printf("home path: %s", path) data := fmt.Sprintf("machine %s\nlogin %s\npassword %s\n", env["DRONE_NETRC_MACHINE"], env["DRONE_NETRC_USERNAME"], env["DRONE_NETRC_PASSWORD"]) @@ -92,20 +90,15 @@ func HandleSetup(engine *engine.Engine) http.HandlerFunc { } s.Volumes = append(s.Volumes, getSharedVolume()) - - netrcFile, err := GetNetrcFile(OSLinux, s.Envs) - if err != nil { - fmt.Printf("Skipping netrc file creation: %v\n", err) - } else { - s.Files = append(s.Files, netrcFile) + if val, ok := s.Envs["DRONE_PERSIST_CREDS"]; ok && val == "true" { + netrcFile, err := GetNetrcFile(OSLinux, s.Envs) + if err != nil { + fmt.Printf("Skipping netrc file creation: %v\n", err) + } else { + s.Files = append(s.Files, netrcFile) + } } - b, _ := json.MarshalIndent(s, "", " ") - - logger.FromRequest(r). - WithField("request: ", string(b)). - Infoln("here1: request after appending shared volume") - cfg := &spec.PipelineConfig{ Envs: s.Envs, Network: s.Network, From adee2d4ab166796b7c8fbfd6f6b5d097edb84b1b Mon Sep 17 00:00:00 2001 From: Ebtasam Faridy Date: Fri, 8 Aug 2025 21:22:38 +0530 Subject: [PATCH 4/4] feat: [CI-18088]: removing logs --- handler/setup.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/handler/setup.go b/handler/setup.go index 25135f86..aed1bbdb 100644 --- a/handler/setup.go +++ b/handler/setup.go @@ -31,10 +31,6 @@ var ( const OSWindows = "windows" const OSLinux = "linux" const OSMac = "darwin" -const ArchAMD64 = "amd64" -const ArchARM64 = "arm64" - -// HandleExecuteStep returns an http.HandlerFunc that executes a step func GetNetrc(os string) string { switch os { @@ -45,8 +41,8 @@ func GetNetrc(os string) string { } } -func GetNetrcFile(goOS string, env map[string]string) (*spec.File, error) { - netrcName := GetNetrc(goOS) +func GetNetrcFile(env map[string]string) (*spec.File, error) { + netrcName := GetNetrc(runtime.GOOS) homeDir, err := os.UserHomeDir() if err != nil { fmt.Printf("Error getting home directory: %v\n", err) @@ -65,6 +61,7 @@ func GetNetrcFile(goOS string, env map[string]string) (*spec.File, error) { }, nil } +// HandleExecuteStep returns an http.HandlerFunc that executes a step func HandleSetup(engine *engine.Engine) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { st := time.Now() @@ -91,7 +88,7 @@ func HandleSetup(engine *engine.Engine) http.HandlerFunc { s.Volumes = append(s.Volumes, getSharedVolume()) if val, ok := s.Envs["DRONE_PERSIST_CREDS"]; ok && val == "true" { - netrcFile, err := GetNetrcFile(OSLinux, s.Envs) + netrcFile, err := GetNetrcFile(s.Envs) if err != nil { fmt.Printf("Skipping netrc file creation: %v\n", err) } else {