From ae31af8f314c397d8e1020e7d8392118e201f8eb Mon Sep 17 00:00:00 2001 From: Rizul Date: Sat, 26 Aug 2023 10:56:17 +0530 Subject: [PATCH] change path string --- go.mod | 2 ++ go.sum | 1 + lib/utils/os.go | 11 ++++++++++- services/challengedeployerservice/controller.go | 4 ++-- services/infrasetservice/helper.go | 3 ++- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index b969d922..8c476420 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.7.0 + github.com/stretchr/testify v1.8.4 github.com/xdg-go/pbkdf2 v1.0.0 go.mongodb.org/mongo-driver v1.12.1 golang.org/x/crypto v0.12.0 @@ -74,6 +75,7 @@ require ( github.com/pierrec/lz4/v4 v4.1.18 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.4.4 // indirect github.com/sergi/go-diff v1.3.1 // indirect github.com/skeema/knownhosts v1.2.0 // indirect diff --git a/go.sum b/go.sum index d2a4749a..05678f8a 100644 --- a/go.sum +++ b/go.sum @@ -197,6 +197,7 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8= diff --git a/lib/utils/os.go b/lib/utils/os.go index b764c215..31fe2691 100644 --- a/lib/utils/os.go +++ b/lib/utils/os.go @@ -40,7 +40,7 @@ func Tar(src string, writers ...io.Writer) error { return err } - header.Name = strings.TrimPrefix("./"+file, src+string(filepath.Separator)) + header.Name = strings.TrimPrefix(file, src+string(filepath.Separator)) if err := tw.WriteHeader(header); err != nil { return err } @@ -69,3 +69,12 @@ func RunCommand(cmd string) error { return nil } + +func GetPath() (string, error) { + katanaDir, err := os.Getwd() + if err != nil { + fmt.Println("Error:", err) + return "", nil + } + return katanaDir, nil +} diff --git a/services/challengedeployerservice/controller.go b/services/challengedeployerservice/controller.go index 1814c447..1bb57de7 100644 --- a/services/challengedeployerservice/controller.go +++ b/services/challengedeployerservice/controller.go @@ -135,12 +135,12 @@ func ChallengeUpdate(c *fiber.Ctx) error { if err != nil { log.Println("Error pulling changes:", err) } - + katanaDir, err := utils.GetPath() imageName := strings.Replace(dir, "/", "-", -1) log.Println("Pull successful for", teamName, ". Building image...") firstPatch := !utils.DockerImageExists(imageName) - utils.BuildDockerImage(imageName, "./teams/"+dir) + utils.BuildDockerImage(imageName, katanaDir+"/teams/"+dir) if firstPatch { log.Println("First Patch for", teamName) diff --git a/services/infrasetservice/helper.go b/services/infrasetservice/helper.go index 036bfbfc..c6a90f1a 100644 --- a/services/infrasetservice/helper.go +++ b/services/infrasetservice/helper.go @@ -94,7 +94,8 @@ func envVariables(gogs string, pwd string, podNamespace string) { } func buildKatanaServices() { - katanaServicesDir := "./katana-services" + katanaDir, err := utils.GetPath() + katanaServicesDir := katanaDir + "/katana-services" services, err := os.ReadDir(katanaServicesDir) if err != nil {