forked from project-stacker/stacker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grab.go
42 lines (34 loc) · 938 Bytes
/
grab.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
39
40
41
42
package stacker
import (
"fmt"
"os"
"path"
"github.com/pkg/errors"
"github.com/project-stacker/stacker/container"
"github.com/project-stacker/stacker/types"
)
func Grab(sc types.StackerConfig, storage types.Storage, name string, source string, targetDir string) error {
c, err := container.New(sc, name)
if err != nil {
return err
}
defer c.Close()
err = c.BindMount(targetDir, "/stacker", "")
if err != nil {
return err
}
defer os.Remove(path.Join(sc.RootFSDir, name, "rootfs", "stacker"))
binary, err := os.Readlink("/proc/self/exe")
if err != nil {
return errors.Wrapf(err, "couldn't find executable for bind mount")
}
err = c.BindMount(binary, "/static-stacker", "")
if err != nil {
return err
}
err = SetupBuildContainerConfig(sc, storage, c, name)
if err != nil {
return err
}
return c.Execute(fmt.Sprintf("/static-stacker internal-go cp %s /stacker/%s", source, path.Base(source)), nil)
}