Skip to content

Commit

Permalink
Add symlink and new file structure to loader.go binary (bazelbuild#951)
Browse files Browse the repository at this point in the history
* Add symlink to puller's OCI intermediate format

* modify symlink generator to account for new pulled image file structure

* amend puller to take in general output directory so as to maintain image convention and add image-oci

* simplify directory logic for new file structure and add error checking for safe os operations

* refactor utility function into a utility package

* rename functions in package and export consts

* export ImageDir for consistency and expand error checking

* refactor puller binary with const and integrate compat package

* add docs for symlink function

* Add symlink to puller's OCI intermediate format

* modify symlink generator to account for new pulled image file structure

* amend puller to take in general output directory so as to maintain image convention and add image-oci

* simplify directory logic for new file structure and add error checking for safe os operations

* refactor utility function into a utility package

* rename functions in package and export consts

* export ImageDir for consistency and expand error checking

* refactor puller binary with const and integrate compat package

* add docs for symlink function

* Add symlink and new file structure to loader.go binary

* rebase on puller_go to add dependency to loader binary

* rebase on puller_go branch and use exported constant in loader binary

* update loader binary to be compatible with updated compat package

* rename symlink naming to convention src to dst

* clarify symlink in docs

* Add symlink and new file structure to loader.go binary

* rebase on puller_go to add dependency to loader binary

* rebase on puller_go branch and use exported constant in loader binary

* update loader binary to be compatible with updated compat package

* rename variables and remove comments mentioning symlinks
  • Loading branch information
xwinxu authored and k8s-ci-robot committed Jul 4, 2019
1 parent d7c9559 commit 432706d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions container/go/cmd/loader/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ go_library(
importpath = "github.com/bazelbuild/rules_docker/container/go/cmd/loader",
visibility = ["//visibility:private"],
deps = [
"//container/go/pkg/compat:go_default_library",
"//container/go/pkg/oci:go_default_library",
"@com_github_google_go_containerregistry//pkg/v1/tarball:go_default_library",
"@com_github_pkg_errors//:go_default_library",
Expand Down
16 changes: 15 additions & 1 deletion container/go/cmd/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ package main
import (
"flag"
"log"
"path"

"github.com/bazelbuild/rules_docker/container/go/pkg/oci"
"github.com/bazelbuild/rules_docker/container/go/pkg/compat"
"github.com/google/go-containerregistry/pkg/v1/tarball"
"github.com/pkg/errors"
)
Expand All @@ -33,17 +35,29 @@ var (
imgTarball = flag.String("tarball", "", "The path to the tarball to load.")
)

// Directory containing the pulled OCI image artifacts without modification.
const ociImageDir = "image-oci"

// Directory containing an image and image.tar to be consumed by container_import.
const legacyDir = "image"

// load loads a docker image tarball generated by docker save from path <dir>.
func load(tar, dir string) error {
img, err := tarball.ImageFromPath(tar, nil)
if err != nil {
return errors.Wrapf(err, "failed to read docker image tarball from %q", dir)
}

if err = oci.Write(img, dir); err != nil {
ociPath := path.Join(dir, ociImageDir)
legacyPath := path.Join(dir, legacyDir)
if err = oci.Write(img, ociPath); err != nil {
return errors.Wrapf(err, "failed to write image to OCI layout at path %s", dir)
}

if err := compat.LegacyFromOCIImage(img, ociPath, legacyPath); err != nil {
return errors.Wrapf(err, "failed to generate symbolic links to pulled image at %s", dir)
}

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion container/go/pkg/compat/ociToLegacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func LegacyFromOCIImage(img v1.Image, srcDir, dstDir string) error {
layerDigest, err := layer.Digest()
if err != nil {
return errors.Wrap(err, "failed to fetch the layer's digest")
}
}

layerPath = path.Join(targetDir, layerDigest.Hex)
out := strconv.Itoa(i) + targzExt
Expand Down

0 comments on commit 432706d

Please sign in to comment.