Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 038d56f

Browse files
committed
aci, builder: utilize the new tar for ACI files
Enables dgr to work on hosts that don't have any tar. (See also #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 #210
1 parent b995934 commit 038d56f

2 files changed

Lines changed: 24 additions & 38 deletions

File tree

aci-builder/bin-run/builder.go

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -136,39 +136,36 @@ func (b *Builder) tarAci() error {
136136
}
137137

138138
upperPath := b.pod.Root + PATH_OVERLAY + "/" + upperId + PATH_UPPER
139-
upperNamedRootfs := upperPath + "/" + manifestApp(b.pod).Name.String()
140-
upperRootfs := upperPath + common.PathRootfs
141-
142-
if err := os.RemoveAll(upperNamedRootfs + PATH_TMP); err != nil {
143-
logs.WithEF(err, b.fields.WithField("path", upperNamedRootfs+PATH_TMP)).Warn("Failed to clean tmp directory")
144-
}
145-
146-
if err := os.Rename(upperNamedRootfs, upperRootfs); err != nil { // TODO this is dirty and can probably be renamed during tar
147-
return errs.WithEF(err, b.fields.WithField("path", upperNamedRootfs), "Failed to rename rootfs")
148-
}
149-
defer os.Rename(upperRootfs, upperNamedRootfs)
150-
151-
dir, err := os.Getwd()
152-
if err != nil {
153-
return errs.WithEF(err, b.fields, "Failed to get current working directory")
154-
}
155-
defer func() {
156-
if err := os.Chdir(dir); err != nil {
157-
logs.WithEF(err, b.fields.WithField("path", dir)).Warn("Failed to chdir back")
139+
rootfsAlias := manifestApp(b.pod).Name.String()
140+
destination := b.aciTargetPath + common.PathImageAci // absolute dir, outside upperPath (think: /tmp/…)
141+
142+
params := []string{"--sort=name", "--numeric-owner", "--exclude", rootfsAlias + PATH_TMP + "/*"}
143+
params = append(params, "-C", upperPath, "--transform", "s@^"+rootfsAlias+"@rootfs@")
144+
params = append(params, "-cf", destination, common.PathManifest[1:], rootfsAlias)
145+
146+
logs.WithF(b.fields).Debug("Calling tar to collect all files")
147+
if err := common.ExecCmd("tar", params...); err != nil {
148+
// In case the host's tar is too old, try the builder's if it exists.
149+
stage1Tar := rktcommon.Stage1RootfsPath(b.pod.Root)
150+
var buildersTar string
151+
for _, t := range []string{"/dgr/usr/bin/tar", "/bin/tar", "/usr/bin/tar"} {
152+
buildersTar = filepath.Join(stage1Tar, t)
153+
if _, err := os.Stat(buildersTar); err == nil {
154+
break
155+
}
158156
}
159-
}()
160157

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

dgr/common/tar.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)