ARG PHP_VERSION
FROM ${PHP_VERSION}

ARG TZ
ARG PHP_EXTENSIONS
ARG CONTAINER_PACKAGE_URL


# RUN sed -i "s/dl-cdn.alpinelinux.org/${CONTAINER_PACKAGE_URL}/g" /etc/apk/repositories


# COPY ./extensions /tmp/extensions
# WORKDIR /tmp/extensions

# RUN chmod +x install.sh \
#     && sh install.sh

# RUN rm -fr /tmp/extensions


RUN apk --no-cache add tzdata \
    && cp "/usr/share/zoneinfo/$TZ" /etc/localtime \
    && echo "$TZ" > /etc/timezone


# Fix: https://github.com/docker-library/php/issues/240
RUN apk add gnu-libiconv --no-cache --repository http://${CONTAINER_PACKAGE_URL}/alpine/v3.10/community/ --allow-untrusted
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php

RUN apk add --no-cache libzip-dev \
    && docker-php-ext-configure zip --with-libzip=/usr/include \
    && docker-php-ext-install zip

# Install composer and change it's cache home
# RUN curl -o /usr/bin/composer https://mirrors.aliyun.com/composer/composer.phar \
#     && chmod +x /usr/bin/composer
# RUN composer self-update --2.2
#  WORKDIR /tmp
#  RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
#      && php composer-setup.php --version=2.2.18 \
#      && mv composer.phar /usr/bin/composer \
#      && php composer-setup.php --version=1.10.26 \
#      && mv composer.phar /usr/bin/composer1 \
#      && chmod +x /usr/bin/composer \
#      && chmod +x /usr/bin/composer1 \
#      && rm -f /tmp/composer-setup.php
# ENV COMPOSER_HOME=/tmp/composer-setup.php
 ENV COMPOSER_HOME=/usr/local/bin/composer


# php image's www-data user uid & gid are 82, change them to 1000 (primary user)
RUN apk --no-cache add shadow && usermod -u 1000 www-data && groupmod -g 1000 www-data
# Use www-data to run the first process
USER www-data


WORKDIR /www
