126 lines
5.0 KiB
Docker
126 lines
5.0 KiB
Docker
ARG OS_VERSION=9.5
|
|
|
|
FROM quay.io/teras/almalinux:${OS_VERSION}-minimal AS builder
|
|
|
|
ARG OS_SHORT_VERSION=9
|
|
ARG PHP_VERSION=8.4
|
|
ARG COMPOSER_VERSION=2.8.9
|
|
ARG WEB_SERVER=false
|
|
|
|
ENV PHP_VERSION=${PHP_VERSION}
|
|
ENV COMPOSER_VERSION=${COMPOSER_VERSION}
|
|
ENV SERVER_ROOT=/app
|
|
ENV APP_ROOT=${SERVER_ROOT}/htdocs
|
|
ENV WEB_SERVER=${WEB_SERVER}
|
|
|
|
ENV COMPOSER_HOME=/var/lib/composer
|
|
ENV COMPOSER_ALLOW_SUPERUSER=0
|
|
ENV COMPOSER_NO_INTERACTION=1
|
|
ENV COMPOSER_CACHE_DIR=${COMPOSER_HOME}/cache
|
|
ENV COMPOSER_VENDOR_DIR=${COMPOSER_HOME}/vendor
|
|
ENV COMPOSER_BIN_DIR=${COMPOSER_HOME}/bin
|
|
|
|
USER root
|
|
WORKDIR ${SERVER_ROOT}
|
|
|
|
ADD https://github.com/composer/composer/releases/download/${COMPOSER_VERSION}/composer.phar /usr/local/bin/composer
|
|
ADD ./htdocs/index.html ${APP_ROOT}/
|
|
|
|
RUN /bin/mkdir -p ${COMPOSER_CACHE_DIR} ${COMPOSER_VENDOR_DIR} ${COMPOSER_BIN_DIR}; \
|
|
/bin/chown -R appuser:appuser ${COMPOSER_HOME}; \
|
|
/bin/microdnf -y --nodocs install epel-release; \
|
|
/bin/microdnf -y upgrade; \
|
|
/bin/rpm -Uvh --replacepkgs --replacefiles \
|
|
https://rpms.remirepo.net/enterprise/remi-release-${OS_SHORT_VERSION}.rpm; \
|
|
/bin/microdnf -y module reset php; \
|
|
/bin/microdnf -y module enable php:remi-${PHP_VERSION}; \
|
|
/bin/microdnf -y --nodocs install \
|
|
php php-cli php-common php-phar \
|
|
php-iconv php-mbstring php-json; \
|
|
/bin/chmod +rx /usr/local/bin/composer; \
|
|
/bin/sed -i "s|#version#|${PHP_VERSION}}|" ${APP_ROOT}/index.html ;
|
|
|
|
# Run if httpd is being installed, otherwise remove all packages related to it
|
|
RUN if [ ${WEB_SERVER} = "apache" ]; then \
|
|
/bin/mkdir -p ${SERVER_ROOT}/cgi-bin; \
|
|
/bin/chown -R appuser:appuser ${SERVER_ROOT}/cgi-bin; \
|
|
/bin/chown -R appuser:appuser /etc/httpd \
|
|
/bin/sed -i "s|ServerRoot /var/www|ServerRoot ${SERVER_ROOT}|" /etc/httpd/conf/httpd.conf ; \
|
|
/bin/sed -i "s|User apache|User appuser|" /etc/httpd/conf/httpd.conf ; \
|
|
/bin/sed -i "s|Group httpd|Group appuser|" /etc/httpd/conf/httpd.conf ; \
|
|
/bin/sed -i "s|ServerAdmin root@localhost| ServerAdmin appuser@localhost|" /etc/httpd/conf/httpd.conf ; \
|
|
/bin/sed -i "s|DocumentRoot \"/var/www\"|DocumentRoot \"${SERVER_ROOT}\"|" /etc/httpd/conf/httpd.conf ; \
|
|
/bin/sed -i "s|DocumentRoot \"/var/www/html\"|DocumentRoot \"${APP_ROOT}\"|" /etc/httpd/conf/httpd.conf ; \
|
|
/bin/sed -i "s|Directory \"/var/www/html\"|Directory \"${APP_ROOT}\"|" /etc/httpd/conf/httpd.conf ; \
|
|
/bin/sed -i "s|AllowOverride None|AllowOverride All|" /etc/httpd/conf/httpd.conf ; \
|
|
/bin/sed -i "s|ErrorLog .*|ErrorLog /dev/stderr \nTransferLog /dev/stdout|" /etc/httpd/conf/httpd.conf ; \
|
|
/bin/sed -i "s|CustomLog .* combined|CustomLog /dev/stdout combined|" /etc/httpd/conf/httpd.conf ; \
|
|
/bin/sed -i "s|LogLevel .*|LogLevel ${LOG_LEVEL}|" /etc/httpd/conf/httpd.conf ; \
|
|
/bin/sed -i "s|LogLevel .*|LogLevel ${LOG_LEVEL}|" /etc/httpd/conf/httpd.conf ; \
|
|
/bin/sed -i "s|/var/www/cgi-bin/|${SERVER_ROOT}/cgi-bin/|" /etc/httpd/conf/httpd.conf ; \
|
|
else \
|
|
/bin/rpm -e --nodeps $(rpm -qa | grep ^httpd) php-fpm; \
|
|
/bin/rm -rf /etc/httpd; \
|
|
fi
|
|
|
|
# Run if nginx is being installed otherwise remove all packages related to it
|
|
RUN if [ ${WEB_SERVER} = "fpm-nginx" ]; then \
|
|
/bin/microdnf -y --nodocs install nginx php-fpm; \
|
|
else \
|
|
/bin/rpm -e --nodeps $(rpm -qa | grep ^nginx); \
|
|
fi
|
|
|
|
# Remove unnecessary packages and clean up all cached files
|
|
RUN rpm -e --nodeps python-unversioned-command $(rpm -qa | grep ^python3) ; \
|
|
rm -rf /usr/lib/python3* /usr/lib64/python3* /usr/share/doc/python3* /usr/share/man/man1/python3* ; \
|
|
/bin/microdnf clean all; \
|
|
/bin/rm -rf /var/cache/yum/*; \
|
|
/bin/rm -rf /var/lib/yum/history/*; \
|
|
/bin/rm -rf /var/lib/yum/yumdb/*; \
|
|
/bin/rm -rf /var/lib/dnf/*;
|
|
|
|
# Create symlinks to /usr/bin/php in case it doesn't exists
|
|
RUN ln -ns /usr/bin/php${PHP_VERSION} /usr/bin/php; exit 0
|
|
|
|
FROM scratch
|
|
|
|
ARG PHP_VERSION=8.4
|
|
ARG COMPOSER_VERSION=2.8.9
|
|
|
|
# Environment variables for user root
|
|
ENV LANG=en_US.UTF-8
|
|
|
|
ENV PHP_VERSION=${PHP_VERSION}
|
|
ENV COMPOSER_VERSION=${COMPOSER_VERSION}
|
|
ENV SERVER_ROOT=/app
|
|
ENV APP_ROOT=${SERVER_ROOT}/htdocs
|
|
|
|
ENV COMPOSER_HOME=${SERVER_ROOT}/.composer
|
|
ENV COMPOSER_ALLOW_SUPERUSER=0
|
|
ENV COMPOSER_NO_INTERACTION=1
|
|
ENV COMPOSER_CACHE_DIR=${COMPOSER_HOME}/cache
|
|
ENV COMPOSER_VENDOR_DIR=${COMPOSER_HOME}/vendor
|
|
ENV COMPOSER_BIN_DIR=${COMPOSER_HOME}/bin
|
|
|
|
LABEL maintainer="Muhamad Aditya Prima <aditya@teraslink.id>"
|
|
LABEL name="php"
|
|
LABEL version="${PHP_VERSION}"
|
|
LABEL distribution-scope="public"
|
|
|
|
#labels for container catalog
|
|
LABEL summary="PHP ${PHP_VERSION} on almalinux-minimal container image"
|
|
LABEL description="Provide php on almalinux-minimal container base image"
|
|
LABEL io.k8s.description="PHP with composer"
|
|
LABEL io.k8s.display-name="PHP ${PHP_VERSION}"
|
|
|
|
COPY --from=builder / /
|
|
|
|
ENV PATH="${PATH}:${COMPOSER_BIN_DIR}:${COMPOSER_VENDOR_DIR}/bin"
|
|
|
|
WORKDIR ${SERVER_ROOT}
|
|
|
|
USER appuser
|
|
|
|
STOPSIGNAL SIGQUIT
|
|
|
|
CMD ["/usr/bin/php", "-v"] |