From 3a1c4be815ac13130cabeba9c9237358bffb409a Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Sun, 8 Dec 2024 21:56:27 +0700 Subject: [PATCH] feat: create php 8.4 image --- .github/workflows/php84-docker-public.yml | 104 ++++++++++++++++++++++ php84/Dockerfile | 39 ++++++++ php84/cslant.php.ini | 10 +++ php84/cslant.pool.conf | 74 +++++++++++++++ 4 files changed, 227 insertions(+) create mode 100644 .github/workflows/php84-docker-public.yml create mode 100644 php84/Dockerfile create mode 100644 php84/cslant.php.ini create mode 100644 php84/cslant.pool.conf diff --git a/.github/workflows/php84-docker-public.yml b/.github/workflows/php84-docker-public.yml new file mode 100644 index 0000000..c247676 --- /dev/null +++ b/.github/workflows/php84-docker-public.yml @@ -0,0 +1,104 @@ +name: Publish PHP84 image to Docker Hub + +on: + push: + branches: + - main + +permissions: + contents: write + +env: + IMAGE_NAME: dev-php84 + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} + DOCKERHUB_ID: ${{ secrets.DOCKERHUB_ID }} + +jobs: + push_to_registry: + if: github.event_name != 'pull_request' + name: Build and push PHP84 image + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log into Docker Hub + uses: docker/login-action@v3 + with: + registry: https://index.docker.io/v1/ + username: ${{ env.DOCKERHUB_USERNAME }} + password: ${{ env.DOCKERHUB_PASSWORD }} + + - name: Get latest version tag + id: get_version + run: | + git fetch --tags + # get the latest tag with regex pattern have vphp84 prefix + latest_tag=$(git tag -l | grep -E '^vphp84' | sort -V | tail -n 1) + echo "Latest tag: $latest_tag" + echo "version=$latest_tag" >> $GITHUB_OUTPUT + + - name: Increment version number + id: inc_version + run: | + version=${{ steps.get_version.outputs.version }} + version=${version#"v"} + if [ -z "$version" ]; then + major=0 + minor=0 + patch=0 + else + IFS='.' read -r -a parts <<< "$version" + major=${parts[0]:-0} + minor=${parts[1]:-0} + patch=${parts[2]:-0} + fi + patch=$((patch+1)) + if [ "$patch" -ge 100 ]; then + patch=0 + minor=$((minor+1)) + fi + if [ "$minor" -ge 10]; then + minor=0 + major=$((major+1)) + fi + new_version="v$major.$minor.$patch" + echo "New version: $new_version" + echo "new_version=$new_version" >> $GITHUB_OUTPUT + + - name: Set new version tag + run: | + git tag ${{ steps.inc_version.outputs.new_version }} + git push origin ${{ steps.inc_version.outputs.new_version }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.DOCKERHUB_ID }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=tag + type=semver,pattern={{version}} + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} + type=raw,value=${{ steps.inc_version.outputs.new_version }} + + - name: Build and push PHP84 image + id: build-and-push + uses: docker/build-push-action@v6 + with: + context: php84 + push: true + tags: | + ${{ env.DOCKERHUB_ID }}/${{ env.IMAGE_NAME }}:latest + ${{ env.DOCKERHUB_ID }}/${{ env.IMAGE_NAME }}:${{ steps.inc_version.outputs.new_version }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + PHP_VERSION=8.4 + USER_ID=1000 + GROUP_ID=1000 + PHP_VERSION_SHORT=84 diff --git a/php84/Dockerfile b/php84/Dockerfile new file mode 100644 index 0000000..8817ce8 --- /dev/null +++ b/php84/Dockerfile @@ -0,0 +1,39 @@ +ARG PHP_VERSION=8.4 + +FROM php:${PHP_VERSION}-fpm-alpine +LABEL maintainer="Tan Nguyen " +LABEL authors="cslant" +LABEL description="PHP image for CSlant development" + +## Make php ini +RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" + +## Install composer +RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \ + && php composer-setup.php \ + && mv composer.phar /usr/local/bin/composer + +## Config user +ARG USER_ID=1000 +ENV USER_ID=${USER_ID} +ARG GROUP_ID=1000 +ENV GROUP_ID=${GROUP_ID} + +# ensure www-data user exists +RUN set -eu; \ + addgroup -g ${USER_ID} csdev; \ + adduser -D -u ${USER_ID} -G csdev csdev + +ADD cslant.php.ini "$PHP_INI_DIR/conf.d/cslant.ini" +ADD cslant.pool.conf /usr/local/etc/php-fpm.d/www.conf + +# Default workdir +WORKDIR /var/dev + +## Install Ext +ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ +RUN install-php-extensions soap pcntl bcmath gd exif sockets zip xdebug redis intl pdo_pgsql pgsql pdo_mysql mysqli + +USER csdev + +CMD ["php-fpm"] diff --git a/php84/cslant.php.ini b/php84/cslant.php.ini new file mode 100644 index 0000000..83e5a85 --- /dev/null +++ b/php84/cslant.php.ini @@ -0,0 +1,10 @@ +date.timezone=Asia/Ho_Chi_Minh +display_errors=Off +log_errors=On + +memory_limit = 256M +upload_max_filesize = 20M +post_max_size = 20M +max_execution_time=600 +default_socket_timeout=3600 +request_terminate_timeout=600 diff --git a/php84/cslant.pool.conf b/php84/cslant.pool.conf new file mode 100644 index 0000000..39f8265 --- /dev/null +++ b/php84/cslant.pool.conf @@ -0,0 +1,74 @@ +; Start a new pool named 'www'. +; the variable $pool can be used in any directive and will be replaced by the +; pool name ('www' here) +[www] + +; Unix user/group of processes +; Note: The user is mandatory. If the group is not set, the default user's group +; will be used. +user = csdev +group = csdev + +; The address on which to accept FastCGI requests. +; Valid syntaxes are: +; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on +; a specific port; +; 'port' - to listen on a TCP socket to all addresses on a +; specific port; +; '/path/to/unix/socket' - to listen on a unix socket. +; Note: This value is mandatory. +listen = 0.0.0.0:9000 + +; Choose how the process manager will control the number of child processes. +; Possible Values: +; static - a fixed number (pm.max_children) of child processes; +; dynamic - the number of child processes are set dynamically based on the +; following directives. With this process management, there will be +; always at least 1 children. +; pm.max_children - the maximum number of children that can +; be alive at the same time. +; pm.start_servers - the number of children created on startup. +; pm.min_spare_servers - the minimum number of children in 'idle' +; state (waiting to process). If the number +; of 'idle' processes is less than this +; number then some children will be created. +; pm.max_spare_servers - the maximum number of children in 'idle' +; state (waiting to process). If the number +; of 'idle' processes is greater than this +; number then some children will be killed. +; ondemand - no children are created at startup. Children will be forked when +; new requests will connect. The following parameter are used: +; pm.max_children - the maximum number of children that +; can be alive at the same time. +; pm.process_idle_timeout - The number of seconds after which +; an idle process will be killed. +; Note: This value is mandatory. +pm = dynamic + +; The number of child processes to be created when pm is set to 'static' and the +; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. +; This value sets the limit on the number of simultaneous requests that will be +; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. +; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP +; CGI. The below defaults are based on a server without much resources. Don't +; forget to tweak pm.* to fit your needs. +; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' +; Note: This value is mandatory. +pm.max_children = 20 + +; The number of child processes created on startup. +; Note: Used only when pm is set to 'dynamic' +; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 +pm.start_servers = 2 + +; The desired minimum number of idle server processes. +; Note: Used only when pm is set to 'dynamic' +; Note: Mandatory when pm is set to 'dynamic' +pm.min_spare_servers = 1 + +; The desired maximum number of idle server processes. +; Note: Used only when pm is set to 'dynamic' +; Note: Mandatory when pm is set to 'dynamic' +pm.max_spare_servers = 3 + +catch_workers_output = yes