# syntax=docker/dockerfile:1
FROM 594765360358.dkr.ecr.ca-central-1.amazonaws.com/tbi-php-85:8.5.12

USER root

# Webpack 4 cannot build on Node 24. Node 18 is the newest release this frontend supports.
# memcached 3.4.0 is already installed in the PHP 8.5.12 image.
RUN apt-get update && apt-get install -y --no-install-recommends unzip git \
    && curl -fsSL https://nodejs.org/dist/v18.20.8/node-v18.20.8-linux-x64.tar.xz | tar -xJ -C /usr/local --strip-components=1 \
    && rm -rf /var/lib/apt/lists/*

RUN mkdir -p /data/websites

COPY . /data/websites/

RUN curl -fsSL -o /usr/local/bin/composer https://github.com/composer/composer/releases/download/2.10.3/composer.phar \
    && echo "7a2d379d5b8ffdaa028580ef26494c36d2feef4b178d3dd1473a4dbc5e17c8d6  /usr/local/bin/composer" | sha256sum -c - \
    && chmod +x /usr/local/bin/composer

WORKDIR /data/websites

RUN --mount=type=secret,id=github_token \
    token=$(cat /run/secrets/github_token) \
    && test -n "$token" \
    && composer config --global github-oauth.github.com "$token" \
    && composer install -n \
    && composer install -n --working-dir=/data/websites/cars \
    && composer install -n --working-dir=/data/websites/flights \
    && composer install -n --working-dir=/data/websites/library \
    && composer config --global --unset github-oauth.github.com \
    && rm -rf /root/.composer /root/.config/composer

RUN npm install
RUN npm run prod

RUN printf '%s\n' \
    'opcache.enable=0' \
    'opcache.enable_cli=0' \
    'opcache.jit=disable' \
    'opcache.jit_buffer_size=0' \
    > /usr/local/etc/php/conf.d/zz-opcache-off.ini

RUN chown -R www-data:www-data /data/websites
COPY apache-booking.conf /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite headers
