# retrieve the base image (default to latest).
ARG BASE_IMAGE="nextcloud:29-fpm"

FROM ${BASE_IMAGE}
LABEL org.opencontainers.image.authors="Belman Kraul <bkraul@gmail.com>"

RUN set -ex \
  usermod -u 82 www-data; \
  groupmod -g 82 www-data; \
  usermod -g 82 www-data; \
  # for some reason this needs to be repeated.
  usermod -u 82 www-data; \
  chown -R www-data:root /var/www; \
  chmod -R g=u /var/www

RUN set -ex; \
  apt-get update; \
  apt-get install -y libmagickcore-6.q16-3-extra libsmbclient; \
  rm -rf /var/lib/apt/lists/*;

RUN set -ex; \
  savedAptMark="$(apt-mark showmanual)"; \
  apt-get update; \
  apt-get install -y libsmbclient-dev; \
  pecl install smbclient; \
  docker-php-ext-enable smbclient; \
  apt-get install -y libbz2-dev; \
  docker-php-ext-install bz2; \
  # reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
  apt-mark auto '.*' > /dev/null; \
  apt-mark manual $savedAptMark; \
  ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \
      | awk '/=>/ { print $3 }' \
      | sort -u \
      | xargs -r dpkg-query -S \
      | cut -d: -f1 \
      | sort -u \
      | xargs -rt apt-mark manual; \
   \
  apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
  rm -rf /var/lib/apt/lists/*

# copy the redis configuration file.
COPY redis/redis.config.php /usr/src/nextcloud/config/redis.config.php