Hello! I’ve seen a few threads related to this but...
# general
s
Hello! I’ve seen a few threads related to this but I am still at a loss. I am attempting to build a Go Binary for a docker container on my M1 Mac. I’ve attempted to use Docker Desktop and Colima and have run into issues either way. I would appreciate some pointers on how to get this set up correctly! *pants.to*ml
Copy code
[docker]
build_args = ["GIT_COMMIT=local"]


[environments-preview.names]
osx = "//:local_osx"
linux_docker = "//:linux_docker"
BUILD
Copy code
local_environment(name="local_osx", compatible_platforms=["macos_arm64"])

docker_environment(
    name="linux_docker",
    platform="linux_x86_64",
    image="ubuntu:22.04",
)
go BUILD file
Copy code
go_binary(name="bin", environment=parametrize("osx", "linux_docker"))

go_package()
Dockerfile
Copy code
FROM golang:1.20

WORKDIR /app

COPY src.go.cmd.proglog/bin@environment=linux_docker /app/proglog

CMD [ "/app/proglog" ]
The error in question
Copy code
pants package ::                                                                                                                                                    1 ↵
16:23:47.94 [INFO] Initializing scheduler...
16:23:48.39 [INFO] Scheduler initialized.
16:23:58.09 [ERROR] 1 Exception encountered:

Engine traceback:
  in `package` goal

IntrinsicError: Failed to start Docker container `cd7d8eee4e86c465bcffedfc161a2020d9798707b3ec219ecbdc66e3dbfdeed1` for image `sha256:0bced47fffa3361afa981854fcabcd4577cd43cebbb808cea2b1f33a3dd7f508`: JsonSerdeError { err: Error("expected value", line: 1, column: 1) }
I’m able to run the equivalent image through docker normally, so it’s entirely possible that something else is going on
docker run -ti --rm --platform=linux/amd64 ubuntu:22.04 /bin/bash
e
2nd search hit: https://pantsbuild.slack.com/archives/C046T6T9U/p1682991196531589?thread_ts=1682990057.975249&cid=C046T6T9U You don't have env vars poked through in your config above, that exchange indicates you must.
s
The error seems to be somewhere with the go binary environment - I removed the parametrize from the
go_binary
target and
pants package ::
was successful. I was able to get a working docker build with this config. The only problem is it’s using the M1 mac compiled binary
Copy code
[docker]
build_args = ["GIT_COMMIT=local"]
env_vars = [
    "DOCKER_CONTEXT=default",
]
Copy code
pants run src/go:docker-osx                                                                                                                                         
17:11:28.28 [INFO] Completed: Building docker image docker-osx:latest
exec /app/proglog: exec format error
Bumping with some additional details (sorry if this isn’t allowed - I figured this would be easier then prepping another thread): I am only using
Docker Desktop 4.21.1
and
Pants 2.16.0
- I updated my
pants.toml - [docker]
section to this
Copy code
[docker]
build_args = ["GIT_COMMIT=local"]
env_vars = [
    "DOCKER_CONTEXT=default",
    "DOCKER_HOST=/var/run/docker.sock",
    "USER=%(user)s",
    "HOME=%(homedir)s",
    "PATH"
]
tools = [
  "sw_vers"
]
The root of the issue seems to be occurring when spinning up the docker environment. I’ve tried building the go binary myself to some success, but I would hate to lose the dependency inference (and squash this bug/misconfiguration :))
Copy code
pants --keep-sandboxes=on_failure package src/go/cmd/proglog:bin@environment=linux_docker
Any thoughts would be helpful - This has become a blocker for one of my side projects and I would love to start working on it soon!
c
do the envvars to punch through the docker host need to go at the subprocess-environment scope? https://www.pantsbuild.org/docs/reference-subprocess-environment#env_vars
s
Here are the debug logs after adding those subprocess env_vars - looks like the same result to me. That seems like a good direction to focus on though!
e
Sounds good to the ear, but these are only used for the Python backend: https://github.com/search?q=repo%3Apantsbuild%2Fpants%20SubprocessEnvironmentVars&type=code
s
I ended up wiping my docker desktop install which seemed to solving my issue. From what i can tell it was some sort of misconfiguration on my end
h
Yeah that option is misnamed (or we should make it do what it says on the tin and use it for all processes)
n
chiming in much later here, if you do these two things, one in your
pants.toml
and the other in Docker Desktop (Advanced Settings) you should be g2g