Skip to content

Commit e696201

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

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-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: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,35 +61,40 @@ Python 3.6 function container image looks like this:
6161
FROM fnproject/python:3.6-dev as build-stage
6262
WORKDIR /function
6363
ADD requirements.txt /function/
64+
6465
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
66+
rm -fr ~/.cache/pip /tmp* requirements.txt func.yaml Dockerfile .venv &&\
67+
chmod -R o+r /python
6668
ADD . /function/
6769
RUN rm -fr /function/.pip_cache
68-
6970
FROM fnproject/python:3.6
7071
WORKDIR /function
71-
COPY --from=build-stage /function /function
7272
COPY --from=build-stage /python /python
73-
ENV PYTHONPATH=/python
73+
COPY --from=build-stage /function /function
74+
RUN chmod -R o+r /function
75+
ENV PYTHONPATH=/function:/python
7476
ENTRYPOINT ["/python/bin/fdk", "/function/func.py", "handler"]
7577
```
7678

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
79+
It's a two stage build with the first stage containing python with build tools
80+
and the second stage with only the python runtime and minimum required dependencies.
81+
This approach is designed to ensure that deployable function container
8082
images are as small as possible, which is beneficial for a number of reasons
8183
including the time it takes to transfer the image from a Docker respository to
8284
the compute node where the function is to be run.
8385

84-
The *fnproject/python* container image is built on Debian so we'll need to install
86+
The *fnproject/python:3.6* container image needs ImageMagick from the EPEL repo, so we'll need to install
8587
the
86-
[ImageMagick Debian package](https://packages.debian.org/buster/imagemagick)
87-
using the *apt-get* package management utility.
88+
[ImageMagick package](https://yum.oracle.com/repo/OracleLinux/OL8/developer/EPEL/x86_64/index.html)
89+
using the *microdnf* package management utility.
8890
```Dockerfile
89-
RUN apt-get update && apt-get install -y imagemagick
91+
RUN microdnf install oracle-epel-release-el8 &&\
92+
microdnf install ImageMagick &&\
93+
microdnf remove oracle-epel-release-el8 &&\
94+
microdnf clean all
9095
```
9196
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.
97+
so we need to add line in the second stage.
9398

9499

95100
## Deploy the function
@@ -132,3 +137,4 @@ possible to customize your function's runtime environment including letting you
132137
install any Linux libraries or utilities that your function might need. And
133138
thanks to the Fn CLI's support for Dockerfiles it's the same user experience as
134139
when developing any function.
140+

0 commit comments

Comments
 (0)