From bdc599358d2a87fa7e61beacbf0691c4aaedc3be Mon Sep 17 00:00:00 2001 From: Matt McFarland Date: Wed, 12 Apr 2023 09:52:50 -0400 Subject: [PATCH 1/9] Run uvicorn as docker root user The tiler base image was switched to micro-mamba in order to source a particular build of rasterio, however the image user did not have permission to bind to port 80 to run uvicorn. Switching the uvicorn execution to root restores previous behavior. --- pctiler/Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pctiler/Dockerfile b/pctiler/Dockerfile index 86a0cd15..723cd11c 100644 --- a/pctiler/Dockerfile +++ b/pctiler/Dockerfile @@ -46,4 +46,8 @@ ENV MOSAIC_CONCURRENCY 1 ENV APP_HOST=0.0.0.0 ENV APP_PORT=80 + +# Run uvicorn as root. The build context user is $MAMBA_USER which doesn't have +# permission to bind to port 80. +USER root CMD uvicorn pctiler.main:app --host ${APP_HOST} --port ${APP_PORT} --log-level info From 8fa0340acab7321cf3a744ff056e155f25d38c03 Mon Sep 17 00:00:00 2001 From: Matt McFarland Date: Wed, 12 Apr 2023 11:39:42 -0400 Subject: [PATCH 2/9] Build slimmer tiler image --- pctiler/Dockerfile | 39 ++++++++++++++++++++++++--------------- pctiler/setup.py | 32 ++++++++++++++------------------ 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/pctiler/Dockerfile b/pctiler/Dockerfile index 723cd11c..01bbbdf6 100644 --- a/pctiler/Dockerfile +++ b/pctiler/Dockerfile @@ -1,26 +1,35 @@ -FROM mambaorg/micromamba:1.4.0 -COPY --chown=$MAMBA_USER:$MAMBA_USER pctiler/environment.yaml /tmp/env.yaml +# Use a smaller base image, like python:3.9-slim +FROM python:3.9-slim as build -RUN micromamba install -y -n base -f /tmp/env.yaml && \ - micromamba clean --all --yes +# Install Micromamba +RUN apt-get update && apt-get install -y curl bzip2 +RUN curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba -# The devops Personal Access Token for accessing -# Azure Artifacts. Note: This will be visible as -# plain text in the docker build logs. Only use your -# PAT for development containers in your local environment. -# Azure Pipelines will utilize a temporary key for builds -# when building deploy images so that there is not arisk of -# exposure. -ARG DEVOPS_PAT +COPY pctiler/environment.yaml /tmp/env.yaml + +# Create a separate environment for the packages and remove unnecessary files +RUN micromamba create -p /opt/conda/envs/myenv -f /tmp/env.yaml && \ + micromamba clean --all --yes && \ + rm -rf /root/.cache /tmp/env.yaml + +# Multi-stage build to reduce the final image size +FROM python:3.9-slim + +# Copy the environment from the build stage +COPY --from=build /opt/conda/envs/myenv /opt/conda/envs/myenv +ENV PATH="/opt/conda/envs/myenv/bin:$PATH" EXPOSE 8000 WORKDIR /opt/src ARG MAMBA_DOCKERFILE_ACTIVATE=1 -COPY --chown=$MAMBA_USER:$MAMBA_USER pccommon /opt/src/pccommon -COPY --chown=$MAMBA_USER:$MAMBA_USER pctiler /opt/src/pctiler -RUN python3 -m pip install -e ./pccommon -e ./pctiler[server] +COPY pccommon /opt/src/pccommon +COPY pctiler /opt/src/pctiler + +# Install the local modules in the new environment +# RUN /bin/bash -c "source activate myenv && python3 -m pip install -e ./pccommon -e ./pctiler[server]" +RUN /bin/bash -c "python3 -m pip install -e ./pccommon -e ./pctiler[server]" # GDAL config ENV GDAL_CACHEMAX 200 diff --git a/pctiler/setup.py b/pctiler/setup.py index 3626d5ed..fe4558fb 100644 --- a/pctiler/setup.py +++ b/pctiler/setup.py @@ -4,24 +4,20 @@ # Runtime requirements. inst_reqs = [ - "geojson-pydantic==0.4.2", - "jinja2==3.0.3", - "pystac==1.*", - "planetary-computer==0.4.*", - - "rasterio==1.3.*", - "titiler.core==0.10.2", - "titiler.mosaic==0.10.2", - - # titiler-pgstac - "psycopg[binary,pool]", - "titiler.pgstac==0.2.2", - - # colormap dependencies - "matplotlib==3.4.*", - - "importlib_resources>=1.1.0;python_version<'3.9'", - "pccommon", + # "geojson-pydantic==0.4.2", + # "jinja2==3.0.3", + # "pystac==1.*", + # "planetary-computer==0.4.*", + # "rasterio==1.3.*", + # "titiler.core==0.10.2", + # "titiler.mosaic==0.10.2", + # # titiler-pgstac + # "psycopg[binary,pool]", + # "titiler.pgstac==0.2.2", + # # colormap dependencies + # "matplotlib==3.4.*", + # "importlib_resources>=1.1.0;python_version<'3.9'", + # "pccommon", ] extra_reqs = { From ffd71abdde384aedaaaf6a764a541ca514e64283 Mon Sep 17 00:00:00 2001 From: Matt McFarland Date: Wed, 12 Apr 2023 16:11:36 -0400 Subject: [PATCH 3/9] Create slimmer image --- pctiler/Dockerfile | 28 +++++++++++++++------------- pctiler/environment.yaml | 15 ++++++--------- pctiler/setup.py | 19 ++----------------- 3 files changed, 23 insertions(+), 39 deletions(-) diff --git a/pctiler/Dockerfile b/pctiler/Dockerfile index 01bbbdf6..1bfb1ff1 100644 --- a/pctiler/Dockerfile +++ b/pctiler/Dockerfile @@ -1,5 +1,4 @@ -# Use a smaller base image, like python:3.9-slim -FROM python:3.9-slim as build +FROM ubuntu:latest as build # Install Micromamba RUN apt-get update && apt-get install -y curl bzip2 @@ -12,24 +11,27 @@ RUN micromamba create -p /opt/conda/envs/myenv -f /tmp/env.yaml && \ micromamba clean --all --yes && \ rm -rf /root/.cache /tmp/env.yaml -# Multi-stage build to reduce the final image size -FROM python:3.9-slim +# Start from a new stage to avoid copying the build environment, and +# copy the environment from the build stage +FROM ubuntu:latest -# Copy the environment from the build stage COPY --from=build /opt/conda/envs/myenv /opt/conda/envs/myenv ENV PATH="/opt/conda/envs/myenv/bin:$PATH" -EXPOSE 8000 - WORKDIR /opt/src -ARG MAMBA_DOCKERFILE_ACTIVATE=1 COPY pccommon /opt/src/pccommon COPY pctiler /opt/src/pctiler # Install the local modules in the new environment -# RUN /bin/bash -c "source activate myenv && python3 -m pip install -e ./pccommon -e ./pctiler[server]" -RUN /bin/bash -c "python3 -m pip install -e ./pccommon -e ./pctiler[server]" +RUN /bin/sh -c "python -m pip install --no-cache-dir -e ./pccommon -e ./pctiler[server]" + +# Remove unnecessary files +RUN find /opt/conda/envs/myenv -type f -name "*.pyc" -exec rm -f {} \; +RUN rm -rf /opt/conda/envs/myenv/share/doc +RUN rm -rf /opt/conda/envs/myenv/share/locale +RUN rm -rf /opt/conda/envs/myenv/man +RUN rm -rf /opt/conda/envs/myenv/include # GDAL config ENV GDAL_CACHEMAX 200 @@ -56,7 +58,7 @@ ENV MOSAIC_CONCURRENCY 1 ENV APP_HOST=0.0.0.0 ENV APP_PORT=80 -# Run uvicorn as root. The build context user is $MAMBA_USER which doesn't have -# permission to bind to port 80. -USER root +# # Run uvicorn as root. The build context user is $MAMBA_USER which doesn't have +# # permission to bind to port 80. +# USER root CMD uvicorn pctiler.main:app --host ${APP_HOST} --port ${APP_PORT} --log-level info diff --git a/pctiler/environment.yaml b/pctiler/environment.yaml index f4b8e1e0..4b085de6 100644 --- a/pctiler/environment.yaml +++ b/pctiler/environment.yaml @@ -10,16 +10,13 @@ dependencies: - planetary-computer==0.4.9 - geojson-pydantic==0.4.2 # colormap dependencies - - matplotlib==3.4.3 + - matplotlib-base==3.4.3 - git - pip - pip: - - "titiler.core==0.10.2" - - "titiler.mosaic==0.10.2" + - "titiler.core==0.10.2" + - "titiler.mosaic==0.10.2" - - # titiler-pgstac - - "psycopg[binary,pool]" - - "titiler.pgstac==0.2.2" - - # - "importlib_resources>=1.1.0;python_version<'3.9'" - # - "pccommon" \ No newline at end of file + - # titiler-pgstac + - "psycopg[binary,pool]" + - "titiler.pgstac==0.2.2" diff --git a/pctiler/setup.py b/pctiler/setup.py index fe4558fb..8ccbc79b 100644 --- a/pctiler/setup.py +++ b/pctiler/setup.py @@ -2,23 +2,8 @@ from setuptools import find_packages, setup -# Runtime requirements. -inst_reqs = [ - # "geojson-pydantic==0.4.2", - # "jinja2==3.0.3", - # "pystac==1.*", - # "planetary-computer==0.4.*", - # "rasterio==1.3.*", - # "titiler.core==0.10.2", - # "titiler.mosaic==0.10.2", - # # titiler-pgstac - # "psycopg[binary,pool]", - # "titiler.pgstac==0.2.2", - # # colormap dependencies - # "matplotlib==3.4.*", - # "importlib_resources>=1.1.0;python_version<'3.9'", - # "pccommon", -] +# Runtime requirements, see environment.yaml +inst_reqs = [] extra_reqs = { "server": [ From 35da8769a14ab4dc87f6a04d0eb83e3f09481808 Mon Sep 17 00:00:00 2001 From: Matt McFarland Date: Thu, 13 Apr 2023 11:56:21 -0400 Subject: [PATCH 4/9] Use alpine conda base Image size is 2.7GB --- pctiler/Dockerfile | 39 ++++++++++++---------------- pctiler/Dockerfile.conda.base | 49 +++++++++++++++++++++++++++++++++++ pctiler/environment.yaml | 4 +-- 3 files changed, 66 insertions(+), 26 deletions(-) create mode 100644 pctiler/Dockerfile.conda.base diff --git a/pctiler/Dockerfile b/pctiler/Dockerfile index 1bfb1ff1..5ef9449b 100644 --- a/pctiler/Dockerfile +++ b/pctiler/Dockerfile @@ -1,22 +1,14 @@ -FROM ubuntu:latest as build +FROM pctiler-base:latest -# Install Micromamba -RUN apt-get update && apt-get install -y curl bzip2 -RUN curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba +COPY pctiler/environment.yaml /tmp/environment.yaml +RUN /opt/conda/bin/conda env update -f /tmp/environment.yaml +RUN source ~/.profile +# RUN /opt/conda/bin/conda activate base -COPY pctiler/environment.yaml /tmp/env.yaml - -# Create a separate environment for the packages and remove unnecessary files -RUN micromamba create -p /opt/conda/envs/myenv -f /tmp/env.yaml && \ - micromamba clean --all --yes && \ - rm -rf /root/.cache /tmp/env.yaml - -# Start from a new stage to avoid copying the build environment, and -# copy the environment from the build stage -FROM ubuntu:latest - -COPY --from=build /opt/conda/envs/myenv /opt/conda/envs/myenv -ENV PATH="/opt/conda/envs/myenv/bin:$PATH" +RUN /opt/conda/bin/conda clean -afy \ + && find /opt/conda/ -follow -type f -name '*.a' -delete \ + && find /opt/conda/ -follow -type f -name '*.pyc' -delete \ + && find /opt/conda/ -follow -type f -name '*.js.map' -delete WORKDIR /opt/src @@ -24,14 +16,15 @@ COPY pccommon /opt/src/pccommon COPY pctiler /opt/src/pctiler # Install the local modules in the new environment -RUN /bin/sh -c "python -m pip install --no-cache-dir -e ./pccommon -e ./pctiler[server]" +# RUN /bin/sh -c "/opt/conda/python -m pip install --no-cache-dir -e ./pccommon -e ./pctiler[server]" +RUN /opt/conda/bin/conda develop ./pccommon ./pctiler[server] # Remove unnecessary files -RUN find /opt/conda/envs/myenv -type f -name "*.pyc" -exec rm -f {} \; -RUN rm -rf /opt/conda/envs/myenv/share/doc -RUN rm -rf /opt/conda/envs/myenv/share/locale -RUN rm -rf /opt/conda/envs/myenv/man -RUN rm -rf /opt/conda/envs/myenv/include +# RUN find /opt/conda/envs/myenv -type f -name "*.pyc" -exec rm -f {} \; +# RUN rm -rf /opt/conda/envs/myenv/share/doc +# RUN rm -rf /opt/conda/envs/myenv/share/locale +# RUN rm -rf /opt/conda/envs/myenv/man +# RUN rm -rf /opt/conda/envs/myenv/include # GDAL config ENV GDAL_CACHEMAX 200 diff --git a/pctiler/Dockerfile.conda.base b/pctiler/Dockerfile.conda.base new file mode 100644 index 00000000..33688814 --- /dev/null +++ b/pctiler/Dockerfile.conda.base @@ -0,0 +1,49 @@ +FROM frolvlad/alpine-glibc:alpine-3.9_glibc-2.29 +LABEL MAINTAINER="Matt McFarland" + +ENV CONDA_SCRIPT=Miniconda3-py39_22.11.1-1-Linux-x86_64.sh +ENV MINICONDA_URL https://repo.anaconda.com/miniconda/${CONDA_SCRIPT} +ENV CONDA_MD5 fcd62ba94376cbbdea83a4e615d201dd + +# Tell Python not to recreate the bytecode files. Since this is a docker image, +# these will be recreated every time, writing them just uses unnecessary disk +# space. +ENV PYTHONDONTWRITEBYTECODE=true + +# We do the following all in one block: +# - Create user and group anaconda +# - Install miniconda install dependencies +# - Download miniconda and check the md5sum +# - Install miniconda +# - Downgrade and pin conda to 4.6.8 (can remove once 4.7 is released) +# - Install tini +# - Remove all conda managed static libraries +# - Remove all conda managed *.pyc files +# - Cleanup conda files +# - Uninstall miniconda install dependencies +RUN apk add --no-cache wget bzip2 \ + && addgroup -S anaconda \ + && adduser -D -u 10151 anaconda -G anaconda \ + && wget --quiet ${MINICONDA_URL} \ + && echo "${CONDA_MD5} ${CONDA_SCRIPT}" > miniconda.md5 \ + && if [ $(md5sum -c miniconda.md5 | awk '{print $2}') != "OK" ] ; then exit 1; fi \ + && mv ${CONDA_SCRIPT} miniconda.sh \ + && sh ./miniconda.sh -b -p /opt/conda \ + && rm miniconda.sh miniconda.md5 \ + && ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh \ + && echo ". /opt/conda/etc/profile.d/conda.sh" >> /home/anaconda/.profile \ + && echo "conda activate base" >> /home/anaconda/.profile \ + # && /opt/conda/bin/conda install conda==4.6.8 \ + # && echo "conda ==4.6.8" >> /opt/conda/conda-meta/pinned \ + && /opt/conda/bin/conda install --freeze-installed tini -y \ + && find /opt/conda/ -follow -type f -name '*.a' -delete \ + && find /opt/conda/ -follow -type f -name '*.pyc' -delete \ + && /opt/conda/bin/conda clean -afy \ + && chown -R anaconda:anaconda /opt/conda \ + && apk del wget bzip2 + +USER anaconda:anaconda +WORKDIR /home/anaconda/ + +ENTRYPOINT ["/opt/conda/bin/tini", "-g" ] +CMD ["sh", "--login", "-i"] diff --git a/pctiler/environment.yaml b/pctiler/environment.yaml index 4b085de6..d639db63 100644 --- a/pctiler/environment.yaml +++ b/pctiler/environment.yaml @@ -9,14 +9,12 @@ dependencies: - pyproj==3.4.1 - planetary-computer==0.4.9 - geojson-pydantic==0.4.2 - # colormap dependencies - matplotlib-base==3.4.3 + - conda-build - git - pip - pip: - "titiler.core==0.10.2" - "titiler.mosaic==0.10.2" - - - # titiler-pgstac - "psycopg[binary,pool]" - "titiler.pgstac==0.2.2" From 1080fd07f2a540a541a35c57c66bc53c6fdd25d7 Mon Sep 17 00:00:00 2001 From: Matt McFarland Date: Thu, 13 Apr 2023 11:57:05 -0400 Subject: [PATCH 5/9] Revert "Use alpine conda base" This reverts commit 35da8769a14ab4dc87f6a04d0eb83e3f09481808. --- pctiler/Dockerfile | 39 ++++++++++++++++------------ pctiler/Dockerfile.conda.base | 49 ----------------------------------- pctiler/environment.yaml | 4 ++- 3 files changed, 26 insertions(+), 66 deletions(-) delete mode 100644 pctiler/Dockerfile.conda.base diff --git a/pctiler/Dockerfile b/pctiler/Dockerfile index 5ef9449b..1bfb1ff1 100644 --- a/pctiler/Dockerfile +++ b/pctiler/Dockerfile @@ -1,14 +1,22 @@ -FROM pctiler-base:latest +FROM ubuntu:latest as build -COPY pctiler/environment.yaml /tmp/environment.yaml -RUN /opt/conda/bin/conda env update -f /tmp/environment.yaml -RUN source ~/.profile -# RUN /opt/conda/bin/conda activate base +# Install Micromamba +RUN apt-get update && apt-get install -y curl bzip2 +RUN curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba -RUN /opt/conda/bin/conda clean -afy \ - && find /opt/conda/ -follow -type f -name '*.a' -delete \ - && find /opt/conda/ -follow -type f -name '*.pyc' -delete \ - && find /opt/conda/ -follow -type f -name '*.js.map' -delete +COPY pctiler/environment.yaml /tmp/env.yaml + +# Create a separate environment for the packages and remove unnecessary files +RUN micromamba create -p /opt/conda/envs/myenv -f /tmp/env.yaml && \ + micromamba clean --all --yes && \ + rm -rf /root/.cache /tmp/env.yaml + +# Start from a new stage to avoid copying the build environment, and +# copy the environment from the build stage +FROM ubuntu:latest + +COPY --from=build /opt/conda/envs/myenv /opt/conda/envs/myenv +ENV PATH="/opt/conda/envs/myenv/bin:$PATH" WORKDIR /opt/src @@ -16,15 +24,14 @@ COPY pccommon /opt/src/pccommon COPY pctiler /opt/src/pctiler # Install the local modules in the new environment -# RUN /bin/sh -c "/opt/conda/python -m pip install --no-cache-dir -e ./pccommon -e ./pctiler[server]" -RUN /opt/conda/bin/conda develop ./pccommon ./pctiler[server] +RUN /bin/sh -c "python -m pip install --no-cache-dir -e ./pccommon -e ./pctiler[server]" # Remove unnecessary files -# RUN find /opt/conda/envs/myenv -type f -name "*.pyc" -exec rm -f {} \; -# RUN rm -rf /opt/conda/envs/myenv/share/doc -# RUN rm -rf /opt/conda/envs/myenv/share/locale -# RUN rm -rf /opt/conda/envs/myenv/man -# RUN rm -rf /opt/conda/envs/myenv/include +RUN find /opt/conda/envs/myenv -type f -name "*.pyc" -exec rm -f {} \; +RUN rm -rf /opt/conda/envs/myenv/share/doc +RUN rm -rf /opt/conda/envs/myenv/share/locale +RUN rm -rf /opt/conda/envs/myenv/man +RUN rm -rf /opt/conda/envs/myenv/include # GDAL config ENV GDAL_CACHEMAX 200 diff --git a/pctiler/Dockerfile.conda.base b/pctiler/Dockerfile.conda.base deleted file mode 100644 index 33688814..00000000 --- a/pctiler/Dockerfile.conda.base +++ /dev/null @@ -1,49 +0,0 @@ -FROM frolvlad/alpine-glibc:alpine-3.9_glibc-2.29 -LABEL MAINTAINER="Matt McFarland" - -ENV CONDA_SCRIPT=Miniconda3-py39_22.11.1-1-Linux-x86_64.sh -ENV MINICONDA_URL https://repo.anaconda.com/miniconda/${CONDA_SCRIPT} -ENV CONDA_MD5 fcd62ba94376cbbdea83a4e615d201dd - -# Tell Python not to recreate the bytecode files. Since this is a docker image, -# these will be recreated every time, writing them just uses unnecessary disk -# space. -ENV PYTHONDONTWRITEBYTECODE=true - -# We do the following all in one block: -# - Create user and group anaconda -# - Install miniconda install dependencies -# - Download miniconda and check the md5sum -# - Install miniconda -# - Downgrade and pin conda to 4.6.8 (can remove once 4.7 is released) -# - Install tini -# - Remove all conda managed static libraries -# - Remove all conda managed *.pyc files -# - Cleanup conda files -# - Uninstall miniconda install dependencies -RUN apk add --no-cache wget bzip2 \ - && addgroup -S anaconda \ - && adduser -D -u 10151 anaconda -G anaconda \ - && wget --quiet ${MINICONDA_URL} \ - && echo "${CONDA_MD5} ${CONDA_SCRIPT}" > miniconda.md5 \ - && if [ $(md5sum -c miniconda.md5 | awk '{print $2}') != "OK" ] ; then exit 1; fi \ - && mv ${CONDA_SCRIPT} miniconda.sh \ - && sh ./miniconda.sh -b -p /opt/conda \ - && rm miniconda.sh miniconda.md5 \ - && ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh \ - && echo ". /opt/conda/etc/profile.d/conda.sh" >> /home/anaconda/.profile \ - && echo "conda activate base" >> /home/anaconda/.profile \ - # && /opt/conda/bin/conda install conda==4.6.8 \ - # && echo "conda ==4.6.8" >> /opt/conda/conda-meta/pinned \ - && /opt/conda/bin/conda install --freeze-installed tini -y \ - && find /opt/conda/ -follow -type f -name '*.a' -delete \ - && find /opt/conda/ -follow -type f -name '*.pyc' -delete \ - && /opt/conda/bin/conda clean -afy \ - && chown -R anaconda:anaconda /opt/conda \ - && apk del wget bzip2 - -USER anaconda:anaconda -WORKDIR /home/anaconda/ - -ENTRYPOINT ["/opt/conda/bin/tini", "-g" ] -CMD ["sh", "--login", "-i"] diff --git a/pctiler/environment.yaml b/pctiler/environment.yaml index d639db63..4b085de6 100644 --- a/pctiler/environment.yaml +++ b/pctiler/environment.yaml @@ -9,12 +9,14 @@ dependencies: - pyproj==3.4.1 - planetary-computer==0.4.9 - geojson-pydantic==0.4.2 + # colormap dependencies - matplotlib-base==3.4.3 - - conda-build - git - pip - pip: - "titiler.core==0.10.2" - "titiler.mosaic==0.10.2" + + - # titiler-pgstac - "psycopg[binary,pool]" - "titiler.pgstac==0.2.2" From 1eaa24016b460c51fae2cccb7fe0d7609680304e Mon Sep 17 00:00:00 2001 From: Matt McFarland Date: Thu, 13 Apr 2023 12:57:45 -0400 Subject: [PATCH 6/9] Remove commented out code --- pctiler/Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/pctiler/Dockerfile b/pctiler/Dockerfile index 1bfb1ff1..25928f27 100644 --- a/pctiler/Dockerfile +++ b/pctiler/Dockerfile @@ -58,7 +58,4 @@ ENV MOSAIC_CONCURRENCY 1 ENV APP_HOST=0.0.0.0 ENV APP_PORT=80 -# # Run uvicorn as root. The build context user is $MAMBA_USER which doesn't have -# # permission to bind to port 80. -# USER root CMD uvicorn pctiler.main:app --host ${APP_HOST} --port ${APP_PORT} --log-level info From 08c59514fd58b42fe66bcf653fb64f25884dea21 Mon Sep 17 00:00:00 2001 From: Matt McFarland Date: Thu, 13 Apr 2023 13:34:07 -0400 Subject: [PATCH 7/9] Remove mamba related code Base image doesn't rely on activated mamba environment --- pctiler/Dockerfile.dev | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pctiler/Dockerfile.dev b/pctiler/Dockerfile.dev index 9c268f6f..b427cb79 100644 --- a/pctiler/Dockerfile.dev +++ b/pctiler/Dockerfile.dev @@ -1,8 +1,6 @@ FROM pc-apis-tiler -ARG MAMBA_DOCKERFILE_ACTIVATE=1 - -COPY --chown=$MAMBA_USER:$MAMBA_USER requirements-dev.txt requirements-dev.txt +COPY requirements-dev.txt requirements-dev.txt RUN python3 -m pip install -r requirements-dev.txt RUN python3 -m pip install -e ./pccommon -e ./pctiler From 03971df6f718d918ab4de6cfdd900ce33ca836ba Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Tue, 18 Apr 2023 06:43:31 -0500 Subject: [PATCH 8/9] Removed git from conda environment 1.08GB --- pctiler/environment.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/pctiler/environment.yaml b/pctiler/environment.yaml index 4b085de6..42f85555 100644 --- a/pctiler/environment.yaml +++ b/pctiler/environment.yaml @@ -11,7 +11,6 @@ dependencies: - geojson-pydantic==0.4.2 # colormap dependencies - matplotlib-base==3.4.3 - - git - pip - pip: - "titiler.core==0.10.2" From dc49d41ea8b764b62bacca4f63222e8f3adf59a1 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Tue, 18 Apr 2023 08:27:20 -0500 Subject: [PATCH 9/9] Moved file cleanup to before COPY --from 843 MB This ensures these unnecessary files are never in a layer. --- pctiler/Dockerfile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pctiler/Dockerfile b/pctiler/Dockerfile index 25928f27..428a7587 100644 --- a/pctiler/Dockerfile +++ b/pctiler/Dockerfile @@ -13,6 +13,13 @@ RUN micromamba create -p /opt/conda/envs/myenv -f /tmp/env.yaml && \ # Start from a new stage to avoid copying the build environment, and # copy the environment from the build stage +# Remove unnecessary files +RUN find /opt/conda/envs/myenv -type f -name "*.pyc" -exec rm -f {} \; +RUN rm -rf /opt/conda/envs/myenv/share/doc +RUN rm -rf /opt/conda/envs/myenv/share/locale +RUN rm -rf /opt/conda/envs/myenv/man +RUN rm -rf /opt/conda/envs/myenv/include + FROM ubuntu:latest COPY --from=build /opt/conda/envs/myenv /opt/conda/envs/myenv @@ -26,13 +33,6 @@ COPY pctiler /opt/src/pctiler # Install the local modules in the new environment RUN /bin/sh -c "python -m pip install --no-cache-dir -e ./pccommon -e ./pctiler[server]" -# Remove unnecessary files -RUN find /opt/conda/envs/myenv -type f -name "*.pyc" -exec rm -f {} \; -RUN rm -rf /opt/conda/envs/myenv/share/doc -RUN rm -rf /opt/conda/envs/myenv/share/locale -RUN rm -rf /opt/conda/envs/myenv/man -RUN rm -rf /opt/conda/envs/myenv/include - # GDAL config ENV GDAL_CACHEMAX 200 ENV GDAL_INGESTED_BYTES_AT_OPEN 32768