mik-laj commented on a change in pull request #14911:
URL: https://github.com/apache/airflow/pull/14911#discussion_r599146534



##########
File path: docs/docker-stack/build.rst
##########
@@ -41,210 +80,322 @@ Debian dependencies with ``apt`` or PyPI dependencies 
with ``pip install`` or an
 You should be aware, about a few things:
 
 * The production image of airflow uses "airflow" user, so if you want to add 
some of the tools
-  as ``root`` user, you need to switch to it with ``USER`` directive of the 
Dockerfile. Also you
-  should remember about following the
+  as ``root`` user, you need to switch to it with ``USER`` directive of the 
Dockerfile and switch back to
+  ``airflow`` user when you are done. Also you should remember about following 
the
   `best practises of Dockerfiles 
<https://docs.docker.com/develop/develop-images/dockerfile_best-practices/>`_
   to make sure your image is lean and small.
 
-  .. code-block:: dockerfile
+* The PyPI dependencies in Apache Airflow are installed in the user library, 
of the "airflow" user, so
+  PIP packages are installed to ~/.local folder as if the ``--user`` flag was 
specified when running PIP.
+  Note also that using ``--no-cache-dir`` is a good idea that can help to make 
your image smaller.
 
-    FROM apache/airflow:2.0.1
-    USER root
-    RUN apt-get update \
-      && apt-get install -y --no-install-recommends \
-             my-awesome-apt-dependency-to-add \
-      && apt-get autoremove -yqq --purge \
-      && apt-get clean \
-      && rm -rf /var/lib/apt/lists/*
-    USER airflow
+* If your apt, or PyPI dependencies require some of the ``build-essential`` or 
other packages that need
+  to compile your python dependencies, then your best choice is to follow the 
"Customize the image" route,
+  because you can build a highly-optimized (for size) image this way. However 
it requires to checkout sources
+  of Apache Airflow, so you might still want to choose to add 
``build-essential`` to your image,
+  even if your image will be significantly bigger.
 
+* You can also embed your dags in the image by simply adding them with COPY 
directive of Airflow.
+  The DAGs in production image are in ``/opt/airflow/dags`` folder.
 
-* PyPI dependencies in Apache Airflow are installed in the user library, of 
the "airflow" user, so
-  you need to install them with the ``--user`` flag and WITHOUT switching to 
airflow user. Note also
-  that using --no-cache-dir is a good idea that can help to make your image 
smaller.
+* You can build your image without any need for Airflow sources. It is enough 
that you place the
+  ``Dockerfile`` and any files that are referred to (such as Dag files) in a 
separate directory and run
+  a command ``docker build . --tag my-image:my-tag`` (where ``my-image`` is 
the name you want to name it
+  and ``my-tag`` is the tag you want to tag the image with.
 
-  .. code-block:: dockerfile
+.. note::
+  As of 2.0.1 image the ``--user`` flag is turned on by default by setting 
``PIP_USER`` environment variable
+  to ``true``. This can be disabled by un-setting the variable or by setting 
it to ``false``. In the
+  2.0.0 image you had to add the ``--user`` flag as ``pip install --user`` 
command.
 
-    FROM apache/airflow:2.0.1
-    RUN pip install --no-cache-dir --user my-awesome-pip-dependency-to-add
+Examples of image extending
+---------------------------
 
-* As of 2.0.1 image the ``--user`` flag is turned on by default by setting 
``PIP_USER`` environment variable
-  to ``true``. This can be disabled by un-setting the variable or by setting 
it to ``false``.
+An ``apt`` package example
+..........................
 
+The following example adds ``vim`` to the airflow image.
 
-* If your apt, or PyPI dependencies require some of the build-essentials, then 
your best choice is
-  to follow the "Customize the image" route. However it requires to checkout 
sources of Apache Airflow,
-  so you might still want to choose to add build essentials to your image, 
even if your image will
-  be significantly bigger.
+.. exampleinclude:: docker-examples/extending/add-apt-packages/Dockerfile
+    :language: Dockerfile
+    :start-after: [START Dockerfile]
+    :end-before: [END Dockerfile]
 
-  .. code-block:: dockerfile
+A ``PyPI`` package example
+..........................
 
-    FROM apache/airflow:2.0.1
-    USER root
-    RUN apt-get update \
-      && apt-get install -y --no-install-recommends \
-             build-essential my-awesome-apt-dependency-to-add \
-      && apt-get autoremove -yqq --purge \
-      && apt-get clean \
-      && rm -rf /var/lib/apt/lists/*
-    USER airflow
-    RUN pip install --no-cache-dir --user my-awesome-pip-dependency-to-add
+The following example adds ``lxml`` python package from PyPI to the image.
 
-* You can also embed your dags in the image by simply adding them with COPY 
directive of Airflow.
-  The DAGs in production image are in ``/opt/airflow/dags`` folder.
+.. exampleinclude:: docker-examples/extending/add-pypi-packages/Dockerfile
+    :language: Dockerfile
+    :start-after: [START Dockerfile]
+    :end-before: [END Dockerfile]
+
+A ``build-essential`` requiring package example
+...............................................
+
+The following example adds ``mpi4py`` package which requires both 
``build-essential`` and ``mpi compiler``.
+
+.. exampleinclude:: 
docker-examples/extending/add-build-essential-extend/Dockerfile
+    :language: Dockerfile
+    :start-after: [START Dockerfile]
+    :end-before: [END Dockerfile]
+
+The size of this image is ~ 1.1 GB when build. As you will see further, you 
can achieve 20% reduction in
+size of the image in case you use "Customizing" rather than "Extending" the 
image.
+
+DAG embedding example
+.....................
+
+The following example adds ``test_dag.py`` to your image in the 
``/opt/airflow/dags`` folder.
+
+.. exampleinclude:: docker-examples/extending/embedding-dags/Dockerfile

Review comment:
       In the Helm documentation, we have an example that sets file 
permissions. Is it necessary? Should we unify these examples?
   
http://apache-airflow-docs.s3-website.eu-central-1.amazonaws.com/docs/helm-chart/latest/manage-dags-files.html#bake-dags-in-docker-image




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to