From c0b5880ae1067710f718ea8e92e78262b8e9506d Mon Sep 17 00:00:00 2001 From: augushong Date: Sun, 7 Apr 2024 13:47:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0docker=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=9B=E4=BF=AE=E5=A4=8D=E9=87=8D=E7=BD=AE=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E9=94=99=E8=AF=AF=EF=BC=9B=E4=BC=98=E5=8C=96timer=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E6=9C=BA=E5=88=B6=E6=94=AF=E6=8C=81=E6=9C=AC=E5=9C=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 67 +++++++++++++++++++ README.md | 3 + docker/nginx.conf | 30 +++++++++ docker/phprun.ini | 11 +++ docker/run.sh | 21 ++++++ .../admin/service/AdminUpdateServiceBase.php | 3 +- extend/base/common/command/TimerBase.php | 18 +++-- .../controller/timer/ResetPasswordBase.php | 2 +- 8 files changed, 147 insertions(+), 8 deletions(-) create mode 100644 Dockerfile create mode 100644 docker/nginx.conf create mode 100644 docker/phprun.ini create mode 100644 docker/run.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..53fa7e0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,67 @@ +# 基于官方 PHP 8.0 镜像 +FROM php:8.0-fpm + +# RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list +# RUN sed -i 's/security.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list + +RUN apt-get update + +# 安装nginx +RUN apt-get install -y nginx + +# 安装ffmpeg +RUN apt-get install -y ffmpeg + +# 安装redis +RUN apt-get install -y redis-server + +# 安装PHP扩展 zip +RUN apt-get install -y libzip-dev \ + && docker-php-ext-install zip + +# 安装PHP扩展 mysql +RUN docker-php-ext-install mysqli pdo_mysql + +# 安装PHP扩展 exif +RUN docker-php-ext-install exif + +# 安装PHP扩展 imagemagick +RUN apt-get install -y libmagickwand-dev \ + && pecl install imagick \ + && docker-php-ext-enable imagick + +# 安装PHP扩展 redis +RUN pecl install redis \ + && docker-php-ext-enable redis + +# 安装PHP扩展 opcache +RUN docker-php-ext-install opcache + +# 清理默认 Nginx 配置 +RUN rm /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default + +# 设置工作目录 +WORKDIR /var/www/html + +# 将当前目录下的文件拷贝到工作目录 +COPY . /var/www/html + +# 创建runtime目录 +RUN mkdir /var/www/html/runtime + +# 设置runtime目录权限为777 +RUN chmod -R 777 /var/www/html/runtime + +# 创建持久化存储目录 +VOLUME /var/www/html/runtime + +# 暴露 Nginx 端口 +EXPOSE 80 + +# +RUN chmod +x /var/www/html/docker/run.sh + +# 启动 Nginx PHP 然后阻塞 +CMD /var/www/html/docker/run.sh + + diff --git a/README.md b/README.md index 7aae521..af9914d 100644 --- a/README.md +++ b/README.md @@ -233,3 +233,6 @@ vscode中liveSassCompiler的配置: ] } ``` + +### docker +内置了docker打包命令,打包出的镜像支持两种调用方法 \ No newline at end of file diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 0000000..567c883 --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,30 @@ + +server { + listen 80 default_server; + listen [::]:80 default_server; + + root /var/www/html/public; + index index.php index.html index.htm; + + server_name _; + + # 上传大小不限制 + client_max_body_size 8192m; + + # 运行时长不限制 + fastcgi_read_timeout 60000; + + location / { + if (!-e $request_filename) { + rewrite ^(.*)$ /index.php?s=$1 last; break; + } + + } + + location ~ \.php$ { + include fastcgi_params; + fastcgi_pass 127.0.0.1:9000; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + } +} diff --git a/docker/phprun.ini b/docker/phprun.ini new file mode 100644 index 0000000..d3e2186 --- /dev/null +++ b/docker/phprun.ini @@ -0,0 +1,11 @@ +; 内存不限制 +memory_limit = -1 + +; 上传文件大小不限制 +upload_max_filesize = -1 + +; 运行时长不限制 +max_execution_time = 0 + +; POST大小不限制 +post_max_size = -1 diff --git a/docker/run.sh b/docker/run.sh new file mode 100644 index 0000000..bad314d --- /dev/null +++ b/docker/run.sh @@ -0,0 +1,21 @@ +# 将代码中的nginx复制到nginx配置文件中 +cp /var/www/html/docker/nginx.conf /etc/nginx/sites-available/default +ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default + +# 将代码中的php配置文件复制到php配置文件中 +cp /var/www/html/docker/phprun.ini /usr/local/etc/php/conf.d + +# 运行redis +nohup redis-server --requirepass "" & +# 运行定时任务 +nohup php /var/www/html/think timer --local & + +# 如果第一个参数是server,或者没有参数,则运行server +if [ "$1" = "server" ] || [ "$1" = "" ]; then + # 运行nginx + service nginx start + # 运行php-fpm + php-fpm +else +php "/var/www/html/""$@" +fi diff --git a/extend/base/admin/service/AdminUpdateServiceBase.php b/extend/base/admin/service/AdminUpdateServiceBase.php index 9d19b95..92f2d86 100644 --- a/extend/base/admin/service/AdminUpdateServiceBase.php +++ b/extend/base/admin/service/AdminUpdateServiceBase.php @@ -348,6 +348,7 @@ class AdminUpdateServiceBase 'app', 'config', 'route', + 'docker' ]; foreach ($optional_files_prefix as $prefix) { @@ -356,7 +357,7 @@ class AdminUpdateServiceBase } } - // 如果file_path不存在目录分隔符,则是可选更新的文件 + // 如果file_path不存在目录分隔符,则是可选更新的文件(根目录下的文件) if (strpos($file_path, '/') === false) { return true; } diff --git a/extend/base/common/command/TimerBase.php b/extend/base/common/command/TimerBase.php index 2a2546b..84ee468 100644 --- a/extend/base/common/command/TimerBase.php +++ b/extend/base/common/command/TimerBase.php @@ -21,6 +21,9 @@ class TimerBase extends Command $this->setName('timer') ->addOption('temp', null, Option::VALUE_NONE) ->addOption('quit', null, Option::VALUE_NONE) + ->addOption('local', null, Option::VALUE_NONE) + ->addOption('local-host', null, Option::VALUE_OPTIONAL, '本地域名','http://localhost') + ->addOption('local-port', null, Option::VALUE_OPTIONAL, '本地端口', '80') ->setDescription('内置秒级定时器'); } @@ -30,16 +33,23 @@ class TimerBase extends Command $output->writeln('start timer'); $site_domain = sysconfig('site', 'site_domain'); - if (empty($site_domain)) { $output->writeln('请前往后台设置站点域名(site_domain)配置项'); return; } $output->writeln('站点域名:' . $site_domain); + $host = $site_domain; + + if ($input->hasOption('local')) { + $host = $input->getOption('local-host') . ':' . $input->getOption('local-port'); + } $client = new Client([ - 'base_uri' => $site_domain, + 'base_uri' => $host, + 'headers' => [ + 'Host' => $site_domain, + ], 'verify' => false, ]); @@ -52,14 +62,12 @@ class TimerBase extends Command $config_item = static::initConfigItem($config_item); $name = $config_item['name']; - if ($name == 'http_demo' && !env('adminsystem.is_demo', false)) { continue; } $cache_key = 'timer_' . $name; $cache_tag = 'system_timer'; - $last_exec_time = Cache::get($cache_key, 0); if ($last_exec_time >= time() - $config_item['frequency']) { @@ -67,9 +75,7 @@ class TimerBase extends Command } Cache::tag($cache_tag)->set($cache_key, time()); - $type = $config_item['type']; - switch ($type) { case 'site': $output->writeln(date('Y-m-d H:i:s') . ': build site request async:' . $config_item['target']); diff --git a/extend/base/tools/controller/timer/ResetPasswordBase.php b/extend/base/tools/controller/timer/ResetPasswordBase.php index e47f6ce..81b035a 100644 --- a/extend/base/tools/controller/timer/ResetPasswordBase.php +++ b/extend/base/tools/controller/timer/ResetPasswordBase.php @@ -17,7 +17,7 @@ class ResetPasswordBase extends TimerController return $this->error('本功能只有在演示环境下在能使用', '', '/'); } - $output = Console::call('admin:resetPassword', [ + $output = Console::call('admin:reset:password', [ '--password=123456', ]);