Skip to content

Commit 807b02f

Browse files
committed
Moved example to functions new base images
1 parent 12da04a commit 807b02f

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

samples/imagedims-python/Dockerfile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
FROM fnproject/python:3.6-dev as build-stage
1+
FROM fnproject/python:3.6-dev
22
WORKDIR /function
33
ADD requirements.txt /function/
4-
RUN pip3 install --target /python/ --no-cache --no-cache-dir -r requirements.txt &&\
5-
rm -fr ~/.cache/pip /tmp* requirements.txt func.yaml Dockerfile .venv
4+
RUN pip3 install --no-cache --no-cache-dir --upgrade pip && \
5+
pip3 install --target /python/ --no-cache --no-cache-dir -r requirements.txt && \
6+
rm -fr ~/.cache/pip /tmp* requirements.txt func.yaml Dockerfile .venv && \
7+
chmod -R o+r /function
68
ADD . /function/
79
RUN rm -fr /function/.pip_cache
810

911
FROM fnproject/python:3.6
10-
RUN apt-get update && apt-get install -y imagemagick
12+
RUN microdnf install oracle-epel-release-el8 &&\
13+
microdnf install ImageMagick &&\
14+
microdnf remove oracle-epel-release-el8 &&\
15+
microdnf clean all
1116
WORKDIR /function
1217
COPY --from=build-stage /function /function
1318
COPY --from=build-stage /python /python
14-
ENV PYTHONPATH=/python
19+
ENV PYTHONPATH=/python:/function
1520
ENTRYPOINT ["/python/bin/fdk", "/function/func.py", "handler"]
21+

samples/imagedims-python/README.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,38 +58,47 @@ The Dockerfile that "fn build" would automatically generate to build a
5858
Python 3.6 function container image looks like this:
5959

6060
```Dockerfile
61-
FROM fnproject/python:3.6-dev as build-stage
61+
FROM fnproject/python:3.6-dev
6262
WORKDIR /function
6363
ADD requirements.txt /function/
64-
RUN pip3 install --target /python/ --no-cache --no-cache-dir -r requirements.txt &&\
65-
rm -fr ~/.cache/pip /tmp* requirements.txt func.yaml Dockerfile .venv
64+
RUN pip3 install --no-cache --no-cache-dir --upgrade pip && \
65+
pip3 install --target /python/ --no-cache --no-cache-dir -r requirements.txt && \
66+
rm -fr ~/.cache/pip /tmp* requirements.txt func.yaml Dockerfile .venv && \
67+
chmod -R o+r /function
6668
ADD . /function/
6769
RUN rm -fr /function/.pip_cache
6870

6971
FROM fnproject/python:3.6
72+
RUN microdnf install oracle-epel-release-el8 &&\
73+
microdnf install ImageMagick &&\
74+
microdnf remove oracle-epel-release-el8 &&\
75+
microdnf clean all
7076
WORKDIR /function
7177
COPY --from=build-stage /function /function
7278
COPY --from=build-stage /python /python
73-
ENV PYTHONPATH=/python
79+
ENV PYTHONPATH=/python:/function
7480
ENTRYPOINT ["/python/bin/fdk", "/function/func.py", "handler"]
7581
```
7682

77-
It's a two stage build with the *fnproject/python:3.6-dev* image containing *pip* and
78-
other build tools, and the *fnproject/python:3.6* image containing just the Python
79-
runtime. This approach is designed to ensure that deployable function container
83+
It's a two stage build with the first stage containing python with build tools
84+
and the second stage with only the python runtime and minimum required dependencies.
85+
This approach is designed to ensure that deployable function container
8086
images are as small as possible, which is beneficial for a number of reasons
8187
including the time it takes to transfer the image from a Docker respository to
8288
the compute node where the function is to be run.
8389

84-
The *fnproject/python* container image is built on Debian so we'll need to install
90+
The *fnproject/python:3.6* container image needs ImageMagick from the EPEL repo, so we'll need to install
8591
the
86-
[ImageMagick Debian package](https://packages.debian.org/buster/imagemagick)
87-
using the *apt-get* package management utility.
92+
[ImageMagick package](https://yum.oracle.com/repo/OracleLinux/OL8/developer/EPEL/x86_64/index.html)
93+
using the *microdnf* package management utility.
8894
```Dockerfile
89-
RUN apt-get update && apt-get install -y imagemagick
95+
RUN microdnf install oracle-epel-release-el8 &&\
96+
microdnf install ImageMagick &&\
97+
microdnf remove oracle-epel-release-el8 &&\
98+
microdnf clean all
9099
```
91100
We want to install ImageMagick into the runtime image, not the build image,
92-
so we need to add the *RUN* command after the *FROM fnproject/python:3.6* line.
101+
so we need to add line in the second stage.
93102

94103

95104
## Deploy the function
@@ -132,3 +141,4 @@ possible to customize your function's runtime environment including letting you
132141
install any Linux libraries or utilities that your function might need. And
133142
thanks to the Fn CLI's support for Dockerfiles it's the same user experience as
134143
when developing any function.
144+

0 commit comments

Comments
 (0)