Looking for a little guidance on building a docker...
# general
s
Looking for a little guidance on building a docker target (details in thread)
BUILD:
Copy code
python_library(
    name = "bar",
    sources = ["bar/*.py"]
)

python_tests(
    name="test",
    sources = ["test/test_*.py"]
)

pex_binary(
    name="server",
    entry_point="bar/server.py:main"
)

docker_image(
    name='docker',
    sources=["Dockerfile"]
)
Dockerfile:
Copy code
ARG PY_VERSION=3.9
ARG VERSION=${PY_VERSION}-slim-buster

FROM python:${VERSION}
ENTRYPOINT [ "/bin/server" ]
COPY server.pex /bin/server
Roots:
core
foo
bar
File structure (
bar
) • monoreop ◦ bar ▪︎ bar (contains the code) ▪︎ test (contains the tests) ▪︎ Dockerfile ▪︎ BUILD
Error:
Copy code
COPY failed: file not found in build context or excluded by .dockerignore: stat server.pex: file does not exist
c
Try
COPY bar/server.pex /bin/server
s
Sorry I should have mentioned that I'd tried this initially and it didn't work
h
What does
./pants roots
say?
s
Copy code
.
core
foo
bar
thirdparty/python
h
What happens if you add an explicit dep from the
docker_image
target onto
:server
? It should be inferred, but let's find out
s
@happy-kitchen-89482 you mean
bar
like so:
Copy code
docker_image(
    name='docker',
    dependencies=[":bar"],
    sources=["Dockerfile"]
)
it still cant find
bar/server.pex
or
server.pex
c
Sorry for delay in reply; I'm out of town, will look at it when I get back tomorrow..
h
I did mean
:server
since the pex is what the docker image consumes. And the
server
target should have a dep on
:bar
, since that is what it consumes in turn.
And I think you need to be on 2.8.0rc0 ?
Which Pants version are you on?
c
@stale-nightfall-29801 I’m finally back at the “office”. If you add a dependency from your
docker_image
to the pex binary
:server
as Benjy suggested, then run
./pants -ldebug package bar:docker
and check for the log that reads
"Packages for Docker image: …"
should tell you what the pex binary name is that you can use.
s
logs.txt
I can't seem to see the
pex
binary in this:
relevant section of BUILD:
Copy code
docker_image(
    name='docker_server',
    dependencies=[":bar"],
    sources=["Dockerfile"]
)
Sorry forgot to @curved-television-6568 ☝️, thanks again for all the help
c
Hi, change
dependencies=[":bar"],
to
dependencies=[":server"]
which is the name of your pex binary target.
Thank you for your patience troubleshooting this experimental feature! 🙂
Lessons learned here will help us improve the experience going forward..
❤️ 2
s
Thank you 🙂 This worked 💥
👍 1
c
Thanks for getting back. We could improve the experience here by looking at what you were trying to copy, and find a solution for it as a suggested course of action in the error message. 🤔