Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

docker upgrade #1993

Merged
merged 9 commits into from
Jul 17, 2023
Merged

docker upgrade #1993

merged 9 commits into from
Jul 17, 2023

Conversation

xiagw
Copy link
Contributor

@xiagw xiagw commented Jul 17, 2023

  • auto upgrade with docker
  • fix file mode
  • fix file permission
  • add docker-coompose.yml

@star7th
Copy link
Owner

star7th commented Jul 17, 2023

docker-compose.yml 里的宿主机路径写错了。

关于 使用docker里的代码来升级旧代码,你的思路蛮好的,我知道你是想通过纯命令行来实现升级。我一开始也是这么想的,但是当时没这么做是觉得麻烦。

Dockerfile里的版本号,其实并不是showdoc真正的版本号。它应该说,只是docker这个运行环境的版本号,比如叫 2.4 。但showdoc代码程序的版本号已经去到3.2了,这个版本号写在 composer.json 文件的 version字段。
如果需要人为约定docker的版本号跟showdoc代码程序的版本号保持一致,也是可以的。人为规范一下不并不算多大问题。

这里更重要的是,更新的逻辑。

你应该能看到 ,我更新逻辑是写在了一个php脚本里 https://github.com/xiagw/showdoc/blob/docker-upgrade/server/Application/Api/Controller/UpdateController.class.php#L22
里面挺多逻辑是命令行更新没有考虑到或者说不好实现的。
你可以去看一下注释,几乎每个小逻辑我都写了注释是干嘛用的。比如,要先判断权限,要备份数据库,要修正语言设置。
尤其是修正语言设置。由于历史原因,语言设置是直接写死在html文件里的,所以要字符串替换。

@star7th
Copy link
Owner

star7th commented Jul 17, 2023

解释下为什么我说 docker-compose.yml 里的宿主机路径写错了。 宿主机路径,虽然说理论上是什么路径都行,但出于兼容历史的原因,我都统一写 /showdoc_data/html 。 这样的安装方式,还可以无缝复用官方的一键安装脚本来操作 https://www.showdoc.com.cn/help/828455960655160

@xiagw
Copy link
Contributor Author

xiagw commented Jul 17, 2023

如果要沟通这些东西的话,感觉有蛮多需要改的,包括你这些目录结构,架构问题,不过还是算了,没那么多时间搞,你若需要也可以慢慢来

  1. 其实用 /showdoc_data/ 这个并不是好主意,建议改为$HOME/showdoc_data/,这样更好的管理和权限控制
  2. Dockerfile 内版本号其实无所谓,只是检测变更不同 就会更新文件,改大改小都没关系
  3. 更新逻辑其实无所谓,不需要加关注,因为在docker 内是用 root 执行的,权限其实在 run.sh “## fix file permission”行开始已经全部fix 了
  4. 备份可用也可以不用,因为 rsync 时已经排除掉 db 文件,你若需要,可以加一行备份命令即可
  5. 语言建议最好是设置在 db 表内,
  6. 语言替换我可以再给你加一行命令

@xiagw
Copy link
Contributor Author

xiagw commented Jul 17, 2023

解释下为什么我说 docker-compose.yml 里的宿主机路径写错了。 宿主机路径,虽然说理论上是什么路径都行,但出于兼容历史的原因,我都统一写 /showdoc_data/html 。 这样的安装方式,还可以无缝复用官方的一键安装脚本来操作 https://www.showdoc.com.cn/help/828455960655160

建议路径变更一下,不要用这种非POSIX规范路径 /showdoc_data/
文档内指导一下用户 copy 文件,
或者 我给你加一个 判断 并copy 文件也是可以的。

@xiagw
Copy link
Contributor Author

xiagw commented Jul 17, 2023

假如结构调整的话,建议顶级只需三个文件夹即可。因为已经使用了 thinkphp。

  1. server/ (包含 thinkphp,public,web static 等 web 文件)
  2. mock/
  3. web_src/

install/ 置于 thinkphp/public
web/ 不需要提交,通过 docker 内多阶段构建 vue 把 static 文件置于 thinkphp/public
vendor 不需要提交,通过 docker 内多阶段构建 用 composer.json 文件安装即可,

@xiagw
Copy link
Contributor Author

xiagw commented Jul 17, 2023

thinkphp 版本太久,建议升级。

@star7th
Copy link
Owner

star7th commented Jul 17, 2023

当前的目录结构一直是我心病,想改掉好多年了。
不改的原因有:
1,历史上传的图片,其路径里已经包含了 public 路径。如更改的话,导致导致数据库路径以及附件路径都及时变更。也不算不能改,可能在数据库里把已上传的路径都修正应该会好些。这块有没有引起兼容问题,我得认真找个时间试试。
2,web/ 和 vendor 还是需要提交。因为要照顾非docker安装方式。不是所有开发者都会npm build的同时也会 composer ,showdoc现在大部分用户都不是php开发者了。
3,thinkphp 版本 现在无法升级了。一升级,全部写法都得变,还不如直接laravel重写。但是,这个laravel的版本有点激进,稍微新一点的版本,要求的php环境版本都很高。这就给 非docker安装方式 带来了麻烦。这也是我一直没下定决心升级的原因,即 要花费力气去重写,但是带来的好处不多,还可能会限制自己。
现在在用的thinkphp 版本 , 写法是落后点,但我魔改了下,已经能兼容到php8.1 ,而且来性能比laravel高一些。

@star7th
Copy link
Owner

star7th commented Jul 17, 2023

/showdoc_data/ 这个路径,暂时更改不了了。以前决定得太草率,以至于后面都要兼容历史

你再做两个改动吧,
一是,版本的更新 ,改为判断 composer.json这个文件里的version字段。先不用Dockerfile的版本号
二是增加语言字符串替换
这个语言,以后我再尝试更改机制到后台记录。

@xiagw
Copy link
Contributor Author

xiagw commented Jul 17, 2023

非 docker 安装也不需要,
首先你的安装脚本 showdoc 就是docker 安装,
只是要在 docker 里面增加 build 的步骤即可,把 npm 和 composer 放进去

@xiagw
Copy link
Contributor Author

xiagw commented Jul 17, 2023

/showdoc_data/ 这个路径,暂时更改不了了。以前决定得太草率,以至于后面都要兼容历史

你再做两个改动吧, 一是,版本的更新 ,改为判断 composer.json这个文件里的version字段。先不用Dockerfile的版本号 二是增加语言字符串替换 这个语言,以后我再尝试更改机制到后台记录。

语言字串 已经有了。

@star7th
Copy link
Owner

star7th commented Jul 17, 2023

我说一个场景吧,比如说那些只会用宝塔面板,把showdoc丢进php运行环境的那些人。我还是得把web/ 和 vendor 放上来的

@star7th
Copy link
Owner

star7th commented Jul 17, 2023

你那个 docker-compose.yml ,这个路径还是不太对。应该是

/showdo_data/html:/var/www/html

如果你宿主机真的无法改路径,可以通过 软连接的方式 达到路径变换的效果。

@xiagw
Copy link
Contributor Author

xiagw commented Jul 17, 2023

你那个 docker-compose.yml ,这个路径还是不太对。应该是

/showdo_data/html:/var/www/html

如果你宿主机真的无法改路径,可以通过 软连接的方式 达到路径变换的效果。

这个是没问题的,你可以测试一下,都兼容了你说的。

rsync -a --exclude='Sqlite/' --exclude='Public/Uploads/' $showdoc_html_dir/ $web_dir/
## revert lang if lang=en
if grep -q 'lang:.*en' $web_dir/web/index.html; then
sed -i -e "/lang:.*zh-cn.*/s//lang: 'zh-cn'/" $web_dir/web/index.html $web_dir/web_src/index.html
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增加语言字符串替换 这个语言

## upgrade (通过 Dockerfile 的环境变量 变更版本)
version_json=$(grep -o '"version":.*"' $file_json | awk '{print $2}')
version_json="${version_json//\"/}"
if [ -f $file_ver ]; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一是,版本的更新 ,改为判断 composer.json这个文件里的version字段。先不用Dockerfile的版本号

@star7th star7th merged commit ddeef0a into star7th:master Jul 17, 2023
@xiagw xiagw deleted the docker-upgrade branch July 18, 2023 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants