content: # Accepted values: 8.3 - 8.2
  ARG PHP_VERSION=8.3
  
  ARG FRANKENPHP_VERSION=1.8.0
  
  ARG COMPOSER_VERSION=latest
  
  ###########################################
  # Build frontend assets with NPM
  ###########################################
  
  ARG NODE_VERSION=20-alpine
  
  FROM node:${NODE_VERSION} AS build
  
  ENV ROOT=/var/www/html
  
  WORKDIR ${ROOT}
  
  RUN npm config set update-notifier false && npm set progress=false
  
  COPY --link package*.json ./
  
  RUN if [ -f $ROOT/package-lock.json ]; \
      then \
      npm ci --loglevel=error --no-audit; \
      else \
      npm install --loglevel=error --no-audit; \
      fi
  
  COPY --link . .
  
  RUN npm run build
  
  ###########################################
  
  FROM composer:${COMPOSER_VERSION} AS vendor
  
  FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}-alpine
  
  LABEL maintainer="SMortexa <seyed.me720@gmail.com>"
  LABEL org.opencontainers.image.title="Laravel Octane Dockerfile"
  LABEL org.opencontainers.image.description="Production-ready Dockerfile for Laravel Octane"
  LABEL org.opencontainers.image.source=https://github.com/exaco/laravel-octane-dockerfile
  LABEL org.opencontainers.image.licenses=MIT
  
  ARG WWWUSER=1000
  ARG WWWGROUP=1000
  ARG TZ=UTC
  ARG APP_DIR=/var/www/html
  
  ENV TERM=xterm-color \
      WITH_HORIZON=false \
      WITH_SCHEDULER=false \
      OCTANE_SERVER=frankenphp \
      USER=octane \
      ROOT=${APP_DIR} \
      COMPOSER_FUND=0 \
      COMPOSER_MAX_PARALLEL_HTTP=24 \
      XDG_CONFIG_HOME=${APP_DIR}/.config \
      XDG_DATA_HOME=${APP_DIR}/.data
  
  WORKDIR ${ROOT}
  
  SHELL ["/bin/sh", "-eou", "pipefail", "-c"]
  
  RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime \
      && echo ${TZ} > /etc/timezone
  
  RUN apk update; \
      apk upgrade; \
      apk add --no-cache \
      curl \
      wget \
      nano \
      ncdu \
      procps \
      ca-certificates \
      supervisor \
      libsodium-dev \
      # Install PHP extensions (included with dunglas/frankenphp)
      && install-php-extensions \
      bz2 \
      pcntl \
      mbstring \
      bcmath \
      sockets \
      opcache \
      exif \
      pdo_mysql \
      zip \
      intl \
      gd \
      redis \
      memcached \
      igbinary \
      && docker-php-source delete \
      && rm -rf /var/cache/apk/* /tmp/* /var/tmp/*
  
  RUN arch="$(apk --print-arch)" \
      && case "$arch" in \
      armhf) _cronic_fname='supercronic-linux-arm' ;; \
      aarch64) _cronic_fname='supercronic-linux-arm64' ;; \
      x86_64) _cronic_fname='supercronic-linux-amd64' ;; \
      x86) _cronic_fname='supercronic-linux-386' ;; \
      *) echo >&2 "error: unsupported architecture: $arch"; exit 1 ;; \
      esac \
      && wget -q "https://github.com/aptible/supercronic/releases/download/v0.2.29/${_cronic_fname}" \
      -O /usr/bin/supercronic \
      && chmod +x /usr/bin/supercronic \
      && mkdir -p /etc/supercronic \
      && echo "*/1 * * * * php ${ROOT}/artisan schedule:run --no-interaction" > /etc/supercronic/laravel
  
  RUN addgroup -g ${WWWGROUP} ${USER} \
      && adduser -D -h ${ROOT} -G ${USER} -u ${WWWUSER} -s /bin/sh ${USER}
  
  RUN mkdir -p /var/log/supervisor /var/run/supervisor \
      && chown -R ${USER}:${USER} ${ROOT} /var/log /var/run \
      && chmod -R a+rw ${ROOT} /var/log /var/run
  
  RUN cp ${PHP_INI_DIR}/php.ini-production ${PHP_INI_DIR}/php.ini
  
  USER ${USER}
  
  # Custom .env support
  ARG ENV_FILE
  COPY --link --chown=${USER}:${USER} ${ENV_FILE:-.env} .env
  
  COPY --link --chown=${USER}:${USER} --from=vendor /usr/bin/composer /usr/bin/composer
  COPY --link --chown=${USER}:${USER} composer.json composer.lock ./
  
  RUN composer install \
      --no-dev \
      --no-interaction \
      --no-autoloader \
      --no-ansi \
      --no-scripts \
      --audit
  
  COPY --link --chown=${USER}:${USER} . .
  COPY --link --chown=${USER}:${USER} --from=build ${ROOT}/public public
  
  RUN mkdir -p \
      storage/framework/sessions \
      storage/framework/views \
      storage/framework/cache \
      storage/framework/testing \
      storage/logs \
      bootstrap/cache && chmod -R a+rw storage
  
  COPY --link --chown=${USER}:${USER} deployment/supervisord.conf /etc/supervisor/
  COPY --link --chown=${USER}:${USER} deployment/octane/FrankenPHP/supervisord.frankenphp.conf /etc/supervisor/conf.d/
  COPY --link --chown=${USER}:${USER} deployment/supervisord.*.conf /etc/supervisor/conf.d/
  COPY --link --chown=${USER}:${USER} deployment/start-container /usr/local/bin/start-container
  COPY --link --chown=${USER}:${USER} deployment/php.ini ${PHP_INI_DIR}/conf.d/99-octane.ini
  
  # FrankenPHP embedded PHP configuration
  COPY --link --chown=${USER}:${USER} deployment/php.ini /lib/php.ini
  
  RUN composer install \
      --classmap-authoritative \
      --no-interaction \
      --no-ansi \
      --no-dev \
      && composer clear-cache
  
  RUN chmod +x /usr/local/bin/start-container
  
  RUN cat deployment/utilities.sh >> ~/.bashrc
  
  EXPOSE 8000
  EXPOSE 443
  EXPOSE 443/udp
  EXPOSE 2019
  
  ENTRYPOINT ["start-container"]
  
  HEALTHCHECK --start-period=5s --interval=2s --timeout=5s --retries=8 CMD php artisan octane:status || exit 1
  