From 8835d8ebcee55d93fe53fd972899b932cec85c8a Mon Sep 17 00:00:00 2001 From: Charles de Beauchesne Date: Mon, 3 Jul 2023 10:14:53 +0200 Subject: [PATCH] Optimize python build time #562 --- .../build/docker/python/django-poc.Dockerfile | 19 +------------- .../docker/python/django-poc.base.Dockerfile | 25 +++++++++++++++++++ .../build/docker/python/flask-poc.Dockerfile | 12 ++------- .../docker/python/flask-poc.base.Dockerfile | 15 +++++++++++ .../build/docker/python/uds-flask.Dockerfile | 9 +------ .../build/docker/python/uwsgi-poc.Dockerfile | 9 +------ .../docker/python/uwsgi-poc.base.Dockerfile | 15 +++++++++++ 7 files changed, 60 insertions(+), 44 deletions(-) create mode 100644 utils/build/docker/python/django-poc.base.Dockerfile create mode 100644 utils/build/docker/python/flask-poc.base.Dockerfile create mode 100644 utils/build/docker/python/uwsgi-poc.base.Dockerfile diff --git a/utils/build/docker/python/django-poc.Dockerfile b/utils/build/docker/python/django-poc.Dockerfile index 621cb688cb..2f86622523 100644 --- a/utils/build/docker/python/django-poc.Dockerfile +++ b/utils/build/docker/python/django-poc.Dockerfile @@ -1,26 +1,9 @@ -FROM python:3.9 - -# print versions -RUN python --version && curl --version - -# install hello world app -RUN pip install django pycryptodome gunicorn gevent requests - -RUN mkdir app -RUN django-admin startproject django_app app -WORKDIR /app -RUN python3 manage.py startapp app - -RUN sed -i "1s/^/from django.urls import include\n/" django_app/urls.py -RUN sed -i "s/admin\///g" django_app/urls.py -RUN sed -i "s/admin.site.urls/include(\"app.urls\")/g" django_app/urls.py -RUN sed -i "s/ALLOWED_HOSTS\s=\s\[\]/ALLOWED_HOSTS = \[\"0.0.0.0\",\"weblog\"\,\"localhost\"\]/g" django_app/settings.py +FROM datadog/system-tests:django-poc.base-v0 COPY utils/build/docker/python/django/app.sh /app/app.sh COPY utils/build/docker/python/django/django.app.urls.py /app/app/urls.py COPY utils/build/docker/python/iast.py /app/iast.py - COPY utils/build/docker/python/install_ddtrace.sh utils/build/docker/python/get_appsec_rules_version.py binaries* /binaries/ RUN /binaries/install_ddtrace.sh diff --git a/utils/build/docker/python/django-poc.base.Dockerfile b/utils/build/docker/python/django-poc.base.Dockerfile new file mode 100644 index 0000000000..d195eaad03 --- /dev/null +++ b/utils/build/docker/python/django-poc.base.Dockerfile @@ -0,0 +1,25 @@ +FROM python:3.9-slim + +# install bin dependancies +RUN apt-get update && apt-get install -y curl git gcc g++ + +# print versions +RUN python --version && curl --version + +# install python deps +RUN pip install django pycryptodome gunicorn gevent requests + +RUN mkdir app +RUN django-admin startproject django_app app +WORKDIR /app +RUN python3 manage.py startapp app + +RUN sed -i "1s/^/from django.urls import include\n/" django_app/urls.py +RUN sed -i "s/admin\///g" django_app/urls.py +RUN sed -i "s/admin.site.urls/include(\"app.urls\")/g" django_app/urls.py +RUN sed -i "s/ALLOWED_HOSTS\s=\s\[\]/ALLOWED_HOSTS = \[\"0.0.0.0\",\"weblog\"\,\"localhost\"\]/g" django_app/settings.py + + +# docker build --progress=plain -f utils/build/docker/python/django-poc.base.Dockerfile -t datadog/system-tests:django-poc.base-v0 . +# docker push datadog/system-tests:django-poc.base-v0 + diff --git a/utils/build/docker/python/flask-poc.Dockerfile b/utils/build/docker/python/flask-poc.Dockerfile index 14c188e40d..6c61a2c39a 100644 --- a/utils/build/docker/python/flask-poc.Dockerfile +++ b/utils/build/docker/python/flask-poc.Dockerfile @@ -1,11 +1,4 @@ -FROM python:3.9 - -# print versions -RUN python --version && curl --version - -# install hello world app -# Tracer does not support flask 2.3.0 or higher, pin the flask version for now -RUN pip install flask==2.2.4 gunicorn gevent requests pycryptodome psycopg2 +FROM datadog/system-tests:flask-poc.base-v0 COPY utils/build/docker/python/flask /app COPY utils/build/docker/python/iast.py /app/iast.py @@ -23,6 +16,5 @@ ENV DD_REMOTECONFIG_POLL_SECONDS=1 ENV FLASK_APP=app.py CMD ./app.sh -# docker build -f utils/build/docker/python.flask-poc.Dockerfile -t test . +# docker build -f utils/build/docker/python/flask-poc.Dockerfile -t test . # docker run -ti -p 7777:7777 test - diff --git a/utils/build/docker/python/flask-poc.base.Dockerfile b/utils/build/docker/python/flask-poc.base.Dockerfile new file mode 100644 index 0000000000..6fb787a086 --- /dev/null +++ b/utils/build/docker/python/flask-poc.base.Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.9-slim + +# install bin dependancies +RUN apt-get update && apt-get install -y curl git gcc g++ + +# print versions +RUN python --version && curl --version + +# install python deps +# Tracer does not support flask 2.3.0 or higher, pin the flask version for now +RUN pip install flask==2.2.4 gunicorn gevent requests pycryptodome psycopg2-binary + +# docker build --progress=plain -f utils/build/docker/python/flask-poc.base.Dockerfile -t datadog/system-tests:flask-poc.base-v0 . +# docker push datadog/system-tests:flask-poc.base-v0 + diff --git a/utils/build/docker/python/uds-flask.Dockerfile b/utils/build/docker/python/uds-flask.Dockerfile index 2a1acffb4b..a392cda16f 100644 --- a/utils/build/docker/python/uds-flask.Dockerfile +++ b/utils/build/docker/python/uds-flask.Dockerfile @@ -1,11 +1,4 @@ -FROM python:3.9 - -# print versions -RUN python --version && curl --version - -# install hello world app -# Tracer does not support flask 2.3.0 or higher, pin the flask version for now -RUN pip install flask==2.2.4 gunicorn gevent requests pycryptodome psycopg2 +FROM datadog/system-tests:flask-poc.base-v0 COPY utils/build/docker/python/flask /app COPY utils/build/docker/python/iast.py /app/iast.py diff --git a/utils/build/docker/python/uwsgi-poc.Dockerfile b/utils/build/docker/python/uwsgi-poc.Dockerfile index c2146bc1f3..3ceecdd37e 100644 --- a/utils/build/docker/python/uwsgi-poc.Dockerfile +++ b/utils/build/docker/python/uwsgi-poc.Dockerfile @@ -1,11 +1,4 @@ -FROM python:3.9 - -# print versions -RUN python --version && curl --version - -# install hello world app -# Tracer does not support flask 2.3.0 or higher, pin the flask version for now -RUN pip install flask==2.2.4 uwsgi requests pycryptodome psycopg2 +FROM datadog/system-tests:uwsgi-poc.base-v0 COPY utils/build/docker/python/flask /app COPY utils/build/docker/python/iast.py /app/iast.py diff --git a/utils/build/docker/python/uwsgi-poc.base.Dockerfile b/utils/build/docker/python/uwsgi-poc.base.Dockerfile new file mode 100644 index 0000000000..51cd7425dd --- /dev/null +++ b/utils/build/docker/python/uwsgi-poc.base.Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.9-slim + +# install bin dependancies +RUN apt-get update && apt-get install -y curl git gcc g++ + +# print versions +RUN python --version && curl --version + +# install python deps +# Tracer does not support flask 2.3.0 or higher, pin the flask version for now +RUN pip install flask==2.2.4 uwsgi gevent requests pycryptodome psycopg2-binary + +# docker build --progress=plain -f utils/build/docker/python/uwsgi-poc.base.Dockerfile -t datadog/system-tests:uwsgi-poc.base-v0 . +# docker push datadog/system-tests:uwsgi-poc.base-v0 +