FROM composer:2 AS composer

FROM alpine:3.23
WORKDIR /opt/laysite

RUN apk add --no-cache ca-certificates unzip \
        php84 php84-ctype php84-curl php84-dom php84-fileinfo php84-iconv php84-mbstring \
        php84-openssl php84-pcntl php84-pdo_sqlite php84-phar php84-posix php84-session php84-tokenizer \
    && ln -s /usr/bin/php84 /usr/local/bin/php \
    && addgroup -g 10001 laysite \
    && adduser -D -H -u 10001 -G laysite -h /opt/laysite laysite \
    && install -d -o 10001 -g 10001 -m 0750 storage runtime

COPY --from=composer /usr/bin/composer /usr/local/bin/composer
COPY composer.json composer.lock ./
COPY app/ app/
RUN COMPOSER_ALLOW_SUPERUSER=1 composer install --no-dev --prefer-dist --no-interaction --no-progress

COPY bin/ bin/
COPY config/ config/
COPY public/ public/
COPY resources/ resources/
COPY support/ support/
COPY .agents/ .agents/
COPY LICENSE NOTICE README.md VERSION start.php updatescript_map.json ./
COPY --chown=10001:10001 storage/.gitignore storage/.gitignore

ENV LAYSITE_LISTEN=http://0.0.0.0:8787
VOLUME ["/opt/laysite/storage"]
EXPOSE 8787
USER 10001:10001
CMD ["sh", "-c", "php bin/install.php && unset LAYSITE_ADMIN_EMAIL LAYSITE_ADMIN_PASSWORD && exec php start.php start"]
