deleteDeploySource, undeploy 추가
This commit is contained in:
@ -105,7 +105,7 @@ func unmarshal[T any](val *T, src map[string]string) {
|
||||
|
||||
func gatherDeployedPrograms(name string) []*protos.VersionAndArgs {
|
||||
var rawvers []*protos.VersionAndArgs
|
||||
if vers, err := os.ReadDir(path.Join("./", name)); err == nil {
|
||||
if vers, err := os.ReadDir(name); err == nil {
|
||||
for _, ver := range vers {
|
||||
if ver.IsDir() {
|
||||
args := lastExecutionArgs(path.Join(name, ver.Name()))
|
||||
|
||||
@ -160,7 +160,7 @@ func (hc *houstonClient) prepareDeploy(name string, version string) (destPath st
|
||||
}
|
||||
}()
|
||||
|
||||
verpath := path.Join("./", name, version)
|
||||
verpath := path.Join(name, version)
|
||||
if _, err := os.Stat(verpath); os.IsNotExist(err) {
|
||||
// 없네? 만들면 된다.
|
||||
err = os.MkdirAll(verpath, fs.FileMode(os.O_WRONLY))
|
||||
@ -210,7 +210,7 @@ func (hc *houstonClient) deploy(req *shared.DeployRequest) error {
|
||||
}
|
||||
|
||||
func (hc *houstonClient) withdraw(req *shared.WithdrawRequest) error {
|
||||
fd, _ := os.Stat(path.Join("./", req.Name, req.Version))
|
||||
fd, _ := os.Stat(path.Join(req.Name, req.Version))
|
||||
if fd != nil {
|
||||
if fd.IsDir() {
|
||||
for _, running := range hc.childProcs {
|
||||
@ -222,7 +222,7 @@ func (hc *houstonClient) withdraw(req *shared.WithdrawRequest) error {
|
||||
}
|
||||
}
|
||||
|
||||
return os.RemoveAll(path.Join("./", req.Name, req.Version))
|
||||
return os.RemoveAll(path.Join(req.Name, req.Version))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -168,7 +168,7 @@ func prepareProcessLaunch(req *shared.StartProcessRequest) *procmeta {
|
||||
re := regexp.MustCompile(`[^\s"']+|"([^"]*)"|'([^']*)`)
|
||||
args := re.FindAllString(req.Args, -1)
|
||||
|
||||
verpath := path.Join("./", req.Name, req.Version)
|
||||
verpath := path.Join(req.Name, req.Version)
|
||||
fi, err := os.Stat(verpath)
|
||||
|
||||
if err == nil && fi.IsDir() {
|
||||
@ -319,7 +319,7 @@ func (hc *houstonClient) startChildProcess(req *shared.StartProcessRequest) erro
|
||||
logger.Println("startChildProcess :", *req)
|
||||
if req.Version == "latest" {
|
||||
// 최신 버전을 찾음
|
||||
latest, err := shared.FindLastestVersion(path.Join("./", req.Name))
|
||||
latest, err := shared.FindLastestVersion(req.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -357,7 +357,7 @@ var errNoRunningProcess = errors.New("no running processed")
|
||||
func (hc *houstonClient) stopChildProcess(req *shared.StopProcessRequest) error {
|
||||
if req.Version == "latest" {
|
||||
// 최신 버전을 찾음
|
||||
latest, err := shared.FindLastestVersion(path.Join("./", req.Name))
|
||||
latest, err := shared.FindLastestVersion(req.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -424,7 +424,7 @@ func (hc *houstonClient) stopChildProcess(req *shared.StopProcessRequest) error
|
||||
func (hc *houstonClient) restartChildProcess(req *shared.RestartProcessRequest) error {
|
||||
if req.Version == "latest" {
|
||||
// 최신 버전을 찾음
|
||||
latest, err := shared.FindLastestVersion(path.Join("./", req.Name))
|
||||
latest, err := shared.FindLastestVersion(req.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -476,7 +476,7 @@ func (hc *houstonClient) restartChildProcess(req *shared.RestartProcessRequest)
|
||||
func (hc *houstonClient) uploadFiles(req *shared.UploadRequest) error {
|
||||
if req.Version == "latest" {
|
||||
// 최신 버전을 찾음
|
||||
latest, err := shared.FindLastestVersion(path.Join("./", req.Name))
|
||||
latest, err := shared.FindLastestVersion(req.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -96,6 +96,28 @@ func (h *houstonHandler) UploadDeploySource(w http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
}
|
||||
|
||||
func (h *houstonHandler) DeleteDeploySource(w http.ResponseWriter, r *http.Request) {
|
||||
// <form action="/houston" method="post" enctype="multipart/form-data">
|
||||
// <input type="text" name="name">
|
||||
// <input type="text" name="version">
|
||||
// </form>
|
||||
version := r.FormValue("version")
|
||||
name := r.FormValue("name")
|
||||
|
||||
if len(version) == 0 || len(name) == 0 {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// deploys 폴더는 파일시스템 서비스이므로 다운로드 가능
|
||||
targetpath := path.Join("deploys", name, version)
|
||||
if err := os.RemoveAll(targetpath); err != nil {
|
||||
logger.Println("deleteDeploySource failed :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (h *houstonHandler) Deploy(w http.ResponseWriter, r *http.Request) {
|
||||
// <form action="/houston" method="post" enctype="multipart/form-data">
|
||||
// <input type="text" name="name">
|
||||
@ -157,6 +179,39 @@ func (h *houstonHandler) Deploy(w http.ResponseWriter, r *http.Request) {
|
||||
))
|
||||
}
|
||||
|
||||
func (h *houstonHandler) Undeploy(w http.ResponseWriter, r *http.Request) {
|
||||
// <form action="/houston" method="post" enctype="multipart/form-data">
|
||||
// <input type="text" name="name">
|
||||
// <input type="text" name="version">
|
||||
// <input type="text" name="targets">
|
||||
// </form>
|
||||
name := r.FormValue("name")
|
||||
version := r.FormValue("version")
|
||||
traws := r.FormValue("targets")
|
||||
|
||||
var targets []string
|
||||
if len(traws) > 0 {
|
||||
if err := json.Unmarshal([]byte(traws), &targets); err != nil {
|
||||
logger.Error(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if len(name) == 0 || len(version) == 0 || len(targets) == 0 {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
h.Operation().Withdraw(MakeWithdrawRequest(
|
||||
shared.WithdrawRequest{
|
||||
Name: name,
|
||||
Version: version,
|
||||
},
|
||||
targets,
|
||||
))
|
||||
}
|
||||
|
||||
func (h *houstonHandler) StartProcess(w http.ResponseWriter, r *http.Request) {
|
||||
// <form action="/houston" method="post" enctype="multipart/form-data">
|
||||
// <input type="text" name="name">
|
||||
|
||||
@ -46,10 +46,10 @@ func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string
|
||||
logger.Println("houstonHandler registed")
|
||||
serveMux.Handle("/"+path.Join(prefix, "houston"), h)
|
||||
|
||||
fsx := http.FileServer(http.Dir("./deploys"))
|
||||
fsx := http.FileServer(http.Dir("deploys"))
|
||||
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/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) {
|
||||
@ -66,7 +66,7 @@ func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string
|
||||
name := r.Header.Get("Houston-Service-Name")
|
||||
version := r.Header.Get("Houston-Service-Version")
|
||||
filename := r.Header.Get("Houston-Service-Filename")
|
||||
dir := fmt.Sprintf("./downloads/%s/%s", name, version)
|
||||
dir := fmt.Sprintf("downloads/%s/%s", name, version)
|
||||
if err := os.MkdirAll(dir, os.ModePerm); err == nil {
|
||||
file, _ := os.Create(path.Join(dir, filename))
|
||||
if file != nil {
|
||||
|
||||
Reference in New Issue
Block a user