Are files from `sources` from a `python_sources` t...
# general
q
Are files from
sources
from a
python_sources
target not added to a
docker_image
target even if its added a dependency?
My BUILD file looks like this
Copy code
docker_image(
    name='docker-image',
    repository="my-app",
    context_root="./",
    dependencies=[
        ':source', 
        ':files',
    ],
    image_tags=["latest"]
)

python_sources(
    name='source',
    sources=[
        '**/*.py',
        '*.py'
    ],
    resolve="admin-app",
)

files(
    name='files',
    sources=[
        'requirements.txt',
        'configs/*',
        'data/**/*'
    ],
)
and the
Dockerfile
has a line
Copy code
COPY . /app/
The files in the
files
target are copied. But the
*.py
source files from the
source
target are not.
s
yeah, python_sources and files are different things, you can add *.py to your
files.sources
to copy python files as files
by design your are supposed to create something like pex_binary first and then put it into docker image
c
Gregory is absolutely right.. see docs for more details.
q
Havent played around with pex much. Just trying to move some repos into a monorepo and want to ensure I can get them to work as is first in the new setup and then deep dive into migrating to Pex later. But I’ll add them to
files.sources
per Gregory’s suggestion for now and move on. Thanks for pointing me to the docs!
s
If you just want them to work as is, then you don't need to use
pants package docker-image
for the images, just use
COPY . .
and regular
docker build .
just an option to consider 🙂
q
yes, but using pants package was a success criteria I set for myself 😆
😄 1
s
I encourage you to give the pex_binary a shot, here is a very short example how to make it work https://www.pantsbuild.org/blog/2022/08/02/optimizing-python-docker-deploys-using-pants#a-very-simple-example
q
Will I need to deviate from this if the thing I am running in the docker image is a streamlit app and not a simple python script?
s
probably yes, because streamlit doesn't support modules https://github.com/streamlit/streamlit/issues/662
😢 1