コード例 #1
0
ファイル: main.go プロジェクト: felixb/none
// tar workdir
// returns path to local artifact
func tarWorkdir() *string {
	if !*sendWorkdir {
		return nil
	}

	path := fmt.Sprintf("%s/none-workdir-%d.tar.gz", os.TempDir(), os.Getpid())
	tar := new(archivex.TarFile)
	tar.Create(path)
	tar.AddAll(".", true)
	tar.Close()
	return &path
}
コード例 #2
0
ファイル: aci.go プロジェクト: puckel/dgr
func (aci *Aci) tarAci(path string) error {
	tar := new(archivex.TarFile)
	if err := tar.Create(path + pathImageAci); err != nil {
		return errs.WithEF(err, aci.fields.WithField("path", path+pathImageAci), "Failed to create image tar")
	}
	if err := tar.AddFile(path + common.PathManifest); err != nil {
		return errs.WithEF(err, aci.fields.WithField("path", path+common.PathManifest), "Failed to add manifest to tar")
	}
	if err := tar.AddAll(path+common.PathRootfs, true); err != nil {
		return errs.WithEF(err, aci.fields.WithField("path", path+common.PathRootfs), "Failed to add rootfs to tar")
	}
	if err := tar.Close(); err != nil {
		return errs.WithEF(err, aci.fields.WithField("path", path), "Failed to tar aci")
	}
	os.Rename(path+pathImageAci+".tar", path+pathImageAci)
	return nil
}
コード例 #3
0
ファイル: folder.go プロジェクト: sunatthegilddotcom/decker
// Pack ...
func Pack(inputPath string, outputPath string) (fileName string, err error) {
	err = Check(inputPath)

	if err != nil {
		return
	}

	packageFile := path.Join(inputPath, PackageFileName)
	binFolder := path.Join(inputPath, BinFolder)

	pkg, err := LoadFile(packageFile)

	if err != nil {
		return
	}

	fileName = pkg.Name
	if pkg.Version != "" {
		fileName += "-" + pkg.Version
	}
	fileName += ".tar.gz"
	filePath := path.Join(outputPath, fileName)

	tar := new(archivex.TarFile)
	tar.Compressed = true

	if err = tar.Create(filePath); err != nil {
		return
	}

	defer tar.Close()

	if err = tar.AddFile(packageFile); err != nil {
		return
	}

	if err = tar.AddAll(binFolder, true); err != nil {
		return
	}

	return
}
コード例 #4
0
ファイル: build.go プロジェクト: prachpub/dpm
func BuildPackage(dir string) (*Package, error) {
	home := os.Getenv("HOME")

	buf := new(bytes.Buffer)
	tarfile := new(archivex.TarFile)
	tarfile.Writer = tar.NewWriter(buf)

	specContent, err := ioutil.ReadFile(filepath.Join(dir, "SPEC.yml"))
	root := Root{}
	err = yaml.Unmarshal(specContent, &root)
	if err != nil {
		return nil, err
	}
	spec := root.Spec

	tarfile.AddFileWithName(filepath.Join(dir, "SPEC.yml"), "SPEC.yml")
	tarfile.AddFileWithName(filepath.Join(dir, spec.Provision), spec.Provision)
	tarfile.AddFileWithName(filepath.Join(dir, spec.Composition), spec.Composition)
	for _, d := range spec.Dirs {
		tarfile.AddAll(filepath.Join(dir, d), true)
	}

	hashes := []string{}
	graph := make(DepGraph)
	// resolve dependencies on build
	// to gaurantee that the package will have
	// the same behaviour everytime we deploy it
	for name, attributes := range spec.Dependencies {
		attrs, err := parse(attributes)
		if err != nil {
			return nil, err
		}

		entry, err := repo.Get(name, attrs["version"])
		if err != nil {
			return nil, err
		}

		p, err := LoadPackage(filepath.Join(home, ".dpm", "cache", entry.Filename))
		if err != nil {
			return nil, err
		}

		err = p.ExtractIfNotExist()
		if err != nil {
			return nil, err
		}

		hashes = append(hashes, entry.Hash)
		deps, err := p.Deps()
		if err != nil {
			return nil, err
		}
		graph = merge(graph, deps)
	}

	// add entry of this package before save to DEPS
	graph["this"] = hashes

	depsContent, err := yaml.Marshal(graph)
	if err != nil {
		return nil, err
	}
	tarfile.Add("DEPS", depsContent)

	order, cyclic := toposort(graph)
	if len(cyclic) != 0 {
		return nil, fmt.Errorf("Dependency cyclic detected")
	}

	for _, h := range order {
		if h == "this" {
			continue
		}
		tarfile.AddAll(filepath.Join(home, ".dpm", "workspace", h), true)
	}

	tarfile.Close()
	return &Package{buf.Bytes()}, nil
}