add better generate
Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
parent
3fc6abf56b
commit
cdd93563f5
5655 changed files with 1187011 additions and 392 deletions
43
container/rootfs.go
Normal file
43
container/rootfs.go
Normal file
|
|
@ -0,0 +1,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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue