2014-10-29 19:06:51 +00:00
|
|
|
package chrootarchive
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2014-11-18 21:33:13 +00:00
|
|
|
"io/ioutil"
|
2014-10-29 19:06:51 +00:00
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"github.com/docker/docker/pkg/archive"
|
|
|
|
"github.com/docker/docker/pkg/reexec"
|
|
|
|
)
|
|
|
|
|
|
|
|
func applyLayer() {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if err := syscall.Chroot(flag.Arg(0)); err != nil {
|
|
|
|
fatal(err)
|
|
|
|
}
|
|
|
|
if err := syscall.Chdir("/"); err != nil {
|
|
|
|
fatal(err)
|
|
|
|
}
|
2014-11-18 21:33:13 +00:00
|
|
|
tmpDir, err := ioutil.TempDir("/", "temp-docker-extract")
|
|
|
|
if err != nil {
|
|
|
|
fatal(err)
|
|
|
|
}
|
|
|
|
os.Setenv("TMPDIR", tmpDir)
|
2014-10-29 19:06:51 +00:00
|
|
|
if err := archive.ApplyLayer("/", os.Stdin); err != nil {
|
2014-11-18 21:33:13 +00:00
|
|
|
os.RemoveAll(tmpDir)
|
2014-10-29 19:06:51 +00:00
|
|
|
fatal(err)
|
|
|
|
}
|
2014-11-18 21:33:13 +00:00
|
|
|
os.RemoveAll(tmpDir)
|
2014-12-08 23:04:34 +00:00
|
|
|
flush(os.Stdin)
|
2014-10-29 19:06:51 +00:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ApplyLayer(dest string, layer archive.ArchiveReader) error {
|
|
|
|
cmd := reexec.Command("docker-applyLayer", dest)
|
|
|
|
cmd.Stdin = layer
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("ApplyLayer %s %s", err, out)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|