Initial commit

This commit is contained in:
2025-10-28 01:39:22 +03:00
commit 8d1473935a
23 changed files with 870 additions and 0 deletions

56
api-v2/Dockerfile Normal file
View File

@@ -0,0 +1,56 @@
# Аналогично API v1, кастомизация под v2 при необходимости
FROM debian:bookworm-slim
LABEL maintainer="your-email@example.com"
LABEL version="1.0"
LABEL description="PHP-FPM container for API v2 with PostgreSQL and Memcached"
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
RUN apt-get update && apt-get install -y \
curl \
wget \
gnupg \
lsb-release \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg \
&& echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list
RUN apt-get update && apt-get install -y --no-install-recommends \
php8.2-fpm \
php8.2-cli \
php8.2-pgsql \
php8.2-memcached \
php8.2-curl \
php8.2-mbstring \
php8.2-xml \
php8.2-zip \
php8.2-gd \
php8.2-intl \
php8.2-bcmath \
php8.2-opcache \
postgresql-client \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN mkdir -p /var/log/php-fpm \
&& mkdir -p /var/run/php
COPY config/php-fpm.conf /etc/php/8.2/fpm/php-fpm.conf
COPY config/www.conf /etc/php/8.2/fpm/pool.d/www.conf
RUN groupadd -g 1001 www \
&& useradd -u 1001 -ms /bin/bash -g www www
WORKDIR /var/www/html
COPY . /var/www/html/
RUN chown -R www:www /var/www/html /var/log \
&& chmod -R 755 /var/www/html \
&& chmod -R 775 /var/log
EXPOSE 9000
CMD ["php-fpm8.2", "-F"]

View File

@@ -0,0 +1,4 @@
[global]
error_log = /var/log/php-fpm/v2-error.log
daemonize = no
include=/etc/php/8.2/fpm/pool.d/*.conf

27
api-v2/config/www.conf Normal file
View File

@@ -0,0 +1,27 @@
; Пул процессов для API v2
[www]
user = www
group = www
listen = 0.0.0.0:9000
listen.mode = 0660
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 5
clear_env = no
catch_workers_output = yes
php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/php-fpm/v2-error.log
php_admin_flag[log_errors] = on
; Метрики и пинг
pm.status_path = /status
ping.path = /ping
ping.response = pong
security.limit_extensions = .php .php3 .php4 .php5 .php7 .php8

45
api-v2/src/index.php Normal file
View File

@@ -0,0 +1,45 @@
<?php
/**
* API v2 Entry Point
* Docker Container: php-fpm-v2
* Endpoint: /api/v2/
*/
header('Content-Type: application/json');
try {
$pdo = new PDO(
"pgsql:host=" . getenv('DB_HOST') . ";dbname=api_v2",
getenv('DB_USER'),
getenv('DB_PASS')
);
$db_status = "connected";
} catch (PDOException $e) {
$db_status = "error: " . $e->getMessage();
}
try {
$memcached = new Memcached();
$memcached->addServer(getenv('MEMCACHED_HOST'), 11211);
$memcached_status = $memcached->set('test_key_v2', 'test_value', 10) ? "connected" : "error";
} catch (Exception $e) {
$memcached_status = "error: " . $e->getMessage();
}
$response = [
'api_version' => 'v2',
'status' => 'success',
'timestamp' => time(),
'services' => [
'postgresql' => $db_status,
'memcached' => $memcached_status,
],
'container' => gethostname(),
'php_version' => PHP_VERSION,
'features' => [
'advanced_caching',
'extended_metrics'
]
];
echo json_encode($response, JSON_PRETTY_PRINT);