diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e69195da..9afadc96 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -245,6 +245,58 @@ jobs: run: | ! $BLUEPRINT_DOCKER $CMD_VALIDATE $INVALID_TEST + - name: Prepare Benchmark + run: | + make build --no-print-directory + make bench-create-csv --no-print-directory + + - name: 🔥 Benchmark + run: | + ! make bench-docker-quick --no-print-directory + + - name: Push Docker Image (master) + uses: docker/build-push-action@v5 + if: github.ref == 'refs/heads/master' + with: + context: . + push: true + tags: jbzoo/csv-blueprint:master + + + verify-docker-zts: + name: Verify Docker ZTS + runs-on: ubuntu-latest + env: + BENCH_COLS: 1 + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.ref }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: 🐳 Building Docker Image + uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile.zts + push: false + tags: jbzoo/csv-blueprint:local + + - name: 🎨 Test help and logo + run: $BLUEPRINT_DOCKER --ansi -vvv + - name: 👍 Valid CSV files (Parallel) run: $BLUEPRINT_DOCKER $CMD_VALIDATE $VALID_TEST --parallel @@ -265,13 +317,14 @@ jobs: run: | ! make bench-docker-quick-parallel --no-print-directory - - name: Push Docker Image (master) + - name: Push Docker Image (master-zts) uses: docker/build-push-action@v5 if: github.ref == 'refs/heads/master' with: context: . + file: Dockerfile.zts push: true - tags: jbzoo/csv-blueprint:master + tags: jbzoo/csv-blueprint:zts verify-ga: diff --git a/Dockerfile b/Dockerfile index b4aed754..75c9712b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,11 +17,11 @@ COPY . /tmp RUN make build-version ######################################################################################## -FROM php:8.3-zts-alpine +FROM php:8.3-cli-alpine # Install PHP extensions ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ -RUN install-php-extensions opcache parallel @composer +RUN install-php-extensions opcache @composer # Install application WORKDIR /app @@ -38,21 +38,13 @@ RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" COPY ./docker/php.ini /usr/local/etc/php/conf.d/docker-z99-php.ini # Warmup caches -RUN php ./docker/random-csv.php \ - && JBZOO_BUILD_PRELOADER=1 \ - ./csv-blueprint validate:csv \ - --schema=/app/schema-examples/full.yml \ - --csv=/app/docker/random_data.csv \ - --apply-all=yes \ - --report=text --mute-errors | grep issues \ - && rm ./docker/random_data.csv \ - && php ./docker/build-preloader.php \ +RUN OPCACHE_COMPILER=1 php ./docker/build-preloader.php \ && php ./docker/preload.php \ && du -sh /app/docker # && echo "opcache.preload=/app/docker/preload.php" >> /usr/local/etc/php/conf.d/docker-z99-php.ini + # Quick test RUN time ./csv-blueprint -V -ENTRYPOINT ["/app/docker/entrypoint.sh"] -#ENTRYPOINT ["/app/csv-blueprint"] +ENTRYPOINT ["/app/csv-blueprint"] diff --git a/Dockerfile.zts b/Dockerfile.zts new file mode 100644 index 00000000..1f0474e8 --- /dev/null +++ b/Dockerfile.zts @@ -0,0 +1,55 @@ +# +# JBZoo Toolbox - Csv-Blueprint. +# +# This file is part of the JBZoo Toolbox project. +# For the full copyright and license information, please view the LICENSE +# file that was distributed with this source code. +# +# @license MIT +# @copyright Copyright (C) JBZoo.com, All rights reserved. +# @see https://github.com/JBZoo/Csv-Blueprint +# + +FROM alpine:3.9 AS preparatory +RUN apk add --no-cache make git +WORKDIR /tmp +COPY . /tmp +RUN make build-version + +######################################################################################## +FROM php:8.3-zts-alpine + +# Install PHP extensions +ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ +RUN install-php-extensions opcache parallel @composer + +# Install application +WORKDIR /app +ENV COMPOSER_ALLOW_SUPERUSER=1 +COPY . /app +COPY --from=preparatory /tmp/.version /app/.version +RUN composer install --no-dev --classmap-authoritative --no-progress \ + && rm -rf ./.git \ + && composer clear-cache \ + && chmod +x ./csv-blueprint \ + && chmod +x ./docker/entrypoint.sh + +RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" +COPY ./docker/php.ini /usr/local/etc/php/conf.d/docker-z99-php.ini + +# Build custom autoloader for PHP ext-parallel +RUN php ./docker/random-csv.php \ + && JBZOO_BUILD_PRELOADER=1 \ + ./csv-blueprint validate:csv \ + --schema=/app/schema-examples/full.yml \ + --csv=/app/docker/random_data.csv \ + --apply-all=yes \ + --report=text --mute-errors | grep issues \ + && rm ./docker/random_data.csv \ + && php ./docker/build-preloader.php \ + && php ./docker/preload.php + +# Quick test +RUN time ./csv-blueprint -V + +ENTRYPOINT ["/app/docker/entrypoint.sh"] diff --git a/Makefile b/Makefile index 6a8a5525..697ed6a5 100644 --- a/Makefile +++ b/Makefile @@ -77,6 +77,10 @@ docker-build: ##@Docker (Re-)build Docker image $(call title,"Building Docker Image") @docker build -t $(DOCKER_IMAGE) --progress=plain . +docker-build-zts: ##@Docker (Re-)build Docker image with ZTS + $(call title,"Building Docker Image") + @docker build -t $(DOCKER_IMAGE)-zts -f Dockerfile.zts --progress=plain . + docker-demo: ##@Docker Run demo via Docker $(call title,"Demo - Valid CSV \(via Docker\)") @$(BLUEPRINT_DOCKER) $(VALID_CSV) $(VALID_SCHEMA) -vvv diff --git a/docker/build-preloader.php b/docker/build-preloader.php index 4d2bde89..61c41cc0 100644 --- a/docker/build-preloader.php +++ b/docker/build-preloader.php @@ -15,10 +15,11 @@ declare(strict_types=1); use JBZoo\CsvBlueprint\Tools\PreloadBuilder; +use JBZoo\Utils\Env; require_once __DIR__ . '/../vendor/autoload.php'; -(new PreloadBuilder(enableOpcacheCompiler: false)) +(new PreloadBuilder(Env::bool('OPCACHE_COMPILER'))) ->setExcludes([ \dirname(__DIR__) . '/csv-blueprint', \dirname(__DIR__) . '/csv-blueprint.php', diff --git a/docker/php.ini b/docker/php.ini index 6df2cbe2..3d3e52f9 100644 --- a/docker/php.ini +++ b/docker/php.ini @@ -20,7 +20,7 @@ opcache.max_accelerated_files = 10000 opcache.fast_shutdown = 1 opcache.save_comments = 1 opcache.jit_buffer_size = 100M -opcache.jit = tracing +opcache.jit = 1255 opcache.memory_consumption = 200 @@ -32,6 +32,7 @@ opcache.memory_consumption = 200 ;opcache.file_cache = /app/docker/ ;opcache.file_cache_only = 1 + ; Enable aggressive opcache optimization opcache.use_cwd = 0 opcache.validate_root = 0 diff --git a/src/Commands/AbstractValidate.php b/src/Commands/AbstractValidate.php index d093cb09..a7aa3b59 100644 --- a/src/Commands/AbstractValidate.php +++ b/src/Commands/AbstractValidate.php @@ -103,11 +103,15 @@ protected function preparation(): void $threads = $this->getNumberOfThreads(); if ($threads !== 1) { - $this->_( - $threads > 0 - ? "Parallel mode: {$threads} threads" - : 'Parallel mode: ' . WorkerPool::getCpuCount() . ' threads (auto)', - ); + if (WorkerPool::extLoaded()) { + $this->_( + $threads > 0 + ? "Parallel mode: {$threads} threads" + : 'Parallel mode: ' . WorkerPool::getCpuCount() . ' threads (auto)', + ); + } else { + $this->_('Parallel mode: Not available. Please, see docs.'); + } } Utils::setDebugMode($this->getOptBool('debug'));