Last active
May 5, 2024 04:58
-
-
Save lstellway/19441a4a0de81828c7fa5b7e6d254eb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM alpine:3.19.1 as base | |
LABEL Description="NGINX & PHP 8.x on Alpine Linux" | |
LABEL org.opencontainers.image.source=https://github.com/builtforbackroads/admin-wp | |
WORKDIR /var/www/html | |
# System dependencies | |
RUN apk update \ | |
&& apk add --no-cache \ | |
curl \ | |
nginx \ | |
supervisor \ | |
gifsicle jpegoptim pngquant \ | |
php83 php83-fpm php83-bcmath php83-ctype php83-curl php83-dom php83-exif php83-fileinfo php83-gd php83-iconv php83-intl php83-json php83-mbstring php83-mysqli php83-opcache php83-pdo_mysql php83-phar php83-session php83-simplexml php83-soap php83-sockets php83-tokenizer php83-xmlreader php83-xmlwriter php83-xsl php83-zip php83-zlib | |
# Create symlinks | |
RUN \ | |
([ -f "/usr/bin/php" ] || ln -s "/usr/bin/php83" "/usr/bin/php") \ | |
&& PHP_FPM=$(which php-fpm83) \ | |
&& (command -v php-fpm || ln -s "${PHP_FPM}" "${PHP_FPM/83/}") | |
# Make sure files/folders needed by the processes are accessable when they run under the nobody user | |
RUN chown -R nobody.nobody \ | |
/var/www/html \ | |
/run \ | |
/var/lib/nginx \ | |
/var/log/nginx \ | |
/var/log/php83 | |
# Expose the port nginx is reachable on | |
EXPOSE 80 | |
# build | |
FROM base as builder | |
ARG ACF_PRO_KEY= | |
COPY --from=composer /usr/bin/composer /usr/bin/composer | |
RUN apk add --no-cache \ | |
git patch npm \ | |
build-base autoconf automake | |
# Switch to use a non-root user | |
USER nobody | |
# Install composer dependencies | |
COPY --chown=nobody composer.* ./ | |
RUN printf "ACF_PRO_KEY=${ACF_PRO_KEY}" > "/var/www/html/.env" \ | |
&& composer install --optimize-autoloader --no-scripts --no-interaction \ | |
&& rm -f "/var/www/html/.env" | |
#################### | |
# production stage # | |
#################### | |
FROM base AS prod | |
# Add configurations | |
COPY --from=builder --chown=nobody "/var/www/html" "/var/www/html" | |
COPY .dev/build/nginx.conf /etc/nginx/nginx.conf | |
COPY .dev/build/fpm-pool.conf /etc/php83/php-fpm.d/www.conf | |
COPY .dev/build/php.ini /etc/php83/conf.d/custom.ini | |
COPY .dev/build/supervisord.conf /etc/supervisor/conf.d/supervisord.conf | |
COPY --chown=nobody . . | |
USER nobody | |
# Let supervisord start nginx & php-fpm | |
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] | |
# Configure a healthcheck to validate that everything is up&running | |
HEALTHCHECK --timeout=10s CMD curl --silent --fail http://127.0.0.1:8080/fpm-ping |
Author
lstellway
commented
May 5, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment