Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvement by avoiding running commands in docker #254

Merged
merged 1 commit into from
Jul 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,18 @@ Use "fyne-cross <command> -help" for more information about a command.
func cleanTargetDirs(ctx Context, image containerImage) error {

dirs := map[string]string{
"bin": volume.JoinPathContainer(ctx.BinDirContainer(), image.ID()),
"dist": volume.JoinPathContainer(ctx.DistDirContainer(), image.ID()),
"temp": volume.JoinPathContainer(ctx.TmpDirContainer(), image.ID()),
"bin": volume.JoinPathHost(ctx.Volume.BinDirHost(), image.ID()),
"dist": volume.JoinPathHost(ctx.Volume.DistDirHost(), image.ID()),
"temp": volume.JoinPathHost(ctx.Volume.TmpDirHost(), image.ID()),
}

log.Infof("[i] Cleaning target directories...")
for k, v := range dirs {
err := image.Run(ctx.Volume, options{}, []string{"rm", "-rf", v})
if err != nil {
if err := os.RemoveAll(v); err != nil {
return fmt.Errorf("could not clean the %q dir %s: %v", k, v, err)
}

err = image.Run(ctx.Volume, options{}, []string{"mkdir", "-p", v})
if err != nil {
if err := os.MkdirAll(v, os.ModePerm); err != nil {
return fmt.Errorf("could not create the %q dir %s: %v", k, v, err)
}

Expand Down Expand Up @@ -142,10 +140,12 @@ func prepareIcon(ctx Context, image containerImage) error {
}
}

err := image.Run(ctx.Volume, options{}, []string{"cp", volume.JoinPathContainer(ctx.WorkDirContainer(), ctx.Icon), volume.JoinPathContainer(ctx.TmpDirContainer(), image.ID(), icon.Default)})
if err != nil {
return fmt.Errorf("could not copy the icon to temp folder: %v", err)
if data, err := os.ReadFile(volume.JoinPathHost(ctx.Volume.WorkDirHost(), ctx.Icon)); err != nil {
return fmt.Errorf("could not read in icon %s: %w", ctx.Icon, err)
} else if err := os.WriteFile(volume.JoinPathHost(ctx.TmpDirHost(), image.ID(), icon.Default), data, 0644); err != nil {
return fmt.Errorf("could not copy icon %s to tmp folder: %w", ctx.Icon, err)
}

return nil
}

Expand Down