Skip to content

Commit

Permalink
fix code download issue
Browse files Browse the repository at this point in the history
Signed-off-by: allenshen <[email protected]>
  • Loading branch information
AllenShen committed Dec 26, 2023
1 parent a2fb7a5 commit 922571d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion pkg/microservice/aslan/core/service/service/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"text/template"
"time"

fileutil "github.com/koderover/zadig/v2/pkg/cli/zadig-agent/util/file"

"github.com/27149chen/afero"
"github.com/otiai10/copy"
"github.com/pkg/errors"
Expand Down Expand Up @@ -254,7 +256,6 @@ func GetProductionHelmServiceFilePath(serviceName, productName string, revision
return GetProductionHelmFilePath(productName, serviceName, revision, dir)
}

// TODO add production parameter
func GetFileContent(serviceName, productName string, param *GetFileContentParam, log *zap.SugaredLogger) (string, error) {
filePath, fileName, revision, forDelivery := param.FilePath, param.FileName, param.Revision, param.DeliveryVersion
svc, err := commonrepo.NewServiceColl().Find(&commonrepo.ServiceFindOption{
Expand Down Expand Up @@ -283,12 +284,24 @@ func GetFileContent(serviceName, productName string, param *GetFileContentParam,
}

if forDelivery {
originBase := base
base = config.LocalDeliveryChartPathWithRevision(productName, serviceName, revision)
os.RemoveAll(base)
if exists, err := fileutil.FileExists(base); !exists || err != nil {
fullPath := filepath.Join(originBase, svc.ServiceName)
log.Infof("----- copy source svc chart from %s to %s", fullPath, filepath.Join(base, svc.ServiceName))
err := copy.Copy(fullPath, filepath.Join(base, svc.ServiceName))
if err != nil {
return "", err
}
}

}

file := filepath.Join(base, serviceName, filePath, fileName)
fileContent, err := os.ReadFile(file)
if err != nil {

log.Errorf("Failed to read file %s, err: %s", file, err)
return "", e.ErrFileContent.AddDesc(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/microservice/aslan/core/service/service/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func preloadGiteeService(detail *systemconfig.CodeHost, repoOwner, repoName, bra
base := path.Join(config.S3StoragePath(), repoName)
if exist, err := util.PathExists(base); !exist {
log.Warnf("path does not exist,err:%s", err)
log.Infof("------- start run git commands, %s %s %s %s %s %s", repoOwner, repoName, branchName, remoteName, base, loadPath)
//log.Infof("------- start run git commands, %s %s %s %s %s %s", repoOwner, repoName, branchName, remoteName, base, loadPath)
err = command.RunGitCmds(detail, repoOwner, repoOwner, repoName, branchName, remoteName)
if err != nil {
return nil, e.ErrPreloadServiceTemplate.AddDesc(fmt.Sprintf("failed to clone code, err: %s", err.Error()))
Expand Down

0 comments on commit 922571d

Please sign in to comment.