fnproject / dockers

Docker base images for various programming languages.
https://fnproject.github.io/
35 stars 10 forks source link

Rewriting python images #14

Closed denismakogon closed 6 years ago

zootalures commented 6 years ago

Do you know how to rebuild/release these? Not sure that I do

denismakogon commented 6 years ago

@zootalures I need to check if can push an image manually.

denismakogon commented 6 years ago

@zootalures i don't have an access to fnproject dockerhub namespace, but had a month or so ago.

zootalures commented 6 years ago

this is good btw - works for me with the following Dockerfile:

FROM fnproject/python:3
WORKDIR /function
ADD . /function/

RUN  pip3 install --no-cache --no-cache-dir -r requirements.txt &&\
    rm -fr ~/.cache/pip /tmp* requirements.txt func.yaml Dockerfile .venv
ENTRYPOINT ["python3", "func.py"]

I know you looked at this before but the fn image are still ~300MB net because of the GCC deps mostly by the looks of things - any chance we could get closer to doing 2-stage python builds?

denismakogon commented 6 years ago

@zootalures, as far as I know, it's not a quite trivial to copy python compiled dependencies and it might end up having a broken build. By saying "might" I mean python dependencies can go wherever on the file system not only site-, dist-packages. So, bringing python multistage builds can be an unstable experimental thing, but not something recommended and ready for use.

denismakogon commented 6 years ago

we still need to remove build packages as it was introduced in recent CLI PR to shrink an image.

zootalures commented 6 years ago

I got python build images working as follows:

FROM fnproject/python:3 as build # sub for build image 
WORKDIR /function
ADD . /function/

RUN  pip3 install --target /python/  --no-cache --no-cache-dir -r requirements.txt &&\
    rm -fr ~/.cache/pip /tmp* requirements.txt func.yaml Dockerfile .venv

FROM python:3.6-slim-stretch # Sub for runtime image 
COPY --from=build /function /function
COPY --from=build /python /python
ENV PYTHONPATH=/python
WORKDIR /function
ENTRYPOINT ["python3", "func.py"]

The resulting image is 200MB smaller net that currently