mirror of
https://github.com/labring/sealos.git
synced 2026-09-24 15:46:19 +08:00
fix sendpackage and cmd with workdir
This commit is contained in:
@@ -196,6 +196,8 @@ mkdir dashboard && cd dashboard
|
||||
```cassandraql
|
||||
echo "LOAD docker load -i image.tar" >> config
|
||||
echo "APPLY kubectl apply -f dashboard.yaml" >> config
|
||||
echo "DELETE kubectl delete -f dashboard.yaml" >> config
|
||||
echo "REMOVE sleep 10 && docker rmi -f dashboard:latest" >> config
|
||||
```
|
||||
|
||||
3. 下载yaml文件与保存镜像
|
||||
|
||||
+5
-3
@@ -159,16 +159,17 @@ type RunOnEveryNodes struct {
|
||||
func (r *RunOnEveryNodes) Run(config SealConfig, url, pkgName string) {
|
||||
var wg sync.WaitGroup
|
||||
tarCmd := fmt.Sprintf("tar xvf %s.tar", pkgName)
|
||||
workspace := fmt.Sprintf("/root/%s", pkgName)
|
||||
|
||||
nodes := append(config.Masters, config.Nodes...)
|
||||
SendPackage(url, nodes, pkgName)
|
||||
FetchPackage(url, nodes, workspace)
|
||||
for _, node := range nodes {
|
||||
wg.Add(1)
|
||||
go func(node string) {
|
||||
defer wg.Done()
|
||||
Cmd(node, tarCmd)
|
||||
for _, cmd := range r.Cmd {
|
||||
CmdWorkSpace(node, cmd.Cmd, fmt.Sprintf("/root/%s", pkgName))
|
||||
CmdWorkSpace(node, cmd.Cmd, workspace)
|
||||
}
|
||||
}(node)
|
||||
}
|
||||
@@ -181,9 +182,10 @@ type RunOnMaster struct {
|
||||
}
|
||||
|
||||
func (r *RunOnMaster) Run(config SealConfig, url, pkgName string) {
|
||||
workspace := fmt.Sprintf("/root/%s", pkgName)
|
||||
SendPackage(url, []string{config.Masters[0]}, pkgName)
|
||||
for _, cmd := range r.Cmd {
|
||||
CmdWorkSpace(config.Masters[0], cmd.Cmd,fmt.Sprintf("/root/%s", pkgName))
|
||||
CmdWorkSpace(config.Masters[0], cmd.Cmd, workspace)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -335,3 +335,44 @@ func SendPackage(url string, hosts []string, packName string) {
|
||||
}
|
||||
wm.Wait()
|
||||
}
|
||||
|
||||
// FetchPackage if url exist wget it, or scp the local package to hosts
|
||||
// dst is the remote offline path like /root
|
||||
func FetchPackage(url string, hosts []string, dst string) {
|
||||
pkg := path.Base(url)
|
||||
fullDst := fmt.Sprintf("%s/%s", dst, pkg)
|
||||
mkdstdir := fmt.Sprintf("mkdir -p %s || true", dst)
|
||||
|
||||
//only http
|
||||
isHttp := strings.HasPrefix(url, "http")
|
||||
wgetCommand := ""
|
||||
if isHttp {
|
||||
wgetParam := ""
|
||||
if strings.HasPrefix(url, "https") {
|
||||
wgetParam = "--no-check-certificate"
|
||||
}
|
||||
wgetCommand = fmt.Sprintf(" wget %s ", wgetParam)
|
||||
}
|
||||
remoteCmd := fmt.Sprintf("cd %s && %s %s", dst, wgetCommand, url)
|
||||
|
||||
var wm sync.WaitGroup
|
||||
for _, host := range hosts {
|
||||
wm.Add(1)
|
||||
go func(host string) {
|
||||
defer wm.Done()
|
||||
logger.Debug("[%s]please wait for copy offline package", host)
|
||||
Cmd(host, mkdstdir)
|
||||
if RemoteFilExist(host, fullDst) {
|
||||
logger.Warn("[%s]SendPackage: [%s] file is exist", host, fullDst)
|
||||
} else {
|
||||
if isHttp {
|
||||
go WatchFileSize(host, fullDst, GetFileSize(url))
|
||||
Cmd(host, remoteCmd)
|
||||
} else {
|
||||
Copy(host, url, fullDst)
|
||||
}
|
||||
}
|
||||
}(host)
|
||||
}
|
||||
wm.Wait()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user