Example #1
0
// Install ...
func (l *Launchable) Install() (returnedError error) {
	if l.Installed() {
		return nil
	}

	data, err := uri.DefaultFetcher.Open(l.Location)
	if err != nil {
		return err
	}
	defer data.Close()
	defer func() {
		if returnedError != nil {
			os.RemoveAll(l.InstallDir())
		}
	}()
	err = gzip.ExtractTarGz("", data, l.InstallDir())
	if err != nil {
		return util.Errorf("extracting %s: %s", l.Version(), err)
	}
	if _, err = l.getSpec(); err != nil {
		return err
	}

	// Construct the host-specific configuration... This is probably the wrong place for this
	// code because the container cgroup settings depend on the manifest.
	runSpecPath := filepath.Join(l.InstallDir(), RuntimeSpecFilename)
	runSpec := DefaultRuntimeSpec
	runSpecData, err := json.Marshal(runSpec)
	if err != nil {
		return err
	}
	return ioutil.WriteFile(runSpecPath, runSpecData, 0444)
}
Example #2
0
func (hl *Launchable) Install() error {
	if hl.Installed() {
		// install is idempotent, no-op if already installed
		return nil
	}

	// Write to a temporary file for easy cleanup if the network transfer fails
	artifactFile, err := ioutil.TempFile("", path.Base(hl.Location))
	if err != nil {
		return err
	}
	defer os.Remove(artifactFile.Name())
	defer artifactFile.Close()
	remoteData, err := hl.Fetcher.Open(hl.Location)
	if err != nil {
		return err
	}
	defer remoteData.Close()
	_, err = io.Copy(artifactFile, remoteData)
	if err != nil {
		return err
	}
	_, err = artifactFile.Seek(0, os.SEEK_SET)
	if err != nil {
		return err
	}

	err = gzip.ExtractTarGz(hl.RunAs, artifactFile, hl.InstallDir())
	if err != nil {
		os.RemoveAll(hl.InstallDir())
		return util.Errorf("extracting %s: %s", hl.Version(), err)
	}
	return err
}
Example #3
0
func (l *downloader) Download(location *url.URL, verificationData auth.VerificationData, dst string, owner string) error {
	// Write to a temporary file for easy cleanup if the network transfer fails
	// TODO: the end of the artifact URL may not always be suitable as a directory
	// name
	artifactFile, err := ioutil.TempFile("", filepath.Base(location.Path))
	if err != nil {
		return err
	}
	defer os.Remove(artifactFile.Name())
	defer artifactFile.Close()

	remoteData, err := l.fetcher.Open(location)
	if err != nil {
		return err
	}
	defer remoteData.Close()
	_, err = io.Copy(artifactFile, remoteData)
	if err != nil {
		return util.Errorf("Could not copy artifact locally: %v", err)
	}
	// rewind once so we can ask the verifier
	_, err = artifactFile.Seek(0, os.SEEK_SET)
	if err != nil {
		return util.Errorf("Could not reset artifact file position for verification: %v", err)
	}

	err = l.verifier.VerifyHoistArtifact(artifactFile, verificationData)
	if err != nil {
		return err
	}

	// rewind a second time to allow the archive to be unpacked
	_, err = artifactFile.Seek(0, os.SEEK_SET)
	if err != nil {
		return util.Errorf("Could not reset artifact file position after verification: %v", err)
	}

	err = gzip.ExtractTarGz(owner, artifactFile, dst)
	if err != nil {
		_ = os.RemoveAll(dst)
		return util.Errorf("error while extracting artifact: %s", err)
	}
	return err
}
Example #4
0
func (hl *Launchable) extractTarGz(fp io.Reader, fpName string, dest string) (err error) {
	return gzip.ExtractTarGz(hl.RunAs, fp, fpName, dest)
}