1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
package client
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"github.com/apptainer/apptainer/internal/pkg/buildcfg"
"github.com/google/uuid"
)
func ConvertSifToSandbox(directTo, src, pullTo string) error {
if directTo != "" {
// rename the pulled sif first and extract to the sandbox dir
name := filepath.Base(src)
newPath := filepath.Join(filepath.Dir(src), name+"-"+uuid.NewString())
if err := os.Rename(src, newPath); err != nil {
return fmt.Errorf("unable to rename pulled sif: %v", err)
}
defer os.Remove(newPath)
src = newPath
}
// using pulled sif
exe := filepath.Join(buildcfg.BINDIR, "apptainer")
cmdArgs := []string{"build", "-F", "--sandbox", pullTo, src}
cmd := exec.Command(exe, cmdArgs...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return fmt.Errorf("while converting cached sif to sandbox: %v", err)
}
return nil
}
|