From 54ef426c57e1aa910389a236a17d71922abf619c Mon Sep 17 00:00:00 2001 From: Muhamad Aditya Prima Date: Tue, 20 May 2025 16:23:40 +0700 Subject: [PATCH 1/3] Added php-cli with almalinux-minimal base image --- .gitea/workflows/php8-almalinux.yaml | 74 ++++++++++++++++++++++++++++ 8/Dockerfile.almalinux | 67 +++++++++++++++++++++++++ 8/Dockerfile.almalinux-apache | 3 ++ 8/Dockerfile.almalinux-builder | 61 +++++++++++++++++++++++ 8/scripts/almalinux-apache-setup.sh | 31 ++++++++++++ 5 files changed, 236 insertions(+) create mode 100644 .gitea/workflows/php8-almalinux.yaml create mode 100644 8/Dockerfile.almalinux create mode 100644 8/Dockerfile.almalinux-apache create mode 100644 8/Dockerfile.almalinux-builder create mode 100644 8/scripts/almalinux-apache-setup.sh diff --git a/.gitea/workflows/php8-almalinux.yaml b/.gitea/workflows/php8-almalinux.yaml new file mode 100644 index 0000000..b9733ea --- /dev/null +++ b/.gitea/workflows/php8-almalinux.yaml @@ -0,0 +1,74 @@ +name: Build and push PHP 8 container images + +on: + push: + branches: + - php8-almalinux + +jobs: + build: + name: Build PHP 8 container images + runs-on: ubuntu-latest + container: + image: ghcr.io/catthehacker/ubuntu:act-latest + strategy: + matrix: + flavors: + - os: "almalinux" + os_version: "9.5" + php_version: "8.4" + composer_version: "2.8.9" + steps: + - name: Check out repository code + uses: actions/checkout@v4 + - name: Login to quay.io + uses: docker/login-action@v3 + with: + registry: quay.io + username: ${{ vars.QUAY_USERNAME }} + password: ${{ secrets.QUAY_SECRET }} + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v3 + - name: Build and push php ${{ matrix.flavors.php_version }} + uses: docker/build-push-action@v5 + with: + push: true + context: . + file: 8/Dockerfile.${{ matrix.flavors.os }} + build-args: | + OS_VERSION=${{ matrix.flavors.os_version }} + PHP_VERSION=${{ matrix.flavors.php_version }} + COMPOSER_VERSION=${{ matrix.flavors.composer_version }} + tags: | + quay.io/teras/php:${{ matrix.flavors.php_version }} + build-latest: + name: Build PHP 8 container images + runs-on: ubuntu-latest + needs: + - build + container: + image: ghcr.io/catthehacker/ubuntu:act-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + - name: Login to quay.io + uses: docker/login-action@v3 + with: + registry: quay.io + username: ${{ vars.QUAY_USERNAME }} + password: ${{ secrets.QUAY_SECRET }} + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v3 + - name: Build and push php8 latest + uses: docker/build-push-action@v5 + with: + push: true + context: . + file: 8/Dockerfile.almalinux + build-args: | + OS_VERSION=9.5 + PHP_VERSION=8.4 + COMPOSER_VERSION=2.8.9 + tags: | + quay.io/teras/php:8 + quay.io/teras/php:latest diff --git a/8/Dockerfile.almalinux b/8/Dockerfile.almalinux new file mode 100644 index 0000000..ffc5fa7 --- /dev/null +++ b/8/Dockerfile.almalinux @@ -0,0 +1,67 @@ +ARG OS_VERSION=9.5 + +FROM quay.io/teras/almalinux:${OS_VERSION}-minimal AS builder + +ARG PHP_VERSION=8.4 +ARG COMPOSER_VERSION=2.8.9 + +ENV PHP_VERSION=${PHP_VERSION} +ENV COMPOSER_VERSION=${COMPOSER_VERSION} +ENV SERVER_ROOT=/app + +RUN /bin/mkdir -p ${SERVER_ROOT}; \ + /sbin/groupadd -g 10000 php; \ + /sbin/useradd -u 10000 -g 10000 -s /bin/sh -d ${SERVER_ROOT} php; \ + /bin/chown -R php:php ${SERVER_ROOT}; \ + /bin/microdnf -y --nodocs install epel-release; \ + /bin/microdnf -y upgrade; \ + /bin/rpm -Uvh --replacepkgs --replacefiles \ + https://rpms.remirepo.net/enterprise/remi-release-9.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; + +ADD https://github.com/composer/composer/releases/download/${COMPOSER_VERSION}/composer.phar /usr/local/bin/composer + +RUN /bin/chown php:php /usr/local/bin/composer; \ + /bin/chmod +rx /usr/local/bin/composer; \ + /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 + +ENV PHP_VERSION=${PHP_VERSION} +ENV COMPOSER_VERSION=${COMPOSER_VERSION} +ENV SERVER_ROOT=/app + +LABEL maintainer="Muhamad Aditya Prima " +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 / / + +WORKDIR ${SERVER_ROOT} + +USER php + +STOPSIGNAL SIGQUIT + +CMD ["/usr/bin/php", "-v"] \ No newline at end of file diff --git a/8/Dockerfile.almalinux-apache b/8/Dockerfile.almalinux-apache new file mode 100644 index 0000000..e8b983c --- /dev/null +++ b/8/Dockerfile.almalinux-apache @@ -0,0 +1,3 @@ +ARG PHP_VERSION=8.4 + +FROM quay.io/teras/php:${PHP_VERSION} \ No newline at end of file diff --git a/8/Dockerfile.almalinux-builder b/8/Dockerfile.almalinux-builder new file mode 100644 index 0000000..f6ea420 --- /dev/null +++ b/8/Dockerfile.almalinux-builder @@ -0,0 +1,61 @@ +ARG OS_VERSION=9.5 + +FROM quay.io/teras/almalinux:${OS_VERSION}-minimal + +ARG PHP_VERSION=8.4 +ARG PHP_LONG_VERSION=8.4.7 +ARG COMPOSER_VERSION=2.8.9 + +ENV PHP_VERSION=${PHP_VERSION} +ENV COMPOSER_VERSION=${COMPOSER_VERSION} +ENV SERVER_ROOT=/app + +ENV PHP_DEPS \ + tar gzip \ + gcc gcc-c++ make autoconf bison make + +ENV PHP_INI_DIR=/etc/php + +WORKDIR /tmp + +ADD https://www.php.net/distributions/php-${PHP_LONG_VERSION}.tar.gz /tmp/php-src.tar.gz + +RUN /sbin/groupadd -g 10000 php; \ + /sbin/useradd -u 10000 -g 10000 -s /bin/sh -d ${SERVER_ROOT} php; \ + /bin/microdnf -y --nodocs install ${PHP_DEPS}; \ + /bin/tar -xzf /tmp/php-src.tar.gz -C /usr/src; + +# /bin/mkdir -p ${SERVER_ROOT}; \ +# /sbin/groupadd -g 10000 php; \ +# /sbin/useradd -u 10000 -g 10000 -s /bin/sh -d ${SERVER_ROOT} php; \ +# /bin/chown -R php:php ${SERVER_ROOT}; \ +# /bin/microdnf -y --nodocs install epel-release; \ +# /bin/microdnf -y upgrade; \ +# /bin/rpm -Uvh --replacepkgs --replacefiles \ +# https://rpms.remirepo.net/enterprise/remi-release-9.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; + +# ADD https://github.com/composer/composer/releases/download/${COMPOSER_VERSION}/composer.phar /usr/local/bin/composer + +# RUN /bin/chown php:php /usr/local/bin/composer; \ +# /bin/chmod +rx /usr/local/bin/composer; \ +# /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 + +# WORKDIR ${SERVER_ROOT} +# USER php + +# CMD ["/usr/bin/php", "-v"] +CMD ["/bin/sh"] + +STOPSIGNAL SIGQUIT \ No newline at end of file diff --git a/8/scripts/almalinux-apache-setup.sh b/8/scripts/almalinux-apache-setup.sh new file mode 100644 index 0000000..680b04b --- /dev/null +++ b/8/scripts/almalinux-apache-setup.sh @@ -0,0 +1,31 @@ +# DIRECTORY CONFIGURATION +SERVER_ROOT="/app" +APP_ROOT="$SERVER_ROOT/htdocs" +LOG_LEVEL="info" + +/bin/mkdir -p $APP_ROOT $SERVER_ROOT/run $SERVER_ROOT/log $SERVER_ROOT/cgi-bin; +/usr/sbin/groupadd -g 10001 httpd ; +/usr/sbin/useradd -D -u 10001 -g 10001 -s /bin/sh -h $APP_ROOT httpd ; +/bin/chown -R httpd:httpd $SERVER_ROOT; +/bin/chmod -R 755 $APP_ROOT; + +sed -i "s|ServerRoot /var/www|ServerRoot ${SERVER_ROOT}|" /etc/httpd/httpd.conf ; +sed -i "s|User apache|User httpd|" /etc/httpd/httpd.conf ; +sed -i "s|Group httpd|Group httpd|" /etc/httpd/httpd.conf ; +sed -i "s|ServerAdmin root@localhost| ServerAdmin httpd@localhost|" /etc/httpd/httpd.conf ; +sed -i "s|DocumentRoot \"/var/www\"|DocumentRoot \"${SERVER_ROOT}\"|" /etc/httpd/httpd.conf ; +sed -i "s|DocumentRoot \"/var/www/html\"|DocumentRoot \"${APP_ROOT}\"|" /etc/httpd/httpd.conf ; +sed -i "s|Directory \"/var/www/html\"|Directory \"${APP_ROOT}\"|" /etc/httpd/httpd.conf ; +sed -i "s|AllowOverride None|AllowOverride All|" /etc/httpd/httpd.conf ; +sed -i "s|ErrorLog .*|ErrorLog /dev/stderr \nTransferLog /dev/stdout|" /etc/httpd/httpd.conf ; +sed -i "s|CustomLog .* combined|CustomLog /dev/stdout combined|" /etc/httpd/httpd.conf ; +sed -i "s|LogLevel .*|LogLevel ${LOG_LEVEL}|" /etc/httpd/httpd.conf ; +sed -i "s|LogLevel .*|LogLevel ${LOG_LEVEL}|" /etc/httpd/httpd.conf ; +#sed -i "s|#LoadModule rewrite_module|LoadModule rewrite_module|" /etc/httpd/httpd.conf ; +#sed -i "s|#LoadModule deflate_module|LoadModule deflate_module|" /etc/httpd/httpd.conf ; +#sed -i "s|#LoadModule expires_module|LoadModule expires_module|" /etc/httpd/httpd.conf ; +sed -i "s|/var/www/cgi-bin/|${SERVER_ROOT}/cgi-bin/|" /etc/httpd/httpd.conf ; + +# sed -i "s|Require host .example.com|#Require host .example.com|" /etc/apache2/conf.d/info.conf ; +# sed -i "s|Require ip 127|Require all granted|" /etc/apache2/conf.d/info.conf ; +# sed -i "s|/run/apache2/httpd.pid|${SERVER_ROOT}/run/httpd.pid|" /etc/apache2/conf.d/mpm.conf ; \ No newline at end of file From 0e0a416cb915f04743e44542cf31cf1ce0a45a6c Mon Sep 17 00:00:00 2001 From: Muhamad Aditya Prima Date: Tue, 20 May 2025 16:30:04 +0700 Subject: [PATCH 2/3] Updated action workflows --- .gitea/workflows/php8-almalinux.yaml | 36 +++++++++------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/.gitea/workflows/php8-almalinux.yaml b/.gitea/workflows/php8-almalinux.yaml index b9733ea..3f6c506 100644 --- a/.gitea/workflows/php8-almalinux.yaml +++ b/.gitea/workflows/php8-almalinux.yaml @@ -7,7 +7,7 @@ on: jobs: build: - name: Build PHP 8 container images + name: Build php8-almalinux runs-on: ubuntu-latest container: image: ghcr.io/catthehacker/ubuntu:act-latest @@ -18,6 +18,7 @@ jobs: os_version: "9.5" php_version: "8.4" composer_version: "2.8.9" + latest: 'true' steps: - name: Check out repository code uses: actions/checkout@v4 @@ -29,7 +30,8 @@ jobs: password: ${{ secrets.QUAY_SECRET }} - name: Setup Docker buildx uses: docker/setup-buildx-action@v3 - - name: Build and push php ${{ matrix.flavors.php_version }} + - if: ${{ matrix.flavors.latest != 'true' }} + name: Build and push php ${{ matrix.flavors.php_version }} uses: docker/build-push-action@v5 with: push: true @@ -41,34 +43,18 @@ jobs: COMPOSER_VERSION=${{ matrix.flavors.composer_version }} tags: | quay.io/teras/php:${{ matrix.flavors.php_version }} - build-latest: - name: Build PHP 8 container images - runs-on: ubuntu-latest - needs: - - build - container: - image: ghcr.io/catthehacker/ubuntu:act-latest - steps: - - name: Check out repository code - uses: actions/checkout@v4 - - name: Login to quay.io - uses: docker/login-action@v3 - with: - registry: quay.io - username: ${{ vars.QUAY_USERNAME }} - password: ${{ secrets.QUAY_SECRET }} - - name: Setup Docker buildx - uses: docker/setup-buildx-action@v3 - - name: Build and push php8 latest + - if: ${{ matrix.flavors.latest == 'true' }} + name: Build and push php ${{ matrix.flavors.php_version }} uses: docker/build-push-action@v5 with: push: true context: . - file: 8/Dockerfile.almalinux + file: 8/Dockerfile.${{ matrix.flavors.os }} build-args: | - OS_VERSION=9.5 - PHP_VERSION=8.4 - COMPOSER_VERSION=2.8.9 + OS_VERSION=${{ matrix.flavors.os_version }} + PHP_VERSION=${{ matrix.flavors.php_version }} + COMPOSER_VERSION=${{ matrix.flavors.composer_version }} tags: | + quay.io/teras/php:${{ matrix.flavors.php_version }} quay.io/teras/php:8 quay.io/teras/php:latest From 89a96c6b2c35fedc2ad1366bc582cdb209a1afe3 Mon Sep 17 00:00:00 2001 From: Muhamad Aditya Prima Date: Tue, 20 May 2025 16:40:16 +0700 Subject: [PATCH 3/3] Added php 8.0 to 8.3 versions --- .gitea/workflows/php8-almalinux.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.gitea/workflows/php8-almalinux.yaml b/.gitea/workflows/php8-almalinux.yaml index 3f6c506..28f8091 100644 --- a/.gitea/workflows/php8-almalinux.yaml +++ b/.gitea/workflows/php8-almalinux.yaml @@ -14,6 +14,22 @@ jobs: strategy: matrix: flavors: + - os: "almalinux" + os_version: "9.5" + php_version: "8.0" + composer_version: "2.8.9" + - os: "almalinux" + os_version: "9.5" + php_version: "8.1" + composer_version: "2.8.9" + - os: "almalinux" + os_version: "9.5" + php_version: "8.2" + composer_version: "2.8.9" + - os: "almalinux" + os_version: "9.5" + php_version: "8.3" + composer_version: "2.8.9" - os: "almalinux" os_version: "9.5" php_version: "8.4"