|
| 1 | +ARG PYTHON_VERSION=3.11-bullseye |
| 2 | + |
| 3 | +# define an alias for the specfic python version used in this file. |
| 4 | +FROM python:${PYTHON_VERSION} AS python |
| 5 | + |
| 6 | +# Python build stage |
| 7 | +FROM python AS python-build-stage |
| 8 | + |
| 9 | +ARG BUILD_ENVIRONMENT=local |
| 10 | + |
| 11 | +# Install apt packages |
| 12 | +RUN apt-get update && apt-get install --no-install-recommends -y \ |
| 13 | + # dependencies for building Python packages |
| 14 | + build-essential \ |
| 15 | + git \ |
| 16 | + # psycopg2 dependencies |
| 17 | + libpq-dev |
| 18 | + |
| 19 | +# Requirements are installed here to ensure they will be cached. |
| 20 | +COPY ./requirements . |
| 21 | + |
| 22 | +# Update pip |
| 23 | +RUN python -m pip install --upgrade pip |
| 24 | + |
| 25 | +# Create Python Dependency and Sub-Dependency Wheels. |
| 26 | +RUN pip wheel --wheel-dir /usr/src/app/wheels \ |
| 27 | + -r ${BUILD_ENVIRONMENT}.txt |
| 28 | + |
| 29 | + |
| 30 | +# Python 'run' stage |
| 31 | +FROM python AS python-run-stage |
| 32 | + |
| 33 | +ARG BUILD_ENVIRONMENT=local |
| 34 | +ARG APP_HOME=/app |
| 35 | + |
| 36 | +ENV PYTHONUNBUFFERED 1 |
| 37 | +ENV PYTHONDONTWRITEBYTECODE 1 |
| 38 | +ENV BUILD_ENV ${BUILD_ENVIRONMENT} |
| 39 | + |
| 40 | +WORKDIR ${APP_HOME} |
| 41 | + |
| 42 | +# Install required system dependencies |
| 43 | +RUN apt-get update && apt-get install --no-install-recommends -y \ |
| 44 | + # psycopg2 dependencies |
| 45 | + libpq-dev \ |
| 46 | + # Translations dependencies |
| 47 | + gettext \ |
| 48 | + # cleaning up unused files |
| 49 | + && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ |
| 50 | + && rm -rf /var/lib/apt/lists/* |
| 51 | + |
| 52 | +# All absolute dir copies ignore workdir instruction. All relative dir copies are wrt to the workdir instruction |
| 53 | +# copy python dependency wheels from python-build-stage |
| 54 | +COPY --from=python-build-stage /usr/src/app/wheels /wheels/ |
| 55 | + |
| 56 | +# use wheels to install python dependencies |
| 57 | +RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \ |
| 58 | + && rm -rf /wheels/ |
| 59 | + |
| 60 | +COPY ./compose/production/django/entrypoint /entrypoint |
| 61 | +RUN sed -i 's/\r$//g' /entrypoint |
| 62 | +RUN chmod +x /entrypoint |
| 63 | + |
| 64 | +COPY ./compose/local/django/start /start |
| 65 | +RUN sed -i 's/\r$//g' /start |
| 66 | +RUN chmod +x /start |
| 67 | + |
| 68 | + |
| 69 | +COPY ./compose/local/django/celery/worker/start /start-celeryworker |
| 70 | +RUN sed -i 's/\r$//g' /start-celeryworker |
| 71 | +RUN chmod +x /start-celeryworker |
| 72 | + |
| 73 | +COPY ./compose/local/django/celery/beat/start /start-celerybeat |
| 74 | +RUN sed -i 's/\r$//g' /start-celerybeat |
| 75 | +RUN chmod +x /start-celerybeat |
| 76 | + |
| 77 | +COPY ./compose/local/django/celery/flower/start /start-flower |
| 78 | +RUN sed -i 's/\r$//g' /start-flower |
| 79 | +RUN chmod +x /start-flower |
| 80 | + |
| 81 | + |
| 82 | +# copy application code to WORKDIR |
| 83 | +COPY . ${APP_HOME} |
| 84 | + |
| 85 | +ENTRYPOINT ["/entrypoint"] |
0 commit comments