|
| 1 | +# define an alias for the specific python version used in this file. |
| 2 | +FROM docker.io/python:3.11-slim-bookworm AS python |
| 3 | + |
| 4 | +# Python build stage |
| 5 | +FROM python AS python-build-stage |
| 6 | + |
| 7 | +# Install apt packages |
| 8 | +RUN apt-get update && apt-get install --no-install-recommends -y \ |
| 9 | + # dependencies for building Python packages |
| 10 | + build-essential \ |
| 11 | + # psycopg dependencies |
| 12 | + libpq-dev |
| 13 | + |
| 14 | +# Requirements are installed here to ensure they will be cached. |
| 15 | +COPY ./requirements . |
| 16 | + |
| 17 | +# Create Python Dependency and Sub-Dependency Wheels. |
| 18 | +RUN pip wheel --wheel-dir /usr/src/app/wheels \ |
| 19 | + -r development.txt |
| 20 | + |
| 21 | +# Python 'run' stage |
| 22 | +FROM python AS python-run-stage |
| 23 | + |
| 24 | +ARG APP_HOME=/app |
| 25 | + |
| 26 | +ENV PYTHONUNBUFFERED=1 |
| 27 | +ENV PYTHONDONTWRITEBYTECODE=1 |
| 28 | + |
| 29 | +WORKDIR ${APP_HOME} |
| 30 | + |
| 31 | +ARG NODE_MAJOR=20 |
| 32 | + |
| 33 | +RUN apt-get update \ |
| 34 | + && apt-get install -y ca-certificates curl gnupg \ |
| 35 | + && mkdir -p /etc/apt/keyrings \ |
| 36 | + && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \ |
| 37 | + && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \ |
| 38 | + && apt-get update \ |
| 39 | + && apt-get install nodejs -y \ |
| 40 | + && rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man \ |
| 41 | + && apt-get clean |
| 42 | + |
| 43 | +# devcontainer dependencies and utils |
| 44 | +RUN apt-get update && apt-get install --no-install-recommends -y \ |
| 45 | + sudo git bash-completion nano ssh |
| 46 | + |
| 47 | +# Create devcontainer user and add it to sudoers |
| 48 | +RUN groupadd --gid 1000 dev-user \ |
| 49 | + && useradd --uid 1000 --gid dev-user --shell /bin/bash --create-home dev-user \ |
| 50 | + && echo dev-user ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/dev-user \ |
| 51 | + && chmod 0440 /etc/sudoers.d/dev-user |
| 52 | + |
| 53 | + |
| 54 | +# Install required system dependencies |
| 55 | +RUN apt-get update && apt-get install --no-install-recommends -y \ |
| 56 | + # psycopg dependencies |
| 57 | + libpq-dev \ |
| 58 | + wait-for-it \ |
| 59 | + # Translations dependencies |
| 60 | + gettext \ |
| 61 | + # cleaning up unused files |
| 62 | + && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ |
| 63 | + && rm -rf /var/lib/apt/lists/* |
| 64 | + |
| 65 | +# All absolute dir copies ignore workdir instruction. All relative dir copies are wrt to the workdir instruction |
| 66 | +# copy python dependency wheels from python-build-stage |
| 67 | +COPY --from=python-build-stage /usr/src/app/wheels /wheels/ |
| 68 | + |
| 69 | +# use wheels to install python dependencies |
| 70 | +RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \ |
| 71 | + && rm -rf /wheels/ |
| 72 | + |
| 73 | +COPY ./compose/local/django/start /start |
| 74 | +RUN sed -i 's/\r$//g' /start |
| 75 | +RUN chmod +x /start |
| 76 | + |
| 77 | +CMD ["/start"] |
0 commit comments