
FROM alpine:3.15

# all packages (from : https://mricher.fr/post/all-php-modules-for-alpine/)
# apk update && apk add php7-bcmath php7-bz2 php7-calendar php7-cgi php7-common php7-ctype php7-curl php7-dba php7-dbg php7-dev php7-doc php7-dom php7-embed php7-enchant php7-exif php7-fileinfo php7-fpm php7-ftp php7-gd php7-gettext php7-gmp php7-iconv php7-imap php7-intl php7-json php7-ldap php7-litespeed php7-mbstring php7-mysqli php7-mysqlnd php7-odbc php7-opcache php7-openssl php7-pcntl php7-pdo php7-pdo_dblib php7-pdo_mysql php7-pdo_odbc php7-pdo_pgsql php7-pdo_sqlite php7-pear php7-pgsql php7-phar php7-phpdbg php7-posix php7-pspell php7-recode php7-session php7-shmop php7-simplexml php7-snmp php7-soap php7-sockets php7-sodium php7-sqlite3 php7-static php7-sysvmsg php7-sysvsem php7-sysvshm php7-tidy php7-tokenizer php7-wddx php7-xml php7-xmlreader php7-xmlrpc php7-xmlwriter php7-xsl php7-zip php7-pecl-xhprof php7-pecl-xhprof-assets php7-pecl-uuid php7-pecl-protobuf php7-pecl-xdebug php7-pecl-memcached php7-pecl-oauth php7-pecl-ssh2 php7-pecl-imagick php7-pecl-imagick-dev php7-pecl-vips php7-pecl-ast php7-pecl-event php7-pecl-redis php7-phalcon php7-pecl-apcu php7-pecl-timezonedb php7-pecl-mcrypt php7-pecl-mailparse php7-pecl-msgpack php7-pecl-yaml php7-pecl-zmq php7-brotli php7-pecl-amqp php7-pecl-couchbase php7-pecl-gmagick php7-pecl-igbinary php7-pecl-lzf
# bash and vim for debug
RUN apk update && apk add \
	php7 \
	php7-fpm \
	php7-mysqli \
	php7-phar \
	php7-json \
	php7-iconv \
	\
	php7-tokenizer \
	php7-zip \
	php7-dom \
	\
	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_VOLUME_DIR
ARG WP_VOLUME_PLUGINS
ARG MAX_UPLOAD_SIZE
ARG EXECUTION_TIME

# create and empty volumes dir
RUN mkdir -p ${WP_VOLUME_DIR}   ${WP_VOLUME_PLUGINS} && \
	rm -rf   ${WP_VOLUME_DIR}/* ${WP_VOLUME_PLUGINS}/*

# 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"

# 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" ]

