/
packer_sandbox.go
38 lines (31 loc) · 1.09 KB
/
packer_sandbox.go
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
36
37
38
// Copyright (c) 2018, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package sources
import (
"bytes"
"fmt"
"os/exec"
"github.com/sylabs/singularity/internal/pkg/sylog"
"github.com/sylabs/singularity/pkg/build/types"
)
// SandboxPacker holds the locations of where to pack from and to
// Ext3Packer holds the locations of where to back from and to, aswell as image offset info
type SandboxPacker struct {
srcdir string
b *types.Bundle
}
// Pack puts relevant objects in a Bundle!
func (p *SandboxPacker) Pack() (*types.Bundle, error) {
rootfs := p.srcdir
// copy filesystem into bundle rootfs
sylog.Debugf("Copying file system from %s to %s in Bundle\n", rootfs, p.b.Rootfs())
var stderr bytes.Buffer
cmd := exec.Command("cp", "-r", rootfs+`/.`, p.b.Rootfs())
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("cp Failed: %v: %v", err, stderr.String())
}
return p.b, nil
}