FROM perl:5.40.1 As base

LABEL author="sgoti" \
      email="lyunpaw@gmail.com" \
      project="Hacker Public Radio" \
      forge="https://repo.anhonesthost.net/HPR"

ARG unprivilegedUser="janitor"

RUN apt update && apt upgrade --yes;

RUN apt install --no-install-recommends sqlite3 git --yes \
    && rm --recursive --force /var/lib/apt/lists/*;

RUN mkdir --verbose --parent /opt/hpr /tmp/hpr;

RUN groupadd --system ${unprivilegedUser} \
    && useradd --system --no-log-init --gid ${unprivilegedUser} ${unprivilegedUser};

RUN chown --recursive ${unprivilegedUser}:${unprivilegedUser} /opt/hpr \
    && chown --recursive ${unprivilegedUser}:${unprivilegedUser} /tmp/hpr;

#Bill of particulars.

##Meta::CPAN (Comprehensive Perl Archive Network)
RUN cpanm Config::General \
    DBD::SQLite \
    DBI \
    Data::Dumper \
    Date::Calc \
    Date::Parse \
    DateTime \
    DateTime::Duration \
    DateTime::Format::Duration \
    DateTime::TimeZone \
    HTML::Entities \
    JSON \
    Template \
    Template::Filters;

##Included perl core modules (standard library).
##Carp
##Cwd
##Getopt::Long
##Pod::Usage
##File::Copy

USER ${unprivilegedUser}

WORKDIR /opt/hpr

RUN git clone https://repo.anhonesthost.net/HPR/hpr-tools.git \
    && git clone https://repo.anhonesthost.net/HPR/hpr_hub.git \
    && git clone https://repo.anhonesthost.net/HPR/hpr_generator.git \
    && git clone https://repo.anhonesthost.net/HPR/hpr_documentation.git;

WORKDIR /opt/hpr/hpr-tools/Community_News/
RUN ln --symbolic /opt/hpr/hpr_generator/utils/mysql2sqlite /opt/hpr/hpr-tools/Community_News/mysql2sqlite;
RUN ./collect_HPR_database;

CMD bash;

