@@ -58,38 +58,47 @@ The Dockerfile that "fn build" would automatically generate to build a
58
58
Python 3.6 function container image looks like this:
59
59
60
60
``` Dockerfile
61
- FROM fnproject/python:3.6-dev as build-stage
61
+ FROM fnproject/python:3.6-dev
62
62
WORKDIR /function
63
63
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
66
68
ADD . /function/
67
69
RUN rm -fr /function/.pip_cache
68
70
69
71
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
70
76
WORKDIR /function
71
77
COPY --from=build-stage /function /function
72
78
COPY --from=build-stage /python /python
73
- ENV PYTHONPATH=/python
79
+ ENV PYTHONPATH=/python:/function
74
80
ENTRYPOINT ["/python/bin/fdk" , "/function/func.py" , "handler" ]
75
81
```
76
82
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
80
86
images are as small as possible, which is beneficial for a number of reasons
81
87
including the time it takes to transfer the image from a Docker respository to
82
88
the compute node where the function is to be run.
83
89
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
85
91
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.
88
94
``` 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
90
99
```
91
100
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 .
93
102
94
103
95
104
## Deploy the function
@@ -132,3 +141,4 @@ possible to customize your function's runtime environment including letting you
132
141
install any Linux libraries or utilities that your function might need. And
133
142
thanks to the Fn CLI's support for Dockerfiles it's the same user experience as
134
143
when developing any function.
144
+
0 commit comments