diff --git a/pctiler/Dockerfile b/pctiler/Dockerfile index 723cd11c..428a7587 100644 --- a/pctiler/Dockerfile +++ b/pctiler/Dockerfile @@ -1,26 +1,37 @@ -FROM mambaorg/micromamba:1.4.0 -COPY --chown=$MAMBA_USER:$MAMBA_USER pctiler/environment.yaml /tmp/env.yaml +FROM ubuntu:latest 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 -EXPOSE 8000 +# 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 +# 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 +ENV PATH="/opt/conda/envs/myenv/bin:$PATH" 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/sh -c "python -m pip install --no-cache-dir -e ./pccommon -e ./pctiler[server]" # GDAL config ENV GDAL_CACHEMAX 200 @@ -47,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 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 diff --git a/pctiler/environment.yaml b/pctiler/environment.yaml index f4b8e1e0..42f85555 100644 --- a/pctiler/environment.yaml +++ b/pctiler/environment.yaml @@ -10,16 +10,12 @@ dependencies: - planetary-computer==0.4.9 - geojson-pydantic==0.4.2 # colormap dependencies - - matplotlib==3.4.3 - - git + - matplotlib-base==3.4.3 - 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 3626d5ed..8ccbc79b 100644 --- a/pctiler/setup.py +++ b/pctiler/setup.py @@ -2,27 +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": [