Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
deploy_script
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Script
deploy_script
Commits
43a5430b
Commit
43a5430b
authored
Dec 31, 2019
by
金凯强
🎨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
升级脚本
parent
f04110d9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
0 deletions
+100
-0
upgrade.bat
upgrade/upgrade.bat
+25
-0
upgrade.py
upgrade/upgrade.py
+75
-0
No files found.
upgrade/upgrade.bat
0 → 100644
View file @
43a5430b
@echo off
set user=root
set password=huansi.net
set ip=127.0.0.1
set port=1111
plink %user%@%ip% -P %port% -pw %password% "echo huansi"
echo 是否输出huansi
echo 是否输出huansi, 如果正确输出请输入y y/n:
set /p flag=
if /i %flag% == y (
echo 建立上传目录
plink %user%@%ip% -P %port% -pw %password% "mkdir -p /huansi && mkdir -p /huansi/deploy"
echo 删除服务器上的旧版镜像tar
plink %user%@%ip% -P %port% -pw %password% "rm -f /huansi/deploy/*.tar"
echo 上传镜像...
pscp -pw %password% -P %port% -r D:\HuanSi\LinuxData\upload\ %user%@%ip%:/huansi/deploy
echo 升级镜像...
plink %user%@%ip% -P %port% -pw %password% "cd /huansi/deploy && python /huansi/deploy/upgrade.py"
echo 升级完成,可以愉快的玩耍了
)^
else (echo "stop the procedure!")
pause
\ No newline at end of file
upgrade/upgrade.py
0 → 100644
View file @
43a5430b
# -*- coding:utf-8 -*-
import
os
import
re
class
UpgradeTool
():
'''
升级工具
'''
def
load_images
(
self
):
'''
加载镜像
:return:
'''
app_name_list
=
self
.
get_app_list
()
for
app_name
in
app_name_list
:
if
not
app_name
:
continue
image_name
=
app_name
[:
-
4
]
.
replace
(
'___'
,
"/"
)
.
replace
(
"__"
,
":"
)
print
(
'load docker image:{}'
.
format
(
image_name
))
cmd_res
=
os
.
system
(
'docker load -i {}'
.
format
(
app_name
))
if
cmd_res
==
1
:
raise
RuntimeError
(
'load docker image fail'
)
def
get_app_list
(
self
):
'''
获取app列表
:return:
'''
with
os
.
popen
(
'ls | grep .tar'
)
as
f
:
cmd_txt
=
f
.
read
()
if
not
cmd_txt
:
raise
RuntimeError
(
'please check files,not find .tar file'
)
app_name_list
=
cmd_txt
.
split
(
'
\n
'
)
return
app_name_list
def
upgrade
(
self
):
'''
升级app
:return:
'''
self
.
load_images
()
print
(
'docker image load complete
\n
'
)
print
(
'start upgrade app
\n
'
)
with
open
(
'docker-compose.yml'
,
'r'
)
as
f
:
compose_content
=
f
.
read
()
app_list_str
=
re
.
findall
(
'# app_list: ".*"'
,
compose_content
)
if
app_list_str
:
app_list_str
=
app_list_str
[
0
]
else
:
raise
RuntimeError
(
'not set app_list in docker-compose.yml'
)
app_str
=
app_list_str
[
len
(
'# app_list: "'
):
-
1
]
if
app_str
==
'*'
:
res
=
os
.
system
(
'''export HUANSI_REGISTRY_URL=47.110.145.204:8084 &&
\
source /etc/profile.d/huansi.sh &&
\
docker-compose up -d --force-recreate'''
)
else
:
res
=
os
.
system
(
'''export HUANSI_REGISTRY_URL=47.110.145.204:8084 &&
\
source /etc/profile.d/huansi.sh &&
\
docker-compose up -d --force-recreate --no-deps {}'''
.
format
(
app_str
))
if
res
==
1
:
raise
RuntimeError
(
'app upgrade fail'
)
print
(
'upgrade app complete
\n
'
)
if
__name__
==
"__main__"
:
UpgradeTool
()
.
upgrade
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment