Compare commits
2 Commits
28d8fc4149
...
49921d44ce
| Author | SHA1 | Date | |
|---|---|---|---|
| 49921d44ce | |||
| 10555ba61a |
@ -39,7 +39,42 @@ func lastExecutionArgs(verpath string) []string {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (meta *procmeta) zipLogFiles(req *shared.UploadRequest, start, except string) (string, []string, error) {
|
var errUploadZipLogFailed = errors.New("not ok")
|
||||||
|
|
||||||
|
func (hc *houstonClient) uploadZipLogFile(zipFile string, name string, version string) error {
|
||||||
|
zf, err := os.Open(zipFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if zf == nil {
|
||||||
|
return errUploadZipLogFailed
|
||||||
|
}
|
||||||
|
|
||||||
|
defer zf.Close()
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", hc.httpAddr+"/upload", zf)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err)
|
||||||
|
}
|
||||||
|
req.Header.Set("Houston-Service-Name", name)
|
||||||
|
req.Header.Set("Houston-Service-Version", version)
|
||||||
|
req.Header.Set("Houston-Service-Filename", path.Base(zipFile))
|
||||||
|
req.Header.Set("Content-Type", "application/zip")
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return errUploadZipLogFailed
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func zipLogFiles(req *shared.UploadRequest, start, except string) (string, []string, error) {
|
||||||
root := path.Join(req.Name, req.Version)
|
root := path.Join(req.Name, req.Version)
|
||||||
matches, err := filepath.Glob(path.Join(root, req.Filter))
|
matches, err := filepath.Glob(path.Join(root, req.Filter))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -51,8 +86,9 @@ func (meta *procmeta) zipLogFiles(req *shared.UploadRequest, start, except strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
root = path.Join(root, path.Dir(req.Filter))
|
root = path.Join(root, path.Dir(req.Filter))
|
||||||
// Create a file to write the archive to.
|
zipFileName := path.Join(os.TempDir(), path.Base(matches[0]), ".zip")
|
||||||
f, err := os.CreateTemp("", "")
|
f, err := os.OpenFile(zipFileName, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
@ -68,7 +104,7 @@ func (meta *procmeta) zipLogFiles(req *shared.UploadRequest, start, except strin
|
|||||||
if file == root {
|
if file == root {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if file >= except {
|
if len(except) > 0 && file >= except {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if len(start) > 0 && file < start {
|
if len(start) > 0 && file < start {
|
||||||
@ -213,28 +249,17 @@ func (hc *houstonClient) launch(meta *procmeta) error {
|
|||||||
startFile := uploadStartFile
|
startFile := uploadStartFile
|
||||||
uploadStartFile = nextFile
|
uploadStartFile = nextFile
|
||||||
go func(startFile, nextFile string) {
|
go func(startFile, nextFile string) {
|
||||||
zipFile, srcFiles, err := meta.zipLogFiles(req, startFile, nextFile)
|
zipFile, srcFiles, err := zipLogFiles(req, startFile, nextFile)
|
||||||
if err == nil && len(zipFile) > 0 && len(srcFiles) > 0 {
|
if err == nil && len(zipFile) > 0 && len(srcFiles) > 0 {
|
||||||
zf, _ := os.Open(zipFile)
|
if err = hc.uploadZipLogFile(zipFile, meta.name, meta.version); err == nil {
|
||||||
if zf != nil {
|
|
||||||
req, err := http.NewRequest("POST", hc.httpAddr+"/upload", zf)
|
|
||||||
if err != nil {
|
|
||||||
logger.Error(err)
|
|
||||||
}
|
|
||||||
req.Header.Set("Houston-Service-Name", meta.name)
|
|
||||||
req.Header.Set("Houston-Service-Version", meta.version)
|
|
||||||
req.Header.Set("Houston-Service-Filename", path.Base(srcFiles[0])+".zip")
|
|
||||||
req.Header.Set("Content-Type", "application/zip")
|
|
||||||
resp, err := http.DefaultClient.Do(req)
|
|
||||||
if err == nil {
|
|
||||||
defer resp.Body.Close()
|
|
||||||
if resp.StatusCode == http.StatusOK {
|
|
||||||
for _, oldf := range srcFiles {
|
for _, oldf := range srcFiles {
|
||||||
os.Remove(oldf)
|
os.Remove(oldf)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
logger.Println("uploadZipLogFile failed :", err)
|
||||||
}
|
}
|
||||||
}
|
} else if err != nil {
|
||||||
}
|
logger.Println("zipLogFiles failed :", err)
|
||||||
}
|
}
|
||||||
}(startFile, nextFile)
|
}(startFile, nextFile)
|
||||||
|
|
||||||
@ -456,14 +481,29 @@ func (hc *houstonClient) uploadFiles(req *shared.UploadRequest) error {
|
|||||||
req.Version = latest
|
req.Version = latest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Println("uploadFiles req :", *req)
|
||||||
for _, child := range hc.childProcs {
|
for _, child := range hc.childProcs {
|
||||||
if child.version == req.Version && child.name == req.Name {
|
if child.version == req.Version && child.name == req.Name {
|
||||||
|
logger.Println("uploadFiles found :", child.version, child.name)
|
||||||
child.logUploadChan <- req
|
child.logUploadChan <- req
|
||||||
break
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO : 실행 중이 아닌 폴더에서도 대상을 찾는다
|
// 실행 중이 아닌 폴더에서도 대상을 찾는다
|
||||||
// deploys
|
// 전체 파일을 대상으로
|
||||||
|
zipFile, srcFiles, err := zipLogFiles(req, "", "")
|
||||||
|
if err == nil && len(zipFile) > 0 && len(srcFiles) > 0 {
|
||||||
|
if err = hc.uploadZipLogFile(zipFile, req.Name, req.Version); err == nil {
|
||||||
|
for _, oldf := range srcFiles {
|
||||||
|
os.Remove(oldf)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.Println("uploadZipLogFile failed :", err)
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
logger.Println("zipLogFiles failed :", err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,7 +50,7 @@ func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string
|
|||||||
serveMux.Handle(fmt.Sprintf("/%s/deploys/", prefix), http.StripPrefix(fmt.Sprintf("/%s/deploys/", prefix), fsx))
|
serveMux.Handle(fmt.Sprintf("/%s/deploys/", prefix), http.StripPrefix(fmt.Sprintf("/%s/deploys/", prefix), fsx))
|
||||||
|
|
||||||
ufsx := http.FileServer(http.Dir("./downloads"))
|
ufsx := http.FileServer(http.Dir("./downloads"))
|
||||||
serveMux.Handle(fmt.Sprintf("/%s/downloads/", prefix), http.StripPrefix(fmt.Sprintf("/%s/downloads/", prefix), ufsx))
|
serveMux.Handle(fmt.Sprintf("/%s/houston/downloads/", prefix), http.StripPrefix(fmt.Sprintf("/%s/houston/downloads/", prefix), ufsx))
|
||||||
|
|
||||||
serveMux.HandleFunc("/"+path.Join(prefix, "upload"), func(w http.ResponseWriter, r *http.Request) {
|
serveMux.HandleFunc("/"+path.Join(prefix, "upload"), func(w http.ResponseWriter, r *http.Request) {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|||||||
1
warehouse/0.0.5/@args
Normal file
1
warehouse/0.0.5/@args
Normal file
@ -0,0 +1 @@
|
|||||||
|
["././././warehouse.exe","-dev","-port=8090"]
|
||||||
1
warehouse/0.0.5/errs/warehouse_2023-05-26T16-45-31.err
Normal file
1
warehouse/0.0.5/errs/warehouse_2023-05-26T16-45-31.err
Normal file
@ -0,0 +1 @@
|
|||||||
|
2023/05/26 16:45:31 warehouse.exe 2023-05-26 16:11:31.7258831 +0900 KST
|
||||||
Reference in New Issue
Block a user