-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathrootfs.go
43 lines (35 loc) · 1021 Bytes
/
rootfs.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
43
package container
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/docker/docker/pkg/archive"
)
const (
// DefaultTarballPath holds the default path for the embedded tarball.
DefaultTarballPath = "image.tar"
)
// UnpackRootfs unpacks the embedded tarball to the rootfs.
func (c *Container) UnpackRootfs(rootfsDir string, asset func(string) ([]byte, error)) error {
// Make the rootfs directory.
if err := os.MkdirAll(rootfsDir, 0755); err != nil {
return err
}
// Get the embedded tarball.
data, err := asset(DefaultTarballPath)
if err != nil {
return fmt.Errorf("getting bindata asset image.tar failed: %v", err)
}
// Unpack the tarball.
r := bytes.NewReader(data)
if err := archive.Untar(r, rootfsDir, &archive.TarOptions{NoLchown: true}); err != nil {
return err
}
// Write a resolv.conf.
if err := ioutil.WriteFile(filepath.Join(rootfsDir, "etc", "resolv.conf"), []byte("nameserver 8.8.8.8\nnameserver 8.8.4.4"), 0755); err != nil {
return err
}
return nil
}