@@ -61,35 +61,40 @@ Python 3.6 function container image looks like this:
61
61
FROM fnproject/python:3.6-dev as build-stage
62
62
WORKDIR /function
63
63
ADD requirements.txt /function/
64
+
64
65
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
66
68
ADD . /function/
67
69
RUN rm -fr /function/.pip_cache
68
-
69
70
FROM fnproject/python:3.6
70
71
WORKDIR /function
71
- COPY --from=build-stage /function /function
72
72
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
74
76
ENTRYPOINT ["/python/bin/fdk" , "/function/func.py" , "handler" ]
75
77
```
76
78
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
80
82
images are as small as possible, which is beneficial for a number of reasons
81
83
including the time it takes to transfer the image from a Docker respository to
82
84
the compute node where the function is to be run.
83
85
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
85
87
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.
88
90
``` 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
90
95
```
91
- 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 .
96
+ We want to install ImageMagick into the runtime image, not the build image, so we need to
97
+ add the above lines in the second stage as shown in the merged [ Dockerfile ] ( ./Dockerfile ) .
93
98
94
99
95
100
## Deploy the function
@@ -132,3 +137,4 @@ possible to customize your function's runtime environment including letting you
132
137
install any Linux libraries or utilities that your function might need. And
133
138
thanks to the Fn CLI's support for Dockerfiles it's the same user experience as
134
139
when developing any function.
140
+
0 commit comments