FROM php:8.5-fpm-alpine AS base

ARG UID=1000
ARG GID=1000
ENV USER=mareike
ENV GROUPNAME=$USER

RUN addgroup -g ${GID} -S ${GROUPNAME} \
 && adduser -u ${UID} -D -S -G ${GROUPNAME} ${USER}

RUN apk add --no-cache \
    mc \
    unzip \
    rsync

COPY --chmod=0755 /docker/php/composer.phar /usr/bin/composer
RUN apk add --no-cache --virtual .build-deps \
    autoconf \
    build-base \
    libzip-dev \
    libpng-dev \
    libxml2-dev \
    oniguruma-dev \
    nodejs \
    imagemagick-dev \
    npm && \
    pecl install imagick && docker-php-ext-enable imagick

RUN docker-php-ext-install mysqli pdo pdo_mysql mbstring zip exif pcntl gd

COPY . /var/www/html
WORKDIR /var/www/html
RUN composer install --no-dev --optimize-autoloader
RUN npm install
RUN npm run build

EXPOSE 9000

RUN mv /var/www/html /src
COPY docker/run-mareike.sh /usr/local/bin/

USER mareike
CMD ["run-mareike.sh"]
