-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
docker upgrade #1993
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
02bd92f
auto upgrade with docker
xiagw 8c0d4df
fix file mode
xiagw 4d7fda8
fix file permission
xiagw 8babd6b
add docker-coompose.yml
xiagw 2749d1b
docker compose with build image
xiagw 2439ff7
fix revert lang if lang=en
xiagw 63aaeba
add comment for rsync exclude
xiagw 21058b0
fix old dir of showdoc_data
xiagw 3fcf9ca
get ver from composer.json
xiagw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
version: '3' | ||
|
||
networks: | ||
showdocnet: | ||
|
||
services: | ||
showdoc: | ||
## 官方 image ################################ | ||
# image: star7th/showdoc | ||
## 官方 image ################################ | ||
## 源码 build image ################################ | ||
build: | ||
context: ./ | ||
args: | ||
- IN_CHINA=false | ||
## 国内构建镜像, docker compose build --build-arg IN_CHINA=true | ||
## 启动, docker compose up -d | ||
## 源码 build image ################################ | ||
hostname: showdoc | ||
ports: | ||
- 4999:80 | ||
volumes: | ||
## 兼容历史版本文件 | ||
- /showdoc_data:/showdoc_data_old | ||
- ./showdocdata/html:/var/www/html | ||
restart: always | ||
tty: true | ||
networks: | ||
- showdocnet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,64 @@ | |
set -e | ||
|
||
## web site dir | ||
if [ ! -f "/var/www/html/index.php" ]; then | ||
\cp -fr /showdoc_data/html/* /var/www/html/ | ||
showdoc_dir='/showdoc_data' | ||
showdoc_dir_old='/showdoc_data_old' | ||
showdoc_dir_old_skip='/showdoc_data_old/.skip_old' | ||
showdoc_html_dir="$showdoc_dir/html" | ||
web_dir='/var/www/html' | ||
file_ver=$web_dir/.ver | ||
# file_ver_json=$web_dir/.json.ver | ||
file_json=$showdoc_html_dir/composer.json | ||
|
||
db_file=$web_dir/Sqlite/showdoc.db.php | ||
|
||
## 首次启动需要 copy to /var/www/html | ||
if [ -f "$web_dir/index.php" ]; then | ||
echo "Found $web_dir/index.php, skip copy." | ||
else | ||
echo "Not found $web_dir/index.php, copy..." | ||
## 兼容历史版本 宿主机 /showdoc_data | ||
if [[ -f $showdoc_dir_old/html/index.php && ! -f $showdoc_dir_old_skip ]]; then | ||
echo "Found old version of \"showdoc_data\", copy..." | ||
rsync -a $showdoc_dir_old/html/ $web_dir/ && | ||
touch $showdoc_dir_old_skip | ||
else | ||
rsync -a $showdoc_html_dir/ $web_dir/ | ||
fi | ||
fi | ||
## set file mode | ||
chown -R 1000:1000 /var/www/html/Sqlite /var/www/html/Public/Uploads | ||
## upgrade (通过 Dockerfile 的环境变量 变更版本) | ||
version_json=$(grep -o '"version":.*"' $file_json | awk '{print $2}') | ||
version_json="${version_json//\"/}" | ||
if [ -f $file_ver ]; then | ||
# if [[ "$SHOWDOC_DOCKER_VERSION" == "$(cat $file_ver)" ]]; then | ||
if [[ "${version_json}" == "$(cat $file_ver)" ]]; then | ||
echo "Same version, skip upgrade." | ||
else | ||
echo "Backup db file before upgrade..." | ||
\cp -av $db_file ${db_file}."$(date +%F-%H-%M-%S)".php | ||
echo "Upgrade application files..." | ||
## 此处不同步 db 文件和 upload 文件,自动排除 | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 增加语言字符串替换 这个语言 |
||
fi | ||
fi | ||
else | ||
# echo "$SHOWDOC_DOCKER_VERSION" >$file_ver | ||
echo "$version_json" >$file_ver | ||
fi | ||
## fix file permission | ||
# find $web_dir -type f -exec chmod 644 {} \; | ||
# find $web_dir -type d -exec chmod 755 {} \; | ||
# find $web_dir -type f -iname '*.sh' -exec chmod 755 {} \; | ||
[[ -d $web_dir/server/Application/Runtime ]] || | ||
mkdir -p $web_dir/server/Application/Runtime | ||
chown -R 1000:1000 \ | ||
$web_dir/Sqlite \ | ||
$web_dir/Public/Uploads \ | ||
$web_dir/install \ | ||
$web_dir/server/Application/Runtime | ||
|
||
_kill() { | ||
echo "receive SIGTERM, kill $pids" | ||
|
@@ -18,7 +71,6 @@ _kill() { | |
} | ||
|
||
## backup sqlite file every day | ||
db_file=/var/www/html/Sqlite/showdoc.db.php | ||
while [ -f $db_file ]; do | ||
# backup on 20:01 (UTC) every day | ||
if [[ $(date +%H%M) == 2001 ]]; then | ||
|
@@ -33,13 +85,13 @@ pids="$pids $!" | |
|
||
( | ||
sleep 3 | ||
cd /showdoc_data/html/server | ||
cd $showdoc_html_dir/server | ||
php index.php /api/update/dockerUpdateCode | ||
) | ||
( | ||
echo "delay 30s start mock..." | ||
sleep 30 | ||
cd /showdoc_data/mock/ | ||
cd $showdoc_dir/mock/ | ||
npm run start | ||
) & | ||
pids="$pids $!" | ||
|
@@ -51,4 +103,3 @@ pids="$pids $!" | |
trap _kill HUP INT QUIT TERM | ||
|
||
wait | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一是,版本的更新 ,改为判断 composer.json这个文件里的version字段。先不用Dockerfile的版本号