FROM python:3.7.17-bullseye

# Set C.UTF-8 locale as default (Needed by the Click library)
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8

RUN apt-get update
RUN apt-get install -y \
    postgresql \
    postgresql-contrib \
    ca-certificates-java \
    openjdk-17-jdk-headless \
    wget

WORKDIR /root

# install maven
# Download maven 3.6.3
RUN wget https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /tmp

# Untar downloaded file to /opt
RUN tar xf /tmp/apache-maven-*.tar.gz -C /opt

# Install the alternative version for the mvn in your system
RUN update-alternatives --install /usr/bin/mvn mvn /opt/apache-maven-3.6.3/bin/mvn 363

# Check if your configuration is ok. You may use your current or the 3.6.3 whenever you wish, running the command below.
RUN update-alternatives --config mvn


#trying to get ogr to work
RUN apt-get install -y libgdal-dev g++ --no-install-recommends && \
    apt-get clean -y
RUN apt-get update &&\
    apt-get install -y binutils libproj-dev gdal-bin

# Update C env vars so compiler can find gdal
ENV CPLUS_INCLUDE_PATH=/usr/include/gdal
ENV C_INCLUDE_PATH=/usr/include/gdal


# Create directories for config, data and logs
RUN mkdir --parents .local/share/mm_stats

# Copy mm_stats workers repo from local repo
COPY mm_stats/ mm_stats/
COPY tests/ tests/
COPY java/ java/
COPY requirements.txt .
COPY setup.py .
COPY gdrive_service_account_key_file.json .

# Update setuptools and install mapswipe-workers with dependencies (requirements.txt)
RUN pip3 install --upgrade setuptools
RUN pip3 install .

# Don't use a CMD here, this will be defined in docker-compose.yaml
