brash-student-40401
12/15/2022, 9:47 PMshutil.copytree(src/services/app/static, etc)
. This works fine when I run the pex target, but once I build a Docker image from it I get FileNotFoundError: [Errno 2] No such file or directory: 'src/services/app/static'
. I tried adding the directory as both a files
and resources
and having my docker target depend on it, but that didn't help. What's the magic I'm looking for here? Am I not referencing it right in the Docker image, or are those files not going to be there at all without some extra work? For reference, my dockerfile itself is simply
FROM python:3.8
ENTRYPOINT ["/bin/app.pex"]
COPY src.services.app.scripts/app.pex /bin
curved-television-6568
12/15/2022, 10:12 PMCOPY src/ src
to your Dockerfile? otherwise the files would be in the docker build context, but not available to your pex file when running in the container.curved-television-6568
12/15/2022, 10:25 PM/
in there.. Iβve not used Docker for along time, so donβt recall from the top of my head if it needs to be COPY src src/
or COPY src/ src/
or any other combo.. πbrash-student-40401
12/15/2022, 10:26 PMsrc/ src
seemed to have worked, thank you very much!glamorous-nail-59544
12/26/2022, 10:21 PMassets/
, docker in src/python/service_name/Dockerfile,
and my pex has a dependency on the right assets.
It doesn't seem like assets are getting copied automatically, and trying:
COPY /assets assets
in docker isn't working. Any ideas?enough-analyst-54434
12/26/2022, 10:25 PMCOPY assets/ assets
Note the `/`is in a different spot in my example than in yours and my example aligns with the conversation above.glamorous-nail-59544
12/26/2022, 10:27 PMglamorous-nail-59544
12/26/2022, 10:29 PMsrc/python/services_name
src/python/services_name/dockerfile
3rdparty/python/reqs
assets/asset_name
I have default roots in pants.tomlenough-analyst-54434
12/26/2022, 10:31 PMmy pex has a dependency on the right assets.How do you spell the dependency? For the files to live in the PEX the dependency must be on a
resources
target and not a `files`target - for not good reasons, but it's true today anyhow.glamorous-nail-59544
12/26/2022, 10:33 PM./pants dependencies --transitive.
And yes I am aware that they are not packaged in the pex, but I thought docker target will be smarter and copy them into the correct relative path.enough-analyst-54434
12/26/2022, 10:34 PMglamorous-nail-59544
12/26/2022, 10:35 PMenough-analyst-54434
12/26/2022, 10:35 PMenough-analyst-54434
12/26/2022, 10:36 PM./pants package the/pex:target
and then use zipinfo to inspect the PEX and make sure the files are in there.enough-analyst-54434
12/26/2022, 10:36 PMglamorous-nail-59544
12/26/2022, 10:37 PMopen
which I don't think works with resource?
Also, something interesting, adding the assets dep explicitly worked!
docker_image(name="service_name", source="Dockerfile", dependencies=["assets:files"])
enough-analyst-54434
12/26/2022, 10:37 PMenough-analyst-54434
12/26/2022, 10:38 PMglamorous-nail-59544
12/26/2022, 10:38 PMenough-analyst-54434
12/26/2022, 10:39 PMglamorous-nail-59544
12/26/2022, 10:43 PMassets/DejaVuSansCondensed.ttf:files
assets/i18n/BUILD:files
assets/i18n/responses.en.yml:files
with explicit declaration
assets/BUILD:files
assets/DejaVuSansCondensed.ttf:files
assets/cv.docx:files
assets/i18n/BUILD:files
assets/i18n/responses.en.yml:files
assets/test_image.jpg:files
I am using files cause this lib wasn't working with resource based assetsenough-analyst-54434
12/26/2022, 10:48 PMenough-analyst-54434
12/26/2022, 10:50 PMresources
targets. Something like this:
import i18n
i18n.load_path.append(Path(__file__).parent.parent / "assets")
glamorous-nail-59544
12/26/2022, 10:51 PMenough-analyst-54434
12/26/2022, 10:52 PMimportlib.resources
- for example - to access files included via the Pants `resources`concept.enough-analyst-54434
12/26/2022, 10:52 PMfiles
and resources
targets into a single `assets`target to underscore this and hopefully confuse less people.enough-analyst-54434
12/26/2022, 10:53 PMenough-analyst-54434
12/26/2022, 10:54 PM__file__
.glamorous-nail-59544
12/26/2022, 10:54 PMglamorous-nail-59544
12/26/2022, 10:55 PMresource
targetenough-analyst-54434
12/26/2022, 10:55 PMglamorous-nail-59544
12/26/2022, 10:55 PMfiles
targetenough-analyst-54434
12/26/2022, 10:56 PMglamorous-nail-59544
12/26/2022, 10:58 PMresources
as well, but as you mentioned above, if I use file I will loose he path which will make it hard to inferenough-analyst-54434
12/26/2022, 11:06 PMglamorous-nail-59544
12/26/2022, 11:09 PMglamorous-nail-59544
12/26/2022, 11:41 PMresources
are working well, the only gotcha is they don't get inferred, only files are. So I had to turn off assets
inference and explicitly define my resources deps.
I think automatically inferring resources as well would be really nice for a project structure like mine. assets
will always be at root and importing them will always be the same weather my code is packaged or not.
EDIT: looking forward to the assets
target!bitter-ability-32190
12/27/2022, 2:08 AMenough-analyst-54434
12/27/2022, 2:20 AMbitter-ability-32190
12/27/2022, 2:26 AM__name__
)bitter-ability-32190
12/27/2022, 2:35 AMenough-analyst-54434
12/27/2022, 2:44 AMglamorous-nail-59544
12/27/2022, 2:14 PMassets
dir in the repo root. I couldn't find a way to load them using importlib
or pkgutil
, so can't get pants to infer them π€·ββοΈbitter-ability-32190
12/27/2022, 2:33 PM