Short version of question: Is it possible to use `...
# general
m
Short version of question: Is it possible to use
docker_environment
with a locally-built image? Slightly longer version: It seems that a docker_environment requires a manifest ID which does not exist unless and until an image is pushed to a V2 registry. There seems to be a bug (I'll add details in a ๐Ÿงต) where pants will treat the image ID as a manifest ID and attempt to pull a non-existent image from a potentially nonexistent registry even though the image exists locally. Can this be fixed? Even longer version: See thread; relevant code is here.
Long version with issue repro. I'm working to add a cross compiler to @gorgeous-winter-99296โ€™s work on bring rust to pants. See this PR. The critical part of the BUILD file is quite simple:
Copy code
docker_image(
    name = "cross-compiler",
    dependencies = [":cargo-lock"],
    source = "Dockerfile",
    skip_push = True,
    repository = "example/rust-cross-compiler",
)

docker_environment(
    name = "cross-compiler-env",
    image = "example/rust-cross-compiler",
)
I can create the image locally:
Copy code
pants package examples/docker-cross-compile:cross-compiler
09:15:49.74 [INFO] Completed: Building docker image example/rust-cross-compiler:latest
09:15:49.74 [INFO] Wrote dist/examples.docker-cross-compile/cross-compiler.docker-info.json
Built docker image: example/rust-cross-compiler:latest
Docker image ID: sha256:f180e7508550165ca5aef038aa07b32057a2463cdd3f81224a211d5145049915
But if I try to package the other targets, I hit the ๐Ÿ› mentioned above:
Copy code
pants package examples/docker-cross-compile/::
09:17:12.61 [INFO] Completed: Building docker image example/rust-cross-compiler:latest
09:17:13.31 [INFO] Completed: Pulling Docker image `sha256:f180e7508550165ca5aef038aa07b32057a2463cdd3f81224a211d5145049915` because the image is missing locally.
09:17:13.32 [ERROR] 1 Exception encountered:

Engine traceback:
  in `package` goal

IntrinsicError: Failed to pull Docker image `sha256:f180e7508550165ca5aef038aa07b32057a2463cdd3f81224a211d5145049915`: DockerResponseServerError { status_code: 404, message: "pull access denied for sha256, repository does not exist or may require 'docker login': denied: requested access to the resource is denied" }
Note the error: The image is being referenced by the image ID (which does exist locally) but it's being treated as a manifest ID (which does not exist at all):
Copy code
docker image list --digests example/rust-cross-compiler
REPOSITORY                    TAG       DIGEST    IMAGE ID       CREATED        SIZE
example/rust-cross-compiler   latest    <none>    f180e7508550   24 hours ago   1.78GB
A workaround(?) Now, I have been able to make a version of this work. Using my public dockerhub (mccoym2) I've been able to push an image and reference the manifest ID directly. It's a multistep process. First, I change the BUILD to reference my dockerhub and allow publishing to it:
Copy code
docker_image(
    name = "cross-compiler",
    dependencies = [":cargo-lock"],
    source = "Dockerfile",
    # skip_push = True,  # Allow push
    repository = "mccoym2/rust-cross-compiler",
)

docker_environment(
    name = "cross-compiler-env",
    image = "mccoym2/rust-cross-compiler",
)
Second, I publish the image:
Copy code
pants publish examples/docker-cross-compile:cross-compiler
09:21:36.66 [INFO] Completed: Building docker image mccoym2/rust-cross-compiler:latest
09:21:36.66 [INFO] Packaged examples.docker-cross-compile/cross-compiler.docker-info.json
The push refers to repository [<http://docker.io/mccoym2/rust-cross-compiler|docker.io/mccoym2/rust-cross-compiler>]
873cf0224b25: Layer already exists 
586888d725c7: Layer already exists 
5f70bf18a086: Layer already exists 
500d46b9d1bd: Layer already exists 
c9c6219cc174: Layer already exists 
bc63b413552d: Layer already exists 
9cfa8c60a416: Layer already exists 
8087b953cf2e: Layer already exists 
d9fbef8fc08c: Layer already exists 
86d145e933bc: Layer already exists 
latest: digest: sha256:631947d62cb850da3ea590bc53b91dfd4b53711eb104f3af3f83da4af04fde8b size: 2420
Note that the MANIFEST ID now appears at the final step. I can now add this to the BUILD file:
Copy code
docker_environment(
    name = "cross-compiler-env",
    image = "mccoym2/rust-cross-compiler@sha256:631947d62cb850da3ea590bc53b91dfd4b53711eb104f3af3f83da4af04fde8b",
)
Now I'm able to package everything:
Copy code
pants package examples/docker-cross-compile/::         
09:24:24.10 [INFO] Completed: Building docker image mccoym2/rust-cross-compiler:latest
09:25:14.63 [INFO] Wrote dist/examples.docker-cross-compile/cross-compiler.docker-info.json
Built docker image: mccoym2/rust-cross-compiler:latest
Docker image ID: sha256:f180e7508550165ca5aef038aa07b32057a2463cdd3f81224a211d5145049915
09:25:14.63 [INFO] Wrote dist/examples.docker-cross-compile/hello-cross
The main downsides of this workaround: 1. It doesn't allow for local development or simple examples---the image must be pushed to a registry. 2. The environment won't automatically get rebuilt. 3. I literally can't get the manifest ID locally. I have to go to dockerhub.
r
No it's not supported yet. There is an open issue https://github.com/pantsbuild/pants/issues/17714
m
Bummer. Thanks!