### from https://github.com/OSGeo/gdal/tree/master/docker ###

#### Use latest gdal official image
FROM ghcr.io/osgeo/gdal:ubuntu-small-3.6.3


ARG VERSION_APP
ARG TAG_APP

ENV VERSION=${VERSION_APP}
ENV TAG=${TAG_APP}

# Update base container install
RUN apt-get clean

ENV TZ 'Europe/Prague'
RUN echo $TZ > /etc/timezone
RUN apt-get update
RUN DEBIAN_FRONTEND="noninteractive" apt-get -y install tzdata

# Install dependencies
RUN  apt-get -qq -y install cron && apt-get -y -qq install sudo
RUN apt-get install -y python3-pip libgdal-dev locales gettext poppler-utils

# Ensure locales configured correctly
RUN locale-gen cs_CZ.utf8
ENV LC_ALL='cs_CZ.utf8'

# Set python aliases for python3
RUN echo 'alias python=python3' >> ~/.bashrc
RUN echo 'alias pip=pip3' >> ~/.bashrc

ENV PATH="/scripts:${PATH}"

COPY ./webclient/requirements.txt .

RUN pip3 install -r requirements.txt

RUN mkdir /code
COPY ./webclient /code
WORKDIR /code
COPY ./scripts /scripts

RUN chmod +x /scripts/*

# Uploaded images
RUN mkdir -p /vol/web/media

# Staic files for the app
RUN mkdir -p /vol/web/static
# locales for translations
RUN mkdir -p /vol/web/locale/cs/LC_MESSAGES
RUN mkdir -p /vol/web/locale/en/LC_MESSAGES

RUN adduser user
RUN passwd -d user
RUN usermod -aG sudo user
RUN chown -R user:user /vol
RUN chmod -R 755 /vol/web
RUN chown -R user:user /code
RUN chmod -R 755 /code
RUN crontab -u user /scripts/crontab.txt

RUN echo "DATE:$(date +%Y%m%dT%H%M%S),VERSION:${VERSION}" > /version.txt
RUN sed -i "s/1.0.0/${VERSION}/g" ./templates/base_logged_in.html

USER user

CMD ["entrypoint.sh"]
