<commit_before>FROM node:alpine as builder

WORKDIR /smr/

# See https://github.com/hollandben/grunt-cache-bust/issues/236
RUN npm i --save grunt grunt-contrib-uglify grunt-contrib-cssmin grunt-cache-bust@1.4.1

# Copy the SMR source code directories
COPY src src

# Perform CSS/JS minification and cache busting
COPY Gruntfile.js .
RUN npx grunt

# Remove local grunt install so it is not copied to the next build stage
RUN rm -rf node_modules

#---------------------------

FROM php:7.4.14-apache
RUN apt-get update \
	&& apt-get install -y zip unzip \
	&& rm -rf /var/lib/apt/lists/* \
	&& docker-php-ext-install mysqli opcache

# Disable apache access logging (error logging is still enabled)
RUN sed -i 's|CustomLog.*|CustomLog /dev/null common|' /etc/apache2/sites-enabled/000-default.conf

# Disable apache .htaccess files (suggested optimization)
RUN sed -i 's/AllowOverride All/AllowOverride None/g' /etc/apache2/conf-enabled/docker-php.conf

WORKDIR /smr/

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

COPY composer.json .
RUN composer install --no-interaction

# Set the baseline php.ini version based on the value of PHP_DEBUG
ARG PHP_DEBUG=0
RUN MODE=$([ "$PHP_DEBUG" = "0" ] && echo "production" || echo "development") && \
	echo "Using $MODE php.ini" && \
	tar -xOvf /usr/src/php.tar.xz php-$PHP_VERSION/php.ini-$MODE > /usr/local/etc/php/php.ini

RUN if [ "$PHP_DEBUG" = "1" ] ; then pecl install xdebug-2.8.1 \
	&& docker-php-ext-enable xdebug ; \
	fi

COPY --from=builder /smr .
RUN rm -rf /var/www/html/ && ln -s "$(pwd)/src/htdocs" /var/www/html

# Make the upload directory writable by the apache user
RUN chown www-data ./src/htdocs/upload

# Leverage browser caching of static assets using apache's mod_headers
COPY apache/cache-static.conf /etc/apache2/conf-enabled/cache-static.conf
RUN a2enmod headers

# Store the git commit hash of the repo in the final image
COPY .git/HEAD .git/HEAD
COPY .git/refs .git/refs
RUN REF="ref: HEAD" && \
	while [ -n "$(echo $REF | grep ref:)" ]; do REF=$(cat ".git/$(echo $REF | awk '{print $2}')"); done && \
	echo $REF > git-commit
<commit_msg>Dockerfile: clean up PHP_DEBUG logic<commit_after>FROM node:alpine as builder

WORKDIR /smr/

# See https://github.com/hollandben/grunt-cache-bust/issues/236
RUN npm i --save grunt grunt-contrib-uglify grunt-contrib-cssmin grunt-cache-bust@1.4.1

# Copy the SMR source code directories
COPY src src

# Perform CSS/JS minification and cache busting
COPY Gruntfile.js .
RUN npx grunt

# Remove local grunt install so it is not copied to the next build stage
RUN rm -rf node_modules

#---------------------------

FROM php:7.4.14-apache
RUN apt-get update \
	&& apt-get install -y zip unzip \
	&& rm -rf /var/lib/apt/lists/* \
	&& docker-php-ext-install mysqli opcache

# Disable apache access logging (error logging is still enabled)
RUN sed -i 's|CustomLog.*|CustomLog /dev/null common|' /etc/apache2/sites-enabled/000-default.conf

# Disable apache .htaccess files (suggested optimization)
RUN sed -i 's/AllowOverride All/AllowOverride None/g' /etc/apache2/conf-enabled/docker-php.conf

WORKDIR /smr/

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

COPY composer.json .
RUN composer install --no-interaction

# Set the baseline php.ini version based on the value of PHP_DEBUG
ARG PHP_DEBUG=0
RUN MODE=$([ "$PHP_DEBUG" = "1" ] && echo "development" || echo "production") && \
	echo "Using $MODE php.ini" && \
	tar -xOvf /usr/src/php.tar.xz php-$PHP_VERSION/php.ini-$MODE > /usr/local/etc/php/php.ini

RUN if [ "$PHP_DEBUG" = "1" ]; \
	then \
		pecl install xdebug-2.8.1 && \
		docker-php-ext-enable xdebug; \
	fi

COPY --from=builder /smr .
RUN rm -rf /var/www/html/ && ln -s "$(pwd)/src/htdocs" /var/www/html

# Make the upload directory writable by the apache user
RUN chown www-data ./src/htdocs/upload

# Leverage browser caching of static assets using apache's mod_headers
COPY apache/cache-static.conf /etc/apache2/conf-enabled/cache-static.conf
RUN a2enmod headers

# Store the git commit hash of the repo in the final image
COPY .git/HEAD .git/HEAD
COPY .git/refs .git/refs
RUN REF="ref: HEAD" && \
	while [ -n "$(echo $REF | grep ref:)" ]; do REF=$(cat ".git/$(echo $REF | awk '{print $2}')"); done && \
	echo $REF > git-commit

{'fraction_non_alphanumeric': 0.1465260261407934, 'fraction_numerical': 0.011006649850951617, 'mean_word_length': 3.3576423576423577, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6215763', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1498, 'n_words': 468}