Example #1
0
File: aci.go Project: 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
}
Example #2
0
// 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
}