Skip to content
This repository has been archived by the owner on May 22, 2020. It is now read-only.

Commit

Permalink
aci, builder: utilize the new tar for ACI files
Browse files Browse the repository at this point in the history
Enables dgr to work on hosts that don't have any tar. (See also blablacar#217.)

Sorts the contents to have a reproducible order, but pulls the manifest
file to the front for fast access.

Sorted contents of ACIs allow for easier comparison, and usage of
tools such as zsync, and deduplication on the server. The price,
sorting by 'tar', is cheap.

zap the "chdir-acrobatique", use `tar -C`:
    dgr changes paths and performs needless renames, which result in mayhem
if the process quits prematurely or the timing were off. The solution is to
use tar's `-C` param and transform the filenames.

closes blablacar#210
  • Loading branch information
mark-kubacki committed Mar 27, 2017
1 parent b995934 commit 038d56f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 38 deletions.
51 changes: 24 additions & 27 deletions aci-builder/bin-run/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,39 +136,36 @@ func (b *Builder) tarAci() error {
}

upperPath := b.pod.Root + PATH_OVERLAY + "/" + upperId + PATH_UPPER
upperNamedRootfs := upperPath + "/" + manifestApp(b.pod).Name.String()
upperRootfs := upperPath + common.PathRootfs

if err := os.RemoveAll(upperNamedRootfs + PATH_TMP); err != nil {
logs.WithEF(err, b.fields.WithField("path", upperNamedRootfs+PATH_TMP)).Warn("Failed to clean tmp directory")
}

if err := os.Rename(upperNamedRootfs, upperRootfs); err != nil { // TODO this is dirty and can probably be renamed during tar
return errs.WithEF(err, b.fields.WithField("path", upperNamedRootfs), "Failed to rename rootfs")
}
defer os.Rename(upperRootfs, upperNamedRootfs)

dir, err := os.Getwd()
if err != nil {
return errs.WithEF(err, b.fields, "Failed to get current working directory")
}
defer func() {
if err := os.Chdir(dir); err != nil {
logs.WithEF(err, b.fields.WithField("path", dir)).Warn("Failed to chdir back")
rootfsAlias := manifestApp(b.pod).Name.String()
destination := b.aciTargetPath + common.PathImageAci // absolute dir, outside upperPath (think: /tmp/…)

params := []string{"--sort=name", "--numeric-owner", "--exclude", rootfsAlias + PATH_TMP + "/*"}
params = append(params, "-C", upperPath, "--transform", "s@^"+rootfsAlias+"@rootfs@")
params = append(params, "-cf", destination, common.PathManifest[1:], rootfsAlias)

logs.WithF(b.fields).Debug("Calling tar to collect all files")
if err := common.ExecCmd("tar", params...); err != nil {
// In case the host's tar is too old, try the builder's if it exists.
stage1Tar := rktcommon.Stage1RootfsPath(b.pod.Root)
var buildersTar string
for _, t := range []string{"/dgr/usr/bin/tar", "/bin/tar", "/usr/bin/tar"} {
buildersTar = filepath.Join(stage1Tar, t)
if _, err := os.Stat(buildersTar); err == nil {
break
}
}
}()

if err := os.Chdir(upperPath); err != nil {
return errs.WithEF(err, b.fields.WithField("path", upperPath), "Failed to chdir to upper base path")
}
if err := common.Tar(b.aciTargetPath+common.PathImageAci, common.PathManifest[1:], common.PathRootfs[1:]+"/"); err != nil {
return errs.WithEF(err, b.fields, "Failed to tar aci")
if err2 := common.ExecCmd(buildersTar, params...); err2 != nil {
// If that failed, output the original error nevertheless.
logs.WithFields(b.fields).WithField("params", params).Debug("Parameters to 'tar' within the builder")
return errs.WithEF(err, b.fields, "Failed to tar aci")
}
logs.WithF(b.fields).Debug("Had to resort to 'tar' from the builder to create the aci file")
}
// common.ExecCmd sometimes silently fails, hence the redundant check.
if _, err := os.Stat(b.aciTargetPath + common.PathImageAci); os.IsNotExist(err) {
if _, err := os.Stat(destination); os.IsNotExist(err) {
return errs.WithEF(err, b.fields, "Expected aci has not been created")
}
logs.WithField("path", dir).Debug("chdir")
return nil
}

Expand Down
11 changes: 0 additions & 11 deletions dgr/common/tar.go

This file was deleted.

0 comments on commit 038d56f

Please sign in to comment.