Skip to content

Commit 486f226

Browse files
authored
Merge pull request oracle-samples#44 from metamemelord/ol8-example
Moved imagedims to OL8 base image
2 parents 12da04a + e8cc6ed commit 486f226

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

samples/imagedims-python/Dockerfile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
FROM fnproject/python:3.6-dev as build-stage
22
WORKDIR /function
33
ADD requirements.txt /function/
4+
45
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
6+
rm -fr ~/.cache/pip /tmp* requirements.txt func.yaml Dockerfile .venv &&\
7+
chmod -R o+r /python
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
12-
COPY --from=build-stage /function /function
1317
COPY --from=build-stage /python /python
14-
ENV PYTHONPATH=/python
18+
COPY --from=build-stage /function /function
19+
RUN chmod -R o+r /function
20+
ENV PYTHONPATH=/function:/python
1521
ENTRYPOINT ["/python/bin/fdk", "/function/func.py", "handler"]

samples/imagedims-python/README.md

Lines changed: 19 additions & 13 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
```
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).
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)