I’ve seen this error discussed, but with no obviou...
# general
l
I’ve seen this error discussed, but with no obvious solution:
Copy code
BinaryNotFoundError: Cannot find `unzip` on `['/bin', '/opt/homebrew/bin', '/usr/bin', '/usr/local/bin']`. Please ensure that it is installed so that Pants can download the tools Pants needs to run.
I need to build a docker image for my go app, so I defined a `environment`:
Copy code
[environments-preview.names]
linux_go = "//:linux_go"
and in my root
BUILD
:
Copy code
docker_environment(
    name="linux_go",
    platform="linux_x86_64",
    image="golang:1.21"
)
but when I use the
environment
in my
go_binary
:
Copy code
go_binary(
    name="bin",
    environment="linux_go"
)
I get the
unzip
error. I do have
unzip
installed, and everything works just fine when I build by go binary without setting
environment
. Is there an obvious solution I haven’t found for this? (or, maybe I just don’t understand
environment
, yet?)
e
The error message mentions a homebrew path. Although you can use homebrew on Linux, I don't think many people do this. Are you on Mac? If so the error is about your Mac and not the docker container. Your Mac needs unzip installed. Forget for a moment whether or not you think it should need unzip installed given what you're trying to get done in a docker container. This seems to be what the error message is saying.
Ah, I read this opposite. If you can build the go binary fine on your Mac, the error message is about the container. It's the container image that is missing unzip.
For example:
Copy code
$ docker run --rm -it golang:1.21 unzip
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "unzip": executable file not found in $PATH: unknown.
So you need an image that both includes go 1.21 and unzip (and likely other binaries Pants will complain about after you get unzip installed).
👍 1
l
Thanks, and you were right, there’s other things I need to install. the tl;dr is I want to build a go executable that can run on the image
golang:1.21
. (preferably
alpine
) But, running into newbie issues and wondering if there’s docs that can make getting started with Go + Docker easier.
e
I don't think so. You'd have to turn your learning journey into those docs and / or improve Pants to work a bit better here (maybe get the tools it needs from BusyBox automatically or revisit its decision not to provide some of these primitives in the Rust engine).
l
Ok, well I’m onboard to documenting my journey. I don’t know if any wrong decisions were made; a how-to-guide is what I’d be aiming for
@enough-analyst-54434 I was able to get docker working by extending the
golang:1.21
and installing
unzip
(only lib that was missing):
Copy code
docker_environment(
    name="linux_go",
    platform="linux_go",
    image="golang:my-own-image-with-unzip"
)
Is there a more “pants” way of managing custom dockerfiles? That is, rather than requiring I build it locally to use (or in CI), I’d be great to just have pants view it as a dependency for
docker_environment
and build it? As team member interact with our repo, I’d be great to not have them run this docker build manually (I guess I can also upload it to a registry)
e
I don't know if docker_environment targets can depend on docker targets, but I expect not. The docker target evolution was older and more careful. The environments feature is newer and developed under more pressure / had less real world testing / etc.
So, IIUC, what you did is the best you can do for now.
l
Coolio. You’ve been a great help. Yeah, not sure
docker_environment
should depend
docker
targets, what’s outlined in Use a docker_environment to build the inputs to a docker_image feels right. That said, a
docker_environment
does depend on an image, so it doesn’t feel invalid to suggest.
I might just wrap this as a setup step (to build the image) an enable
pants.backend.shell
(or
adhoc_tool
)