Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How import properly pip dependency #171

Closed
Ducatel opened this issue Mar 8, 2018 · 6 comments
Closed

How import properly pip dependency #171

Ducatel opened this issue Mar 8, 2018 · 6 comments

Comments

@Ducatel
Copy link

Ducatel commented Mar 8, 2018

Hi,
I try to make my first image build on distroless.
I wish use the python3 image with a docker multistage build.

What I did :

FROM python:3.5 AS build-env

WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --target=./ --no-cache-dir -r requirements.txt
COPY test.py ./
COPY src ./src/

################################################

FROM gcr.io/distroless/python3
COPY --from=build-env /usr/src/app /app
WORKDIR /app

CMD ["test.py"]

It's working but my source file test.py is mix with the pip dependency.
If I set the target of pip in --target=./site-packages, it will be copied in output image but cannot be used by my test.py.

I must copy my site-packages content to /usr/lib/python3.5 ?

So how I can use pip dependency "properly" ?
Thanks in advance for your help

Ps: There is any plan to upgrade python from 3.5 to 3.6 ?

@akravetz
Copy link

It's pretty straight forward using the Bazel build method: https://github.com/bazelbuild/rules_python

@Ducatel
Copy link
Author

Ducatel commented Mar 21, 2018

All of my ci/cd pipelines are built around docker file. So l prefer to use native Docker solutions.

Also the python rules are in alpha and I need to use production ready solution.

@jiel
Copy link

jiel commented Mar 22, 2018

Hello @Ducatel

I use this:

FROM python:3.5-jessie  AS build-env

ADD /app /app
WORKDIR /app

RUN pip3 install --upgrade pip
RUN pip install -r ./requirements.txt

FROM gcr.io/distroless/python3
COPY --from=build-env /app /app
COPY --from=build-env /usr/local/lib/python3.5/site-packages /usr/local/lib/python3.5/site-packages

WORKDIR /app
ENV PYTHONPATH=/usr/local/lib/python3.5/site-packages

Hope this help.

@Ducatel
Copy link
Author

Ducatel commented Mar 26, 2018

Thanks @jiel
Your solution is quite similar to what I did before.
So maybe there is no better/proper solution for using pip

@tejal29
Copy link
Member

tejal29 commented May 18, 2018

yes. We dont have docker native solutions.
We support bazel rule for apt package manager in https://github.com/GoogleContainerTools/base-images-docker/blob/master/package_managers/download_pkgs.bzl

Untill python_rules are stable, you can write a similar rule for installing from pip for a given list of python packages.
However, using the python_rules is the way to go.

@tejal29
Copy link
Member

tejal29 commented May 18, 2018

Closing this for now. Please open if you have questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants