Skip to content

Commit

Permalink
fix: upload image tar build component failure
Browse files Browse the repository at this point in the history
Signed-off-by: 张启航 <[email protected]>
  • Loading branch information
ZhangSetSail committed Nov 15, 2024
1 parent 82af1cc commit 115be07
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion api/handler/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func saveMetadata(tr *model.ExportAppStruct) error {
logrus.Error("Failed to save metadata", err)
return err
}
err = storage.Default().StorageCli.CopyFileWithProgress(path.Join(tr.SourceDir, "metadata.json"), path.Join(tr.SourceDir, "metadata.json"), nil)
err = storage.Default().StorageCli.UploadFileToFile(path.Join(tr.SourceDir, "metadata.json"), path.Join(tr.SourceDir, "metadata.json"), nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion builder/exector/build_from_market_slug.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (i *MarketSlugItem) Run() error {
return nil
}
} else {
if err := storage.Default().StorageCli.CopyFileWithProgress(i.SlugInfo.SlugPath, i.TGZPath, i.Logger); err != nil {
if err := storage.Default().StorageCli.UploadFileToFile(i.SlugInfo.SlugPath, i.TGZPath, i.Logger); err != nil {
i.Logger.Error("源码包本地获取失败,安装失败", map[string]string{"step": "slug-share", "status": "failure"})
logrus.Errorf("copy slug file error when build service, %s", err.Error())
return nil
Expand Down
2 changes: 1 addition & 1 deletion builder/exector/export_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (i *ExportApp) Run(timeout time.Duration) error {
if re != nil {
// move package file to download dir
downloadPath := path.Dir(i.SourceDir)
err = storage.Default().StorageCli.CopyFileWithProgress(re.PackagePath, path.Join(downloadPath, re.PackageName), nil)
err = storage.Default().StorageCli.UploadFileToFile(re.PackagePath, path.Join(downloadPath, re.PackageName), nil)
if err != nil {
return errors.New("copy file with progress failure: %v" + err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion builder/exector/groupapp_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func (b *BackupAPPNew) checkVersionExist(version *dbmodel.VersionInfo) (bool, er
func (b *BackupAPPNew) saveSlugPkg(app *RegionServiceSnapshot, version *dbmodel.VersionInfo) error {
dstDir := fmt.Sprintf("%s/app_%s/slug_%s.tgz", b.SourceDir, app.ServiceID, version.BuildVersion)
util.CheckAndCreateDir(filepath.Dir(dstDir))
if err := storage.Default().StorageCli.CopyFileWithProgress(version.DeliveredPath, dstDir, b.Logger); err != nil {
if err := storage.Default().StorageCli.UploadFileToFile(version.DeliveredPath, dstDir, b.Logger); err != nil {
b.Logger.Error(util.Translation("push slug file to local dir error"), map[string]string{"step": "backup_builder", "status": "failure"})
logrus.Errorf("copy slug file error when backup app, %s", err.Error())
return err
Expand Down
2 changes: 1 addition & 1 deletion builder/exector/groupapp_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func (b *BackupAPPRestore) getOldServiceID(new string) string {
}
func (b *BackupAPPRestore) downloadSlug(backup *dbmodel.AppBackup, app *RegionServiceSnapshot, version *dbmodel.VersionInfo) error {
dstDir := fmt.Sprintf("%s/app_%s/slug_%s.tgz", b.cacheDir, b.getOldServiceID(app.ServiceID), version.BuildVersion)
if err := storage.Default().StorageCli.CopyFileWithProgress(dstDir, version.DeliveredPath, b.Logger); err != nil {
if err := storage.Default().StorageCli.UploadFileToFile(dstDir, version.DeliveredPath, b.Logger); err != nil {
b.Logger.Error(util.Translation("down slug file from local dir error"), map[string]string{"step": "restore_builder", "status": "failure"})
logrus.Errorf("copy slug file error when backup app, %s", err.Error())
return err
Expand Down
4 changes: 2 additions & 2 deletions builder/exector/share_slug.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ func (i *SlugShareItem) ShareToLocal() error {
i.Logger.Error("生成md5失败", map[string]string{"step": "slug-share", "status": "success"})
return err
}
if err := storage.Default().StorageCli.CopyFileWithProgress(i.LocalSlugPath, i.SlugPath, i.Logger); err != nil {
if err := storage.Default().StorageCli.UploadFileToFile(i.LocalSlugPath, i.SlugPath, i.Logger); err != nil {
os.Remove(i.SlugPath)
logrus.Errorf("copy file to share path error: %s", err.Error())
i.Logger.Error("复制文件失败", map[string]string{"step": "slug-share", "status": "failure"})
return err
}
if err := storage.Default().StorageCli.CopyFileWithProgress(md5, i.SlugPath+".md5", i.Logger); err != nil {
if err := storage.Default().StorageCli.UploadFileToFile(md5, i.SlugPath+".md5", i.Logger); err != nil {
os.Remove(i.SlugPath)
os.Remove(i.SlugPath + ".md5")
logrus.Errorf("copy file to share path error: %s", err.Error())
Expand Down
2 changes: 2 additions & 0 deletions builder/parser/docker_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/goodrain/rainbond/builder/sources"
"github.com/goodrain/rainbond/db/model"
"github.com/goodrain/rainbond/event"
"github.com/goodrain/rainbond/pkg/component/storage"
"github.com/goodrain/rainbond/util"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -99,6 +100,7 @@ func (d *DockerRunOrImageParse) Parse() ParseErrorList {
} else if strings.HasPrefix(d.source, "event") {
eventID := strings.Split(d.source, " ")[1]
tarPath := path.Join("/grdata/package_build/temp/events", eventID)
err := storage.Default().StorageCli.DownloadDirToDir(tarPath, tarPath)
files, _ := filepath.Glob(path.Join(tarPath, "*"))
if len(files) == 1 {
if !strings.HasSuffix(files[0], ".tar") && !strings.HasSuffix(files[0], ".tar.gz") {
Expand Down
2 changes: 1 addition & 1 deletion pkg/component/storage/local_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (l *LocalStorage) SaveFile(fileName string, reader multipart.File) error {
}

// CopyFileWithProgress 复制文件,带进度
func (l *LocalStorage) CopyFileWithProgress(src, dst string, logger event.Logger) error {
func (l *LocalStorage) UploadFileToFile(src, dst string, logger event.Logger) error {
srcFile, err := os.OpenFile(src, os.O_RDONLY, 0644)
if err != nil {
if logger != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/component/storage/s3_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (s3s *S3Storage) SaveFile(fileName string, reader multipart.File) error {
return nil
}

func (s3s *S3Storage) CopyFileWithProgress(src, dst string, logger event.Logger) error {
func (s3s *S3Storage) UploadFileToFile(src, dst string, logger event.Logger) error {
srcFile, err := os.OpenFile(src, os.O_RDONLY, 0644)
if err != nil {
if logger != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/component/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ func Default() *StorageComponent {

type InterfaceStorage interface {
MkdirAll(path string) error
ServeFile(w http.ResponseWriter, r *http.Request, filePath string)
Unzip(archive, target string, currentDirectory bool) error
SaveFile(fileName string, reader multipart.File) error
CopyFileWithProgress(src string, dst string, logger event.Logger) error
ReadDir(dirName string) ([]string, error)
ServeFile(w http.ResponseWriter, r *http.Request, filePath string)
SaveFile(fileName string, reader multipart.File) error
UploadFileToFile(src string, dst string, logger event.Logger) error
DownloadDirToDir(srcDir, dstDir string) error
}

Expand Down

0 comments on commit 115be07

Please sign in to comment.