forked from containers/storage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
overlay: new option to support ostree deduplication
usage example: skopeo copy docker-daemon:busybox:latest containers-storage:\[overlay2@/var/lib/containers/storage+/var/run/containers/storage:overlay2.ostree_repo=/var/lib/containers/storage/overlay2/ostree/.repo,overlay2.override_kernel_check=1\]\busybox Skopeo needs a bugfix from: containers/image#305 which is not merged yet. Just apply this patch: diff --git a/vendor/github.com/containers/image/storage/storage_image.go b/vendor/github.com/containers/image/storage/storage_image.go index 08fa71b..5edccce 100644 --- a/vendor/github.com/containers/image/storage/storage_image.go +++ b/vendor/github.com/containers/image/storage/storage_image.go @@ -174,7 +174,7 @@ func (s *storageImageDestination) putBlob(stream io.Reader, blobinfo types.BlobI id = ddigest.Canonical.FromBytes([]byte(parentLayer + "+" + digest.String())).Hex() } // Attempt to create the identified layer and import its contents. - layer, uncompressedSize, err := s.imageRef.transport.store.PutLayer(id, parentLayer, nil, "", true, multi) + layer, uncompressedSize, err := s.imageRef.transport.store.PutLayer(id, parentLayer, nil, "", false, multi) if err != nil && errors.Cause(err) != storage.ErrDuplicateID { logrus.Debugf("error importing layer blob %q as %q: %v", blobinfo.Digest, id, err) return errorBlobInfo, err Signed-off-by: Giuseppe Scrivano <[email protected]>
- Loading branch information
Showing
5 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,7 @@ var ( | |
"btrfs", | ||
"zfs", | ||
"vfs", | ||
"ostree", | ||
} | ||
|
||
// FsNames maps filesystem id to name of the filesystem. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// +build exclude_ostree | ||
|
||
package overlay | ||
|
||
func ostreeSupport() bool { | ||
return false | ||
} | ||
|
||
func deleteOSTree(repoLocation, id string) error { | ||
return nil | ||
} | ||
|
||
func createOSTreeRepository(repoLocation string, rootUID int, rootGID int) error { | ||
return nil | ||
} | ||
|
||
func convertToOSTree(repoLocation, root, id string) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// +build !exclude_ostree | ||
|
||
package overlay | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"time" | ||
|
||
"github.com/containers/storage/pkg/idtools" | ||
"github.com/containers/storage/pkg/system" | ||
"github.com/ostreedev/ostree-go/pkg/otbuiltin" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func ostreeSupport() bool { | ||
return true | ||
} | ||
|
||
// Create prepares the filesystem for the OSTREE driver and copies the directory for the given id under the parent. | ||
func convertToOSTree(repoLocation, root, id string) error { | ||
repo, err := otbuiltin.OpenRepo(repoLocation) | ||
if err != nil { | ||
return errors.Wrap(err, "could not open the OSTree repository") | ||
} | ||
|
||
if _, err := repo.PrepareTransaction(); err != nil { | ||
return errors.Wrap(err, "could not prepare the OSTree transaction") | ||
} | ||
commitOpts := otbuiltin.NewCommitOptions() | ||
commitOpts.Timestamp = time.Now() | ||
commitOpts.Parent = "0000000000000000000000000000000000000000000000000000000000000000" | ||
branch := fmt.Sprintf("ocilayer/%s", id) | ||
|
||
if _, err := repo.Commit(root, branch, commitOpts); err != nil { | ||
return errors.Wrap(err, "could not commit the layer") | ||
} | ||
|
||
if _, err := repo.CommitTransaction(); err != nil { | ||
return errors.Wrap(err, "could not complete the OSTree transaction") | ||
} | ||
|
||
if err := system.EnsureRemoveAll(root); err != nil { | ||
return err | ||
} | ||
|
||
checkoutOpts := otbuiltin.NewCheckoutOptions() | ||
checkoutOpts.RequireHardlinks = true | ||
if err := otbuiltin.Checkout(repoLocation, root, branch, checkoutOpts); err != nil { | ||
return errors.Wrap(err, "could not checkout from OSTree") | ||
} | ||
return nil | ||
} | ||
|
||
func createOSTreeRepository(repoLocation string, rootUID int, rootGID int) error { | ||
_, err := os.Stat(repoLocation) | ||
if err != nil && !os.IsNotExist(err) { | ||
return err | ||
} else if err != nil { | ||
if err := idtools.MkdirAllAs(repoLocation, 0700, rootUID, rootGID); err != nil { | ||
return errors.Wrap(err, "could not create OSTree repository directory: %v") | ||
} | ||
|
||
if err := exec.Command("ostree", fmt.Sprintf("--repo=%s", repoLocation), "init").Run(); err != nil { | ||
return errors.Wrap(err, "could not create OSTree repository") | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func deleteOSTree(repoLocation, id string) error { | ||
branch := fmt.Sprintf("ocilayer/%s", id) | ||
if err := exec.Command("ostree", fmt.Sprintf("--repo=%s", repoLocation), "refs", "--delete", branch).Run(); err != nil { | ||
return errors.Wrap(err, "could not delete OSTree branch") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters