deployprogress
This commit is contained in:
@ -11,17 +11,19 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
"repositories.action2quare.com/ayo/houston/shared"
|
||||
"repositories.action2quare.com/ayo/houston/shared/protos"
|
||||
|
||||
"golang.org/x/text/encoding/korean"
|
||||
|
||||
"golang.org/x/text/transform"
|
||||
)
|
||||
|
||||
func download(dir string, urlpath string, accessToken string) (target string, err error) {
|
||||
func download(dir string, urlpath string, accessToken string, cb func(int64, int64)) (target string, err error) {
|
||||
logger.Println("start downloading", dir, urlpath)
|
||||
defer func() {
|
||||
if err != nil {
|
||||
@ -54,9 +56,27 @@ func download(dir string, urlpath string, accessToken string) (target string, er
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
_, err = io.Copy(out, resp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
cl := resp.Header.Get("Content-Length")
|
||||
totalLength, _ := strconv.ParseInt(cl, 10, 0)
|
||||
totalWritten := int64(0)
|
||||
|
||||
if cb != nil {
|
||||
cb(0, totalLength)
|
||||
}
|
||||
|
||||
for {
|
||||
written, err := io.CopyN(out, resp.Body, 1024*1024)
|
||||
totalWritten += written
|
||||
if cb != nil {
|
||||
cb(totalWritten, totalLength)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
return filepath.ToSlash(out.Name()), nil
|
||||
@ -248,7 +268,7 @@ func (hc *houstonClient) prepareUpdateSelf(req *shared.DeployRequest) (srcdir st
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
fname, err := download(tempdir, hc.makeDownloadUrl(req.Url), req.AccessToken)
|
||||
fname, err := download(tempdir, hc.makeDownloadUrl(req.Url), req.AccessToken, nil)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
@ -282,7 +302,7 @@ func (hc *houstonClient) prepareUpdateSelf(req *shared.DeployRequest) (srcdir st
|
||||
return filepath.ToSlash(tempdir), replacer, err
|
||||
}
|
||||
|
||||
func (hc *houstonClient) deploy(req *shared.DeployRequest) error {
|
||||
func (hc *houstonClient) deploy(req *shared.DeployRequest, cb func(*protos.DeployingProgress)) error {
|
||||
logger.Println("start deploying")
|
||||
root, err := hc.prepareDeploy(req.Name, req.Version)
|
||||
if err != nil {
|
||||
@ -290,11 +310,25 @@ func (hc *houstonClient) deploy(req *shared.DeployRequest) error {
|
||||
}
|
||||
|
||||
// verpath에 배포 시작
|
||||
fname, err := download(root, hc.makeDownloadUrl(req.Url), req.AccessToken)
|
||||
fname, err := download(root, hc.makeDownloadUrl(req.Url), req.AccessToken, func(written int64, total int64) {
|
||||
prog := protos.DeployingProgress{
|
||||
State: "download",
|
||||
Progress: written,
|
||||
Total: total,
|
||||
}
|
||||
cb(&prog)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cb(&protos.DeployingProgress{
|
||||
State: "unzip/untar",
|
||||
Progress: 0,
|
||||
Total: 0,
|
||||
})
|
||||
|
||||
switch path.Ext(fname) {
|
||||
case ".zip":
|
||||
err = unzip(fname)
|
||||
@ -304,7 +338,7 @@ func (hc *houstonClient) deploy(req *shared.DeployRequest) error {
|
||||
|
||||
if err == nil && len(req.Config) > 0 {
|
||||
// config.json도 다운로드
|
||||
_, err = download(root, hc.makeDownloadUrl(req.Config), req.AccessToken)
|
||||
_, err = download(root, hc.makeDownloadUrl(req.Config), req.AccessToken, nil)
|
||||
}
|
||||
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user