From 592e00b98b911e9786ff28bb024ecf14277992a9 Mon Sep 17 00:00:00 2001 From: mountain Date: Tue, 12 Nov 2024 11:53:18 +0900 Subject: [PATCH] =?UTF-8?q?=EC=85=80=ED=94=84=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=EC=9E=91=EC=97=85=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?by=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/client.go | 2 +- client/deploy.go | 23 +++++++++++------- houston.sh | 54 ++++++++++++++++-------------------------- server/http_api.go | 14 +++++++---- server/http_handler.go | 37 ----------------------------- 5 files changed, 44 insertions(+), 86 deletions(-) diff --git a/client/client.go b/client/client.go index e85e857..b69cfa2 100644 --- a/client/client.go +++ b/client/client.go @@ -414,7 +414,7 @@ func NewClient(standalone bool) (HoustonClient, error) { op.ReportDeployingProgress(ctx, dp) }); err == nil { if dr.Name == "houston" { - // houston.update 다운로드가 완료되었으므로 종료 + // houston_update_dir 다운로드가 완료되었으므로 종료 // 종료되고나면 스크립트가 알아서 재 실행 hc.Shutdown() return diff --git a/client/deploy.go b/client/deploy.go index 708ae6c..78a326c 100644 --- a/client/deploy.go +++ b/client/deploy.go @@ -25,6 +25,10 @@ import ( "golang.org/x/text/transform" ) +const ( + houston_update_dir = "./houston.update" +) + func pof2(x int64, min int64) (out int64) { out = 1 org := x @@ -217,13 +221,7 @@ func (hc *houstonClient) prepareDeploy(name string, version string) (destPath st }() verpath := path.Join(hc.config.StorageRoot, name, version) - if _, err := os.Stat(verpath); os.IsNotExist(err) { - // 없네? 만들면 된다. - err = os.MkdirAll(verpath, 0775) - if err != nil { - return "", err - } - } else { + if _, err := os.Stat(verpath); !os.IsNotExist(err) { // 있네? 재배포 가능한가? for _, child := range hc.childProcs { if child.version == version && child.name == name { @@ -287,8 +285,10 @@ func (hc *houstonClient) deploy(req *shared.DeployRequest, cb func(*protos.Deplo var root string if req.Name == "houston" { - // houston은 버전없이 houston.update폴더로 다운로드 - root = "./houston.update" + // houston은 버전없이 houston_update_dir폴더로 다운로드 + root = houston_update_dir + // 이미 houston_update_dir가 있을 수도 있으므로 폴더채로 삭제 + os.RemoveAll(houston_update_dir) } else { root, err = hc.prepareDeploy(req.Name, req.Version) if err != nil { @@ -296,6 +296,11 @@ func (hc *houstonClient) deploy(req *shared.DeployRequest, cb func(*protos.Deplo } } + err = os.MkdirAll(root, 0775) + if err != nil { + return err + } + // verpath에 배포 시작 h := md5.New() h.Write([]byte(strings.Trim(req.Url, "/"))) diff --git a/houston.sh b/houston.sh index bf34ba4..533a2b4 100644 --- a/houston.sh +++ b/houston.sh @@ -3,49 +3,35 @@ HOUSTON_PATH="./houston" UPDATE_DIR="houston.update" -while true; do - # houston 실행 +run_houston() { if [ -f "$HOUSTON_PATH" ]; then - "$HOUSTON_PATH" - EXIT_CODE=$? + "$HOUSTON_PATH" "$@" + return $? else echo "houston 실행 파일이 없습니다." - EXIT_CODE=1 + return 1 fi - +} + +while true; do + echo "현재 버전의 houston을 실행합니다." + run_houston "$@" + # houston.update 폴더가 존재하는지 확인 if [ -d "$UPDATE_DIR" ]; then - # houston 파일이 존재하는 경우에만 시간 비교 - if [ -f "$HOUSTON_PATH" ]; then - HOUSTON_TIME=$(stat -c %Y "$HOUSTON_PATH") - UPDATE_TIME=$(stat -c %Y "$UPDATE_DIR") - - if [ $UPDATE_TIME -gt $HOUSTON_TIME ]; then - echo "새로운 업데이트 폴더 발견. 업데이트를 진행합니다." - # houston.update 폴더 내의 모든 파일을 현재 폴더로 복사 - cp -R "$UPDATE_DIR"/* . - # 실행 권한 부여 (필요한 경우) - chmod +x "$HOUSTON_PATH" - # 업데이트 폴더 삭제 - rm -rf "$UPDATE_DIR" - echo "업데이트 완료 및 업데이트 폴더 삭제. houston을 다시 시작합니다." - else - echo "업데이트 폴더가 최신이 아닙니다. 업데이트를 건너뜁니다." - break - fi - else - echo "houston 파일이 없습니다. houston.update 폴더의 내용을 복사합니다." - cp -R "$UPDATE_DIR"/* . - chmod +x "$HOUSTON_PATH" - # 업데이트 폴더 삭제 - rm -rf "$UPDATE_DIR" - echo "houston을 시작합니다." - fi + echo "새로운 업데이트 폴더 발견. 업데이트를 진행합니다." + # houston.update 폴더 내의 모든 파일을 현재 폴더로 복사 + cp -R "$UPDATE_DIR"/* . + # 실행 권한 부여 (필요한 경우) + chmod +x "$HOUSTON_PATH" + # 업데이트 폴더 삭제 + rm -rf "$UPDATE_DIR" + echo "업데이트 완료 및 업데이트 폴더 삭제. houston을 다시 시작합니다." else - echo "업데이트 폴더가 없습니다. 스크립트를 종료합니다." + echo "업데이트 폴더가 없습니다. 스크립트 실행을 종료합니다." break fi done echo "houston 실행 및 업데이트 스크립트 종료" -exit $EXIT_CODE \ No newline at end of file +exit $? \ No newline at end of file diff --git a/server/http_api.go b/server/http_api.go index 1f2b4da..48dff70 100644 --- a/server/http_api.go +++ b/server/http_api.go @@ -276,11 +276,15 @@ func (h *houstonHandler) Deploy(w http.ResponseWriter, r *http.Request) { return } - configPath, err := h.findLastestConfigFile(name) - if err != nil { - logger.Println(err) - w.WriteHeader(http.StatusBadRequest) - return + var configPath string + if name != "houston" { + // houston은 config를 포함하여 배포 + configPath, err = h.findLastestConfigFile(name) + if err != nil { + logger.Println(err) + w.WriteHeader(http.StatusBadRequest) + return + } } h.Operation().Deploy(MakeDeployRequest( diff --git a/server/http_handler.go b/server/http_handler.go index c3f7ce4..702aa4c 100644 --- a/server/http_handler.go +++ b/server/http_handler.go @@ -14,7 +14,6 @@ import ( "strings" "repositories.action2quare.com/ayo/gocommon" - "repositories.action2quare.com/ayo/gocommon/flagx" "repositories.action2quare.com/ayo/gocommon/logger" ) @@ -159,9 +158,6 @@ func (h *houstonHandler) RegisterHandlers(serveMux gocommon.ServerMuxInterface, return nil } -var noauth = flagx.Bool("noauth", false, "") -var authtype = flagx.String("auth", "on", "on|off|both") - func (h *houstonHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { defer func() { s := recover() @@ -176,39 +172,6 @@ func (h *houstonHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { r.Body.Close() }() - // TODO : 구글 인증까지 붙인 후에 주석 제거 - // var userinfo map[string]any - // if !*noauth && (*authtype == "on" || *authtype == "both") { - // authheader := r.Header.Get("Authorization") - // if len(authheader) == 0 { - // logger.Println("Authorization header is not valid :", authheader) - // w.WriteHeader(http.StatusBadRequest) - // return - // } - - // req, _ := http.NewRequest("GET", "https://graph.microsoft.com/oidc/userinfo", nil) - // req.Header.Add("Authorization", authheader) - // client := &http.Client{} - - // resp, err := client.Do(req) - // if err != nil { - // logger.Println("graph microsoft api call failed :", err) - // w.WriteHeader(http.StatusBadRequest) - // return - // } - // defer resp.Body.Close() - - // raw, _ := io.ReadAll(resp.Body) - // if err = json.Unmarshal(raw, &userinfo); err != nil { - // return - // } - - // if _, expired := userinfo["error"]; expired { - // w.WriteHeader(http.StatusUnauthorized) - // return - // } - // } - var operation string if r.Method == "POST" { operation = r.FormValue("operation")