# PHP 8.5.12. tbi-php-85 is Debian 13 and already includes mysqli, pdo_mysql,
# mbstring, gd, zip, curl, soap, memcached, and redis.
FROM 594765360358.dkr.ecr.ca-central-1.amazonaws.com/tbi-php-85:latest

# Legacy files use short open tags. The ini also loads the Memcached shim
# so the search engines can keep calling the old Memcache class.
ARG PHP_INI_DIR=/usr/local/etc/php
COPY build/docker/zz-redtag.ini ${PHP_INI_DIR}/conf.d/zz-redtag.ini

# Webpack 4 and node-sass 4 need the Node 14 binary.
RUN curl -fsSL https://nodejs.org/dist/v14.21.3/node-v14.21.3-linux-x64.tar.xz | tar -xJ -C /usr/local --strip-components=1 && \
    apt-get update && \
    apt-get install -y git zip && \
    rm -rf /var/lib/apt/lists/*

RUN mkdir -p /data/websites
COPY . /data/websites/
RUN curl -L https://github.com/composer/composer/releases/download/2.8.12/composer.phar > /usr/local/bin/composer && \
    chmod +x /usr/local/bin/composer

WORKDIR /data/websites

USER root

RUN mkdir /root/.ssh/ && \
    mv id_jenkins /root/.ssh/id_rsa && \
    chmod 400 /root/.ssh/id_rsa && \
    ssh-keyscan github.com >> /root/.ssh/known_hosts

RUN composer install -n --no-dev --optimize-autoloader

WORKDIR /data/websites/engine

RUN composer install -n --no-dev --optimize-autoloader

WORKDIR /data/websites/passport

RUN composer install -n --no-dev --optimize-autoloader

WORKDIR /data/websites/build

RUN npm install --force && \
    npm run prod

WORKDIR /data

RUN chown -R www-data:www-data /data/websites
