FROM redmine:5.1.8

RUN apt update -y && apt install -y unzip zlib1g-dev

RUN cd /usr/src/redmine/plugins \
&& git clone --branch v2.2.8 https://github.com/kontron/redmine_oauth.git \
&& git clone https://github.com/taqueci/redmine_wysiwyg_editor \
&& git clone https://github.com/alphanodes/redmine_messenger \
&& git clone https://github.com/haru/redmine_theme_changer \
&& git clone https://github.com/HugoHasenbein/redmine_more_previews \
&& wget --no-check-certificate https://nexus.nstest.local/repository/redmine-plugins/custom/redmine_checklists-4_0_0-light.zip \
&& unzip redmine_checklists-4_0_0-light.zip && rm redmine_checklists-4_0_0-light.zip \
&& wget --no-check-certificate https://nexus.nstest.local/repository/redmine-plugins/custom/redmine_kanban-v2.6.0-free.zip \
&& unzip redmine_kanban-v2.6.0-free.zip && rm redmine_kanban-v2.6.0-free.zip \
&& wget --no-check-certificate https://nexus.nstest.local/repository/redmine-plugins/custom/redmine_resources-2_0_6-light.zip \
&& unzip redmine_resources-2_0_6-light.zip && rm redmine_resources-2_0_6-light.zip \
&& chown -R www-data:www-data ./

RUN cd /usr/src/redmine/plugins/redmine_kanban/db/migrate/ && \
    if [ -f "20211215012800_create_checklists.rb" ]; then \
        mv "20211215012800_create_checklists.rb" "20211215012800_create_kanban_checklists.rb" && \
        sed -i 's/class CreateChecklists/class CreateKanbanChecklists/g' "20211215012800_create_kanban_checklists.rb"; \
    fi

# Fix permissions for bundle install of bigdecimal for redmine_oauth
RUN chown -R redmine: /usr/local/bundle/ && chmod -R o-w /usr/local/bundle/

# Install build-essential to build dependencies of redmine_oauth
RUN export DEBIAN_FRONTEND=noninteractive \
 && apt-get update \
 && apt-get install --yes --no-install-recommends build-essential \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*
