
FROM alpine:3.15

# bash and vim for debug
RUN apk update && apk add \
	php7 \
	php7-fpm \
	php7-mysqli \
	php7-phar \
	php7-json \
	php7-iconv \
	mariadb-client \
	curl \
	bash vim
RUN rm -rf /var/lib/apt/lists/*

# fpm config
COPY ./conf/www.conf /etc/php7/php-fpm.d/
RUN mkdir /run/php/

ARG WP_DIR
ARG MAX_UPLOAD_SIZE
ARG EXECUTION_TIME

# create wp directory
RUN mkdir -p ${WP_DIR} 

# replace max file size upload and execution time
RUN sed -i "s/\(upload_max_filesize = \).*\(M\)/\1${MAX_UPLOAD_SIZE}\2/g" /etc/php7/php.ini && \
	sed -i "s/\(post_max_size = \).*\(M\)/\1${MAX_UPLOAD_SIZE}\2/g" /etc/php7/php.ini && \
	sed -i "s/\(max_execution_time = \).*/\1${EXECUTION_TIME}/g" /etc/php7/php.ini

# create www-data user and add to group
RUN adduser -S www-data && \
	adduser www-data www-data

ENV PHP_VERSION="php-fpm7"

# empty /var/www/html folder to avoid it to rewrite volume
#RUN rm -rf ${WP_DIR}/*

# install wp-cli : https://wp-cli.org/#installing
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar &&\
	chmod +x wp-cli.phar && \
	mv wp-cli.phar /usr/local/bin/wp

COPY ./conf/wp_entrypoint.sh ./

ENTRYPOINT [ "sh", "wp_entrypoint.sh" ]

