polite-secretary-23285
02/16/2022, 2:53 PMcurved-television-6568
02/16/2022, 2:55 PMFROM
your base image is that what you add with COPY
or ADD
or as a side effect of any RUN
instructions, so there’s no magic going on here.curved-television-6568
02/16/2022, 2:56 PMpex
files etc that you may be including?polite-secretary-23285
02/16/2022, 3:01 PMfresh-cat-90827
02/16/2022, 4:17 PM.pex
files you’ve included contain both the source code of your project code and the 3rd party dependencies the project has as wheels. If there are a lot of dependencies (and they have compiled code such as numpy
, pandas
, scipy
etc) then the .pex
files may become large. For anecdotal stats, the largest one I see locally is 200 MB.
It is possible to create multi-platform PEX files so that the very same .pex
file can be distributed and run both on Linux and MacOS device. This is achieved by adding multiple platform tags for the pex_binary
target declaration. This will make sure that the .pex
file contains wheels for both platforms (e.g., there will be one .whl
file for numpy
compiled for MacOS and one .whl
file for numpy
compiled for Linux).
If there are many requirements with compiled non-Python code, a multi-platform PEX file can be significantly larger than a platform-specific one, so make sure to include only those platforms that need to be supported.polite-secretary-23285
02/16/2022, 4:35 PMcurved-television-6568
02/16/2022, 6:46 PMCOPY
instructions in your Dockerfile, leveraging the Docker caching.curved-television-6568
02/16/2022, 6:50 PMpolite-secretary-23285
02/16/2022, 7:03 PMhundreds-father-404
02/18/2022, 4:44 PMpolite-secretary-23285
02/19/2022, 11:09 AMicy-hair-30586
02/25/2022, 9:30 PMenough-analyst-54434
02/25/2022, 10:32 PMlayout
field, but they're pretty hacky. If this is a wide enough neeed, and it sounds like it is!, it's proably better to get an issue started to flesh out an approach.enough-analyst-54434
02/25/2022, 10:33 PMhundreds-father-404
02/25/2022, 10:35 PMhttps://pantsbuild.slack.com/archives/C046T6T9U/p1645037178557369?thread_ts=1645023217.440459&cid=C046T6T9U@curved-television-6568, are you using this workflow now?
curved-television-6568
02/25/2022, 10:37 PMhundreds-father-404
02/25/2022, 10:40 PMenough-analyst-54434
02/25/2022, 10:44 PMenough-analyst-54434
02/25/2022, 10:49 PMRUN PEX_TOOLS=1 ./my.pex venv --deps-only right/here
RUN PEX_TOOLS=1 ./my.pex venv --source-only right/here
enough-analyst-54434
02/25/2022, 10:50 PMfresh-cat-90827
02/25/2022, 11:00 PMpex_binary(
name='tabulate-runner',
description='Run tabulate on the input files.',
entry_point='tabulate',
dependencies=["//:tabulate"],
shebang='/usr/bin/python3',
)
After packaging this (having tabulate
in the root requirements.txt
), I can now run:
$ cat data.txt
col1,col2,col3
val1,val2,val3
$ ./tabulate-runner.pex --header --sep "," data.txt
col1 col2 col3
------ ------ ------
val1 val2 val3
In other words, you can create PEX files using Pants (this can also be achieved using plain pex
utility of course) that would contain only a single dependency that you could run. Is this any helpful?curved-television-6568
02/25/2022, 11:04 PMenough-analyst-54434
02/25/2022, 11:06 PMenough-analyst-54434
02/25/2022, 11:07 PMenough-analyst-54434
02/26/2022, 5:45 AM^jsirois@gill /tmp/docker-test $ cat file1.txt
Same content.
Different content.
^jsirois@gill /tmp/docker-test $ cat Dockerfile1
FROM busybox AS prep
COPY file1.txt /
RUN head -1 file1.txt > /content
FROM alpine
COPY --from=prep /content /
CMD ["cat", "/content"]
^jsirois@gill /tmp/docker-test $ cat file2.txt
Same content.
DIFFERENT CONTENT
^jsirois@gill /tmp/docker-test $ cat Dockerfile2
FROM busybox AS prep
COPY file2.txt /
RUN head -1 file2.txt > /content
FROM alpine
COPY --from=prep /content /
CMD ["cat", "/content"]
^jsirois@gill ~/Downloads/docker-test $ docker build -t image1 -f Dockerfile1 .
Sending build context to Docker daemon 6.656kB
Step 1/6 : FROM busybox AS prep
---> 7138284460ff
Step 2/6 : COPY file1.txt /
---> 8d439976acc6
Step 3/6 : RUN head -1 file1.txt > /content
---> Running in d261924d69f7
Removing intermediate container d261924d69f7
---> 08661326e660
Step 4/6 : FROM alpine
---> 0a97eee8041e
Step 5/6 : COPY --from=prep /content /
---> 9608c4649999
Step 6/6 : CMD ["cat", "/content"]
---> Running in 79e88cb4d61f
Removing intermediate container 79e88cb4d61f
---> af753bc108ea
Successfully built af753bc108ea
Successfully tagged image1:latest
^jsirois@gill ~/Downloads/docker-test $ docker build -t image2 -f Dockerfile2 .
Sending build context to Docker daemon 6.656kB
Step 1/6 : FROM busybox AS prep
---> 7138284460ff
Step 2/6 : COPY file2.txt /
---> 7da9dee5433d
Step 3/6 : RUN head -1 file2.txt > /content
---> Running in 661242608a2e
Removing intermediate container 661242608a2e
---> 6e858bb951cd
Step 4/6 : FROM alpine
---> 0a97eee8041e
Step 5/6 : COPY --from=prep /content /
---> Using cache
---> 9608c4649999
Step 6/6 : CMD ["cat", "/content"]
---> Using cache
---> af753bc108ea
Successfully built af753bc108ea
Successfully tagged image2:latest
^jsirois@gill ~/Downloads/docker-test $ docker run --rm image1
Same content.
^jsirois@gill ~/Downloads/docker-test $ docker run --rm image2
Same content.
^jsirois@gill ~/Downloads/docker-test $ docker image inspect image1 | jq '.[] | {"Id", "RepoTags", "RootFS"}'
{
"Id": "sha256:af753bc108ea9b5827fde0dde0472c822d05d4119803b2a7e2205614d00d9a53",
"RepoTags": [
"image1:latest",
"image2:latest"
],
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:1a058d5342cc722ad5439cacae4b2b4eedde51d8fe8800fcf28444302355c16d",
"sha256:3f093a6664ad9960eeaae1facc5f32f087f066421c8e251b045170d022f417ef"
]
}
}
^jsirois@gill ~/Downloads/docker-test $ docker image inspect image2 | jq '.[] | {"Id", "RepoTags", "RootFS"}'
{
"Id": "sha256:af753bc108ea9b5827fde0dde0472c822d05d4119803b2a7e2205614d00d9a53",
"RepoTags": [
"image1:latest",
"image2:latest"
],
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:1a058d5342cc722ad5439cacae4b2b4eedde51d8fe8800fcf28444302355c16d",
"sha256:3f093a6664ad9960eeaae1facc5f32f087f066421c8e251b045170d022f417ef"
]
}
}
So my proposal would work.icy-hair-30586
02/26/2022, 1:57 PMenough-analyst-54434
02/26/2022, 6:26 PMicy-hair-30586
02/26/2022, 8:49 PMRUN pip install dependencies
and then RUN pip install mypackage
in the docker fileicy-hair-30586
02/26/2022, 8:50 PMenough-analyst-54434
02/26/2022, 8:55 PM--layout packed
to strike a balance between cache hits for unchanged portions of a venv and sandbox materialization performance. All of this also applies when remote caching is turned on too.enough-analyst-54434
02/26/2022, 9:00 PMenough-analyst-54434
02/26/2022, 9:03 PMenough-analyst-54434
02/28/2022, 7:06 PM