Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when loading rules_oci image tarball into docker #189

Closed
AttilaTheFun opened this issue Apr 29, 2023 · 3 comments
Closed

Error when loading rules_oci image tarball into docker #189

AttilaTheFun opened this issue Apr 29, 2023 · 3 comments

Comments

@AttilaTheFun
Copy link
Contributor

Hi! I'm trying to build my docker images from my Go project with rules_oci. I tried following your guide, but I'm getting an error when attempting to load the tarball into docker.

My tarball target has the repotags set:

go_binary(
    name = "phono",
    embed = [":phono_lib"],
    visibility = ["//visibility:public"],
)

pkg_tar(
    name = "phono_tarball",
    srcs = [":phono"],
)

oci_image(
    name = "phono_image",
    architecture = select({
        "@platforms//cpu:arm64": "arm64",
        "@platforms//cpu:x86_64": "amd64",
    }),
    base = "@distroless_base",
    tars = [":phono_tarball"],
    entrypoint = ["/app"],
    os = "linux",
)

oci_tarball(
    name = "phono_image_tarball",
    image = ":phono_image",
    repotags = ["phono:latest"],
)

But I'm getting this error when running:

$ docker load --input /private/var/tmp/_bazel_logan/6935840e8ee73f156f0328fbaa27d52a/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/apps/phono/phono_image_tarball/tarball.tar
json: cannot unmarshal string into Go struct field manifestItem.RepoTags of type []string

Note that I'm using a bazel symlink prefix in my .bazelrc:

build --symlink_prefix=.bazel/

So I had to use a shell script to construct the full path to the tar:

#!/bin/zsh

# Get the file path of the image tarball:
OCI_IMAGE_TARBALL_RELATIVE_FILE_PATH=$(bazel cquery --output=files $1)

# Trim off the bazel-out prefix:
OCI_IMAGE_TARBALL_RELATIVE_FILE_PATH=${OCI_IMAGE_TARBALL_RELATIVE_FILE_PATH#"bazel-out"}

# Get the path to the bazel-out directory at the destination of our symlink:
BAZEL_OUT_DIR_PATH=$(readlink -f .bazel/out)

# Concatenate the two together to get an absolute path to the image tarball:
OCI_IMAGE_TARBALL_ABSOLUTE_FILE_PATH=$BAZEL_OUT_DIR_PATH$OCI_IMAGE_TARBALL_RELATIVE_FILE_PATH

# Load the image into docker:
docker load --input $OCI_IMAGE_TARBALL_ABSOLUTE_FILE_PATH

I was able to work around the issue by using docker import instead and providing the tag manually but this is less than ideal:

cat /private/var/tmp/_bazel_logan/6935840e8ee73f156f0328fbaa27d52a/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/apps/phono/phono_image_tarball/tarball.tar | docker import - phono:latest

Do you have any suggestions?

@AttilaTheFun
Copy link
Contributor Author

I put up a PR to fix the bug here:
#190

@jmhodges
Copy link

I think this can be closed now that #205 has merged?

@AttilaTheFun
Copy link
Contributor Author

Hi @jmhodges yes my PR fixed it. I’ll close it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants