This commit is contained in:
feng0207
2026-08-11 22:22:10 +08:00
commit 5e312c1266
6985 changed files with 1061169 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
ARG PHP_BASE_IMAGE=php:7.4-cli
ARG COMPOSER_IMAGE=composer:latest
FROM ${PHP_BASE_IMAGE}
RUN set -eux; \
apt-get update && apt-get install -y --no-install-recommends \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libzip-dev \
libssl-dev \
unzip \
git \
default-mysql-client \
; \
docker-php-ext-configure gd --with-freetype --with-jpeg; \
docker-php-ext-install -j$(nproc) gd pdo_mysql bcmath zip pcntl; \
pecl install redis-5.3.7; \
docker-php-ext-enable redis; \
pecl install swoole-4.8.11; \
docker-php-ext-enable swoole; \
rm -rf /var/lib/apt/lists/* /tmp/pear
COPY --from=${COMPOSER_IMAGE} /usr/bin/composer /usr/bin/composer
WORKDIR /var/www/html
COPY swoole.php /tmp/swoole_docker.php
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
EXPOSE 20108
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
+62
View File
@@ -0,0 +1,62 @@
#!/bin/bash
set -e
echo "==> Copying Docker swoole config..."
cp /tmp/swoole_docker.php /var/www/html/config/swoole.php
echo "==> Generating .env from environment variables..."
cat > /var/www/html/.env << ENVEOF
APP_DEBUG = true
APP_KEY = "base64:t6/NqsDlNuYSLcdgx//oSVIVBjtRCMa2D6k35Jizla4="
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
[DATABASE]
TYPE = mysql
HOSTNAME = ${DB_HOSTNAME:-mysql}
DATABASE = ${DB_DATABASE:-crmeb_chat}
USERNAME = ${DB_USERNAME:-root}
PASSWORD = ${DB_PASSWORD:-root}
HOSTPORT = ${DB_PORT:-3306}
CHARSET = utf8
DEBUG = true
[LANG]
default_lang = zh-cn
[REDIS]
REDIS_HOSTNAME = ${REDIS_HOSTNAME:-redis}
PORT = ${REDIS_PORT:-6379}
REDIS_PASSWORD = ${REDIS_PASSWORD:-}
SELECT = 0
ENVEOF
echo "==> Waiting for MySQL..."
until mysqladmin ping -h "${DB_HOSTNAME:-mysql}" -u "${DB_USERNAME:-root}" -p"${DB_PASSWORD:-root}" --silent 2>/dev/null; do
echo " MySQL not ready, retrying..."
sleep 2
done
echo " MySQL is ready!"
echo "==> Importing database schema..."
mysql -h "${DB_HOSTNAME:-mysql}" -u "${DB_USERNAME:-root}" -p"${DB_PASSWORD:-root}" --default-character-set=utf8mb4 "${DB_DATABASE:-crmeb_chat}" < /var/www/html/public/install/crmeb_clean.sql 2>/dev/null && \
echo " Database schema imported." || \
echo " Database may already be initialized (ignoring errors)."
echo "==> Skipping install wizard..."
touch /var/www/html/public/install/install.lock
echo "==> Installing composer dependencies..."
cd /var/www/html
if [ ! -f vendor/autoload.php ]; then
composer install --no-interaction --no-dev --optimize-autoloader
else
echo " Vendors already installed."
fi
echo "==> Cleaning old Swoole PID files..."
rm -f /var/www/html/runtime/swoole.pid /var/www/html/runtime/swoole.log
echo "==> Starting Swoole HTTP server on 0.0.0.0:${SWOOLE_PORT:-20108}..."
exec php think swoole start
+106
View File
@@ -0,0 +1,106 @@
<?php
use app\webscoket\Manager;
use Swoole\Table;
use think\swoole\websocket\socketio\Parser;
return [
'server' => [
'host' => env('SWOOLE_HOST', '0.0.0.0'),
'port' => env('SWOOLE_PORT', 20108),
'mode' => SWOOLE_PROCESS,
'sock_type' => SWOOLE_SOCK_TCP,
'options' => [
'pid_file' => runtime_path() . 'swoole.pid',
'log_file' => runtime_path() . 'swoole.log',
'daemonize' => false,
'reactor_num' => swoole_cpu_num() * 2,
'worker_num' => swoole_cpu_num() * 2,
'task_worker_num' => swoole_cpu_num() * 2,
'task_enable_coroutine' => true,
'enable_static_handler' => true,
'document_root' => root_path('public'),
'package_max_length' => 20 * 1024 * 1024,
'buffer_output_size' => 10 * 1024 * 1024,
'socket_buffer_size' => 128 * 1024 * 1024,
],
],
'websocket' => [
'enable' => true,
'handler' => Manager::class,
'parser' => Parser::class,
'ping_interval' => 25000,
'ping_timeout' => 60000,
'room' => [
'type' => 'table',
'table' => [
'room_rows' => 4096,
'room_size' => 2048,
'client_rows' => 8192,
'client_size' => 2048,
],
'redis' => [
'host' => '127.0.0.1',
'port' => 6379,
'max_active' => 10,
'max_wait_time' => 5,
],
],
'listen' => [],
'subscribe' => [],
],
'rpc' => [
'server' => [
'enable' => false,
'port' => 9000,
'services' => [],
],
'client' => [],
],
'hot_update' => [
'enable' => env('APP_DEBUG', false),
'name' => ['*.php'],
'include' => [app_path(), root_path('crmeb')],
'exclude' => [],
],
'pool' => [
'db' => [
'enable' => true,
'max_active' => 3,
'max_wait_time' => 5,
],
'cache' => [
'enable' => true,
'max_active' => 3,
'max_wait_time' => 5,
],
],
'coroutine' => [
'enable' => false,
'flags' => SWOOLE_HOOK_ALL | SWOOLE_HOOK_CURL,
],
'tables' => [
'user' => [
'size' => 2048 * 50,
'columns' => [
['name' => 'fd', 'type' => Table::TYPE_INT],
['name' => 'type', 'size' => 1024, 'type' => Table::TYPE_STRING],
['name' => 'user_id', 'type' => Table::TYPE_INT],
['name' => 'to_user_id', 'type' => Table::TYPE_INT],
['name' => 'tourist', 'type' => Table::TYPE_INT],
['name' => 'is_open', 'type' => Table::TYPE_INT],
['name' => 'appid', 'size' => 1024, 'type' => Table::TYPE_STRING],
]
]
],
'queue' => [
'enable' => true,
'workers' => [
'CRMEB_CHAT' => [],
],
],
'concretes' => [],
'resetters' => [],
'instances' => [],
'services' => [],
];