Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Dockerfile.zts for PHP ZTS #166

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/#-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

Expand All @@ -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:
Expand Down
18 changes: 5 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
55 changes: 55 additions & 0 deletions Dockerfile.zts
Original file line number Diff line number Diff line change
@@ -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"]
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion docker/build-preloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion docker/php.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
14 changes: 9 additions & 5 deletions src/Commands/AbstractValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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: <yellow>Not available</yellow>. Please, see docs.');
}
}

Utils::setDebugMode($this->getOptBool('debug'));
Expand Down