From 9716d7fe43378395b378825545e28c0f7ea78640 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Fri, 21 Mar 2025 10:51:40 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96docker=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.docker | 4 +- app/Http/Controllers/Api/FileController.php | 2 +- app/Http/Controllers/Api/SystemController.php | 2 +- app/Http/Controllers/IndexController.php | 2 +- app/Models/UserCheckinFace.php | 4 +- .../ElasticSearch/ElasticSearchBase.php | 2 +- app/Tasks/BotReceiveMsgTask.php | 2 +- cmd | 31 ++++---------- docker-compose.yml | 40 ++++++++----------- 9 files changed, 32 insertions(+), 57 deletions(-) diff --git a/.env.docker b/.env.docker index daeb892fa..36ff4ef59 100644 --- a/.env.docker +++ b/.env.docker @@ -17,7 +17,7 @@ LOG_CHANNEL=stack LOG_LEVEL=debug DB_CONNECTION=mysql -DB_HOST="${APP_IPPR}.5" +DB_HOST=mariadb DB_PORT=3306 DB_DATABASE=dootask DB_USERNAME=dootask @@ -34,7 +34,7 @@ SESSION_LIFETIME=120 MEMCACHED_HOST=127.0.0.1 -REDIS_HOST="${APP_IPPR}.4" +REDIS_HOST=redis REDIS_PASSWORD=null REDIS_PORT=6379 diff --git a/app/Http/Controllers/Api/FileController.php b/app/Http/Controllers/Api/FileController.php index f244ebef6..cbb00a39b 100755 --- a/app/Http/Controllers/Api/FileController.php +++ b/app/Http/Controllers/Api/FileController.php @@ -666,7 +666,7 @@ class FileController extends AbstractController // if ($status === 2) { $parse = parse_url($url); - $from = 'http://' . env('APP_IPPR') . '.3' . $parse['path'] . '?' . $parse['query']; + $from = 'http://nginx' . $parse['path'] . '?' . $parse['query']; $path = 'uploads/file/' . $file->type . '/' . date("Ym") . '/' . $file->id . '/' . $key; $save = public_path($path); Base::makeDir(dirname($save)); diff --git a/app/Http/Controllers/Api/SystemController.php b/app/Http/Controllers/Api/SystemController.php index 7c37b09d7..bc6c31663 100755 --- a/app/Http/Controllers/Api/SystemController.php +++ b/app/Http/Controllers/Api/SystemController.php @@ -1510,7 +1510,7 @@ class SystemController extends AbstractController } // 添加office资源 $officePath = ''; - $officeApi = 'http://' . env('APP_IPPR') . '.6/web-apps/apps/api/documents/api.js'; + $officeApi = 'http://office/web-apps/apps/api/documents/api.js'; $content = @file_get_contents($officeApi); if ($content) { if (preg_match("/const\s+ver\s*=\s*'\/*([^']+)'/", $content, $matches)) { diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index 5ec4e0e24..b0c4d44a2 100755 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -493,7 +493,7 @@ class IndexController extends InvokeController if (in_array($ext, File::localExt)) { $url = Base::fillUrl($path); } else { - $url = 'http://' . env('APP_IPPR') . '.3/' . $path; + $url = 'http://nginx/' . $path; } $url = Base::urlAddparameter($url, [ 'fullfilename' => Base::rightDelete($name, '.' . $ext) . '_' . filemtime($file) . '.' . $ext diff --git a/app/Models/UserCheckinFace.php b/app/Models/UserCheckinFace.php index b97709150..1fc2d0b97 100644 --- a/app/Models/UserCheckinFace.php +++ b/app/Models/UserCheckinFace.php @@ -47,7 +47,7 @@ class UserCheckinFace extends AbstractModel $record = base64_encode(file_get_contents($faceFile)); } - $url = 'http://' . env('APP_IPPR') . '.14' . ":7788/user"; + $url = "http://face:7788/user"; $data = [ 'name' => $nickname, 'enrollid' => $userid, @@ -92,7 +92,7 @@ class UserCheckinFace extends AbstractModel } public static function deleteDeviceUser($userid) { - $url = 'http://' . env('APP_IPPR') . '.14' . ":7788/user/delete"; + $url = "http://face:7788/user/delete"; $data = [ 'enrollid' => $userid, 'backupnum' => 50, // 13 删除整个用户 50 删除图片 diff --git a/app/Module/ElasticSearch/ElasticSearchBase.php b/app/Module/ElasticSearch/ElasticSearchBase.php index 61301b6fd..21e67cdb7 100644 --- a/app/Module/ElasticSearch/ElasticSearchBase.php +++ b/app/Module/ElasticSearch/ElasticSearchBase.php @@ -36,7 +36,7 @@ class ElasticSearchBase */ public function __construct($index = null) { - $host = env('ELASTICSEARCH_HOST', env('APP_IPPR') . '.15'); + $host = env('ELASTICSEARCH_HOST', 'es'); $port = env('ELASTICSEARCH_PORT', '9200'); $scheme = env('ELASTICSEARCH_SCHEME', 'http'); $user = env('ELASTICSEARCH_USER', ''); diff --git a/app/Tasks/BotReceiveMsgTask.php b/app/Tasks/BotReceiveMsgTask.php index 4edc38dd6..023641bf6 100644 --- a/app/Tasks/BotReceiveMsgTask.php +++ b/app/Tasks/BotReceiveMsgTask.php @@ -424,7 +424,7 @@ class BotReceiveMsgTask extends AbstractTask */ private function botWebhookBusiness(string $command, WebSocketDialogMsg $msg, User $botUser, WebSocketDialog $dialog) { - $serverUrl = 'http://' . env('APP_IPPR') . '.3'; + $serverUrl = 'http://nginx'; $userBot = null; $extras = []; $errorContent = null; diff --git a/cmd b/cmd index 92b3b0dc1..e5ac425df 100755 --- a/cmd +++ b/cmd @@ -463,7 +463,7 @@ if [ $# -gt 0 ]; then # 启动容器 [[ "$(arg_get port)" -gt 0 ]] && env_set APP_PORT "$(arg_get port)" $COMPOSE up php -d - # 安装composer依赖 + # 安装PHP依赖 run_exec php "composer install" if [ ! -f "${cur_path}/vendor/autoload.php" ]; then run_exec php "composer config repo.packagist composer https://packagist.phpcomposer.com" @@ -475,32 +475,15 @@ if [ $# -gt 0 ]; then exit 1 fi [[ -z "$(env_get APP_KEY)" ]] && run_exec php "php artisan key:generate" + # 设置生产模式 switch_debug "false" - # 检查数据库 - remaining=10 - while [ ! -f "${cur_path}/docker/mysql/data/$(env_get DB_DATABASE)/db.opt" ]; do - ((remaining=$remaining-1)) - if [ $remaining -lt 0 ]; then - error "数据库初始化失败!" - exit 1 - fi - sleep 3 - done # 数据库迁移 - remaining=10 - while [ ! -f "${cur_path}/docker/mysql/data/$(env_get DB_DATABASE)/$(env_get DB_PREFIX)migrations.ibd" ]; do - ((remaining=$remaining-1)) - if [ $remaining -lt 0 ]; then - error "数据库安装失败!" - exit 1 - fi - sleep 3 - run_exec php "php artisan migrate --seed" - done - # 设置初始化密码 + run_exec php "php artisan migrate --seed" + # 启动其他容器 $COMPOSE up -d success "安装完成" info "地址: http://${GreenBG}127.0.0.1:$(env_get APP_PORT)${Font}" + # 设置初始化密码 run_exec mariadb "sh /etc/mysql/repassword.sh" elif [[ "$1" == "update" ]]; then shift 1 @@ -594,9 +577,9 @@ if [ $# -gt 0 ]; then elif [[ "$1" == "npm" ]]; then shift 1 npm $@ - cd electron + pushd electron || exit npm $@ - cd .. + popd || exit docker run --rm -it -v ${cur_path}/resources/mobile:/work -w /work --entrypoint=/bin/bash node:16 -c "npm $@" elif [[ "$1" == "doc" ]]; then shift 1 diff --git a/docker-compose.yml b/docker-compose.yml index 78a8f610d..73872745b 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,9 +25,10 @@ services: extnetwork: ipv4_address: "${APP_IPPR}.2" depends_on: - - mariadb - - redis - - es + mariadb: + condition: service_healthy + redis: + condition: service_healthy restart: unless-stopped nginx: @@ -42,20 +43,16 @@ services: networks: extnetwork: ipv4_address: "${APP_IPPR}.3" - links: - - php - - office - - fileview - - drawio-webapp - - drawio-export - - minder - - okr - - ai restart: unless-stopped redis: container_name: "dootask-redis-${APP_ID}" image: "redis:alpine" + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 5s + timeout: 5s + retries: 5 networks: extnetwork: ipv4_address: "${APP_IPPR}.4" @@ -74,6 +71,11 @@ services: MYSQL_DATABASE: "${DB_DATABASE}" MYSQL_USER: "${DB_USERNAME}" MYSQL_PASSWORD: "${DB_PASSWORD}" + healthcheck: + test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "${DB_USERNAME}", "-p${DB_PASSWORD}"] + interval: 5s + timeout: 5s + retries: 5 networks: extnetwork: ipv4_address: "${APP_IPPR}.5" @@ -126,8 +128,6 @@ services: networks: extnetwork: ipv4_address: "${APP_IPPR}.8" - depends_on: - - drawio-export restart: unless-stopped drawio-export: @@ -164,8 +164,6 @@ services: networks: extnetwork: ipv4_address: "${APP_IPPR}.11" - depends_on: - - mariadb restart: unless-stopped ai: @@ -178,8 +176,6 @@ services: networks: extnetwork: ipv4_address: "${APP_IPPR}.12" - depends_on: - - redis restart: unless-stopped okr: @@ -187,7 +183,7 @@ services: image: "kuaifan/doookr:0.4.5" environment: TZ: "${TIMEZONE:-PRC}" - DOO_TASK_URL: "http://${APP_IPPR}.3" + DOO_TASK_URL: "http://nginx" MYSQL_HOST: "${DB_HOST}" MYSQL_PORT: "${DB_PORT}" MYSQL_DBNAME: "${DB_DATABASE}" @@ -199,8 +195,6 @@ services: networks: extnetwork: ipv4_address: "${APP_IPPR}.13" - depends_on: - - mariadb restart: unless-stopped face: @@ -217,9 +211,7 @@ services: MYSQL_PASSWORD: "${DB_PASSWORD}" MYSQL_DB_NAME: "${DB_DATABASE}" DB_PREFIX: "${DB_PREFIX}" - REPORT_API: "http://${APP_IPPR}.3:80/api/public/checkin/report" - depends_on: - - mariadb + REPORT_API: "http://nginx/api/public/checkin/report" networks: extnetwork: ipv4_address: "${APP_IPPR}.14"