Skip to content
Snippets Groups Projects
Commit ff9ae4a3 authored by Pierre-Gilles Levallois's avatar Pierre-Gilles Levallois
Browse files

Refactoring python imaage

parent 6886c716
No related branches found
No related tags found
1 merge request!6Fully functional version that calculate layer with all stages
# Use an official Python runtime as a parent image ##################################################################################
FROM python:3.9-slim-buster # Taken from https://github.com/Toblerity/Fiona/issues/1063
##################################################################################
FROM debian:10
#buster-slim
# Set the working directory to /app # Set the working directory to /app
WORKDIR /app WORKDIR /app
# Add a non-root user to run the application
RUN groupadd -r calquluser && useradd --no-log-init -r -g calquluser calquluser
# Copy the current directory contents into the container at /app # Copy the current directory contents into the container at /app
COPY . /app COPY ./ /app/
# Install any needed packages specified in requirements.txt # Basic libs and install python3.7
RUN apt-get update && \ RUN apt-get update && apt-get upgrade -y \
apt-get install -y --no-install-recommends \ && apt-get install -y procps wget python3.7 python3-pip gdal-bin libgdal-dev apt-utils git \
libgdal-dev \ && apt-get clean \
pkg-config \ apt-get -y install proj proj-dev && \
python3-gi \ # https://stackoverflow.com/questions/70508775/error-could-not-build-wheels-for-pycairo-which-is-required-to-install-pyprojec
python3-gi-cairo && \ apt-get install -y libcairo2 libcairo2-dev && \
apt-get clean && \ ################################# Debug and diagnose tools #################################
rm -rf /var/lib/apt/lists/* && \ apt-get install -qy apt-utils vim iputils-ping net-tools telnet curl && \
pip install --no-cache-dir --upgrade pip && \ apt-get install -qy postgresql-client && \
pip install --no-cache-dir --no-deps --disable-pip-version-check -r requirements.txt && \ ############################################################################################
rm -rf /root/.cache rm -rf /var/lib/apt/lists/*
# Change ownership of the application to the non-root user
RUN chown -R calquluser:calquluser /app # Pip & Python
RUN python3 -m pip install --no-cache-dir --upgrade pip \
# Switch to the non-root user && pip install --no-cache-dir --global-option=build_ext --global-option="-I/usr/include/gdal" GDAL==`gdal-config --version` \
&& pip install --no-cache-dir --ignore-installed PyYAML \
# https://stackoverflow.com/questions/70508775/error-could-not-build-wheels-for-pycairo-which-is-required-to-install-pyprojec
&& pip install --no-cache-dir manimlib \
&& pip install --no-cache-dir manimce \
&& pip install rtree pygeos \
&& pip install --upgrade shapely \
&& pip install --no-cache-dir --upgrade -r ./scripts/requirements.txt
# Add a non root user (OpenShift Requirements)
RUN addgroup calquluser && \
useradd calquluser -g calquluser --home /app && \
mkdir -p /app && \
mkdir -p /app/logs && \
mkdir -p /app/tmp && \
chown -R calquluser:calquluser /app && \
chmod 777 /app/logs /app/tmp /app
# WORKDIR /app
USER calquluser USER calquluser
# Define the arguments for the Dockerfile # Arguments
ARG NAMESPACE_ENV ARG NAMESPACE_ENV
ARG DB_HOST ARG DB_HOST_ENV
ARG DB_PORT ARG DB_PORT_ENV
ARG DB_NAME ARG DB_NAME_ENV
ARG DB_USER ARG DB_USER_ENV
# Getting some Args and Setting some ENV variables
ENV CPLUS_INCLUDE_PATH="/usr/include/gdal"
ENV C_INCLUDE_PATH="/usr/include/gdal"
# ENV PROJ_LIB="/usr/local/lib/python3.7/dist-packages/pyproj/proj_dir/share/proj"
ENV PROJ_LIB="/usr/local/lib/python3.7/dist-packages/fiona/proj_data/"
ENV GDAL_DATA="/usr/local/lib/python3.7/dist-packages/fiona/gdal_data/"
# Debug verbosity
ENV PROJ_DEBUG=3
# Set the environment variables for the arguments ENV NS_ENV=$NAMESPACE_ENV
ENV NS_ENV=$NS_ENV
ENV DB_HOST="$DB_HOST_ENV-$NAMESPACE_ENV" ENV DB_HOST="$DB_HOST_ENV-$NAMESPACE_ENV"
ENV DB_PORT=$DB_PORT ENV DB_PORT=$DB_PORT_ENV
ENV DB_NAME=$DB_NAME ENV DB_NAME=$DB_NAME_ENV
ENV DB_USER=$DB_USER ENV DB_USER=$DB_USER_ENV
# # Add app
# COPY --chown=calquluser:calquluser ./scripts/*.py ./
# COPY --chown=calquluser:calquluser ./scripts/*.sh ./
# COPY --chown=calquluser:calquluser ./sql ./
# COPY --chown=calquluser:calquluser .env ./
# Set the environment variable for PROJ_LIB # RUN chmod 755 ./*.sh
ENV PROJ_LIB=/usr/share/proj/
# Run the command to start the Python script # Launch calculation
CMD ["/bin/bash", "-c", "/app/launch.sh $NS_ENV $DB_HOST $DB_PORT $DB_NAME $DB_USER"] # Documentation : https://stackoverflow.com/questions/40454470/how-can-i-use-a-variable-inside-a-dockerfile-cmd
\ No newline at end of file CMD [ "/bin/sh", "-c", "/app/scripts/launch.sh $NS_ENV $DB_HOST $DB_PORT $DB_NAME $DB_USER" ]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment