Skip to content

Commit

Permalink
Merge pull request #6554 from spwoodcock/build/cleanup-dockerfiles
Browse files Browse the repository at this point in the history
Cleanup dockerfiles, remove duplicates, upgrade PDM
  • Loading branch information
spwoodcock authored Sep 9, 2024
2 parents e26f3c7 + f54d760 commit d639285
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 156 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
- run: sudo apt-get update
- run: sudo apt-get -y install libgeos-dev # Required for shapely
- run: sudo apt-get -y install proj-bin libproj-dev
- run: pip install --upgrade pip pdm==2.7.4
- run: pip install --upgrade pip pdm==2.18.1
- run: pdm export --dev --without-hashes > requirements.txt
- run: pip install -r requirements.txt
- run: mkdir --mode 766 -p /tmp/logs
Expand Down
26 changes: 15 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
ARG DEBIAN_IMG_TAG=slim-bookworm
ARG PYTHON_IMG_TAG=3.10



FROM docker.io/python:${PYTHON_IMG_TAG}-${DEBIAN_IMG_TAG} as base
ARG APP_VERSION=0.1.0
ARG DOCKERFILE_VERSION=0.5.0
ARG ALPINE_IMG_TAG
ARG DEBIAN_IMG_TAG
ARG PYTHON_IMG_TAG
ARG [email protected]
LABEL org.hotosm.tasks.app-version="${APP_VERSION}" \
Expand All @@ -25,7 +28,7 @@ FROM base as extract-deps
RUN pip install --no-cache-dir --upgrade pip
WORKDIR /opt/python
COPY pyproject.toml pdm.lock README.md /opt/python/
RUN pip install --no-cache-dir pdm==2.7.4
RUN pip install --no-cache-dir pdm==2.18.1
RUN pdm export --prod --without-hashes > requirements.txt


Expand All @@ -34,13 +37,13 @@ FROM base as build
RUN pip install --no-cache-dir --upgrade pip
WORKDIR /opt/python
# Setup backend build-time dependencies
RUN apt-get update
RUN apt-get install --no-install-recommends -y build-essential
RUN apt-get install --no-install-recommends -y \
RUN apt-get update && apt-get install --no-install-recommends -y \
build-essential \
libffi-dev \
libgeos-dev \
postgresql-server-dev-15 \
python3-dev \
libffi-dev \
libgeos-dev
&& rm -rf /var/lib/apt/lists/*
# Setup backend Python dependencies
COPY --from=extract-deps \
/opt/python/requirements.txt /opt/python/
Expand All @@ -63,8 +66,8 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
# Setup backend runtime dependencies
RUN apt-get update && \
apt-get install --no-install-recommends -y \
postgresql-client libgeos3.11.1 proj-bin && \
apt-get clean && rm -rf /var/lib/apt/lists/*
libgeos3.11.1 postgresql-client proj-bin && \
rm -rf /var/lib/apt/lists/*
COPY --from=build \
/home/appuser/.local \
/home/appuser/.local
Expand All @@ -79,7 +82,7 @@ COPY manage.py .

FROM runtime as debug
RUN pip install --user --no-warn-script-location \
--no-cache-dir debugpy==1.6.7
--no-cache-dir debugpy==1.8.5
EXPOSE 5678/tcp
CMD ["python", "-m", "debugpy", "--wait-for-client", "--listen", "0.0.0.0:5678", \
"-m", "gunicorn", "-c", "python:backend.gunicorn", "manage:application", \
Expand All @@ -91,12 +94,13 @@ FROM runtime as prod
USER root
RUN apt-get update && \
apt-get install -y curl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Pre-compile packages to .pyc (init speed gains)
RUN python -c "import compileall; compileall.compile_path(maxlevels=10, quiet=1)"
RUN python -m compileall .
EXPOSE 5000/tcp
USER appuser:appuser
# Default gunicorn worker count is 1
# For prod the WEB_CONCURRENCY env var can be used to set this
CMD ["gunicorn", "-c", "python:backend.gunicorn", "manage:application", \
"--workers", "1", "--log-level", "error"]
"--log-level", "error"]
Loading

0 comments on commit d639285

Please sign in to comment.