Example #1
0
// untar is the entry-point for docker-untar on re-exec. This is not used on
// Windows as it does not support chroot, hence no point sandboxing through
// chroot and rexec.
func untar() {
	runtime.LockOSThread()
	flag.Parse()

	var options *archive.TarOptions

	//read the options from the pipe "ExtraFiles"
	if err := json.NewDecoder(os.NewFile(3, "options")).Decode(&options); err != nil {
		fatal(err)
	}

	if err := chroot(flag.Arg(0)); err != nil {
		fatal(err)
	}

	if err := archive.Unpack(os.Stdin, "/", options); err != nil {
		fatal(err)
	}
	// fully consume stdin in case it is zero padded
	if _, err := flush(os.Stdin); err != nil {
		fatal(err)
	}

	os.Exit(0)
}
func invokeUnpack(decompressedArchive io.ReadCloser,
	dest string,
	options *archive.TarOptions) error {
	// Windows is different to Linux here because Windows does not support
	// chroot. Hence there is no point sandboxing a chrooted process to
	// do the unpack. We call inline instead within the daemon process.
	return archive.Unpack(decompressedArchive, dest, options)
}
Example #3
0
func untar() {
	runtime.LockOSThread()
	flag.Parse()
	if err := chroot(flag.Arg(0)); err != nil {
		fatal(err)
	}
	var options *archive.TarOptions
	if err := json.NewDecoder(strings.NewReader(flag.Arg(1))).Decode(&options); err != nil {
		fatal(err)
	}
	if err := archive.Unpack(os.Stdin, "/", options); err != nil {
		fatal(err)
	}
	// fully consume stdin in case it is zero padded
	flush(os.Stdin)
	os.Exit(0)
}
Example #4
0
func untar() {
	runtime.LockOSThread()
	flag.Parse()

	var options *archive.TarOptions

	if err := json.Unmarshal([]byte(os.Getenv("OPT")), &options); err != nil {
		fatal(err)
	}

	if err := chroot(flag.Arg(0)); err != nil {
		fatal(err)
	}
	if err := archive.Unpack(os.Stdin, "/", options); err != nil {
		fatal(err)
	}
	// fully consume stdin in case it is zero padded
	flush(os.Stdin)
	os.Exit(0)
}
Example #5
0
func untar() {
	runtime.LockOSThread()
	flag.Parse()

	var options *archive.TarOptions

	if runtime.GOOS != "windows" {
		//read the options from the pipe "ExtraFiles"
		if err := json.NewDecoder(os.NewFile(3, "options")).Decode(&options); err != nil {
			fatal(err)
		}
	} else {
		if err := json.Unmarshal([]byte(os.Getenv("OPT")), &options); err != nil {
			fatal(err)
		}
	}

	if err := chroot(flag.Arg(0)); err != nil {
		fatal(err)
	}

	// Explanation of Windows difference. Windows does not support chroot.
	// untar() is a helper function for the command line in the format
	// "docker docker-untar directory input". In Windows, directory will be
	// something like <pathto>\docker-buildnnnnnnnnn. So, just use that directory
	// directly instead.
	//
	// One example of where this is used is in the docker build command where the
	// dockerfile will be unpacked to the machine on which the daemon runs.
	rootPath := "/"
	if runtime.GOOS == "windows" {
		rootPath = flag.Arg(0)
	}
	if err := archive.Unpack(os.Stdin, rootPath, options); err != nil {
		fatal(err)
	}
	// fully consume stdin in case it is zero padded
	flush(os.Stdin)
	os.Exit(0)
}
Example #6
0
func CreateNewProject(name string, reader io.Reader) (*Project, error) {
	project := &Project{
		Name: name,
	}
	exists, err := project.Exists()
	if err != nil {
		return nil, err
	} else if exists == true {
		return nil, errors.New("Project already exists")
	}

	decompressedArchive, err := archive.DecompressStream(reader)
	if err != nil {
		return nil, err
	}
	defer decompressedArchive.Close()

	project.createDirectory()

	archive.Unpack(decompressedArchive, basePath+name, &archive.TarOptions{})

	return project, nil
}