Compare commits

...

2 Commits

3 changed files with 30 additions and 8 deletions

View File

@ -20,9 +20,15 @@ import (
현재 접속 중인 Agent 목록을 보여줍니다. 현재 접속 중인 Agent 목록을 보여줍니다.
- http method : GET - http method : GET
*/ */
const (
sub_folder_name_deploys = string("_deploys")
sub_folder_name_downloads = string("_downloads")
)
func (h *houstonHandler) GetAgents(w http.ResponseWriter, r *http.Request) { func (h *houstonHandler) GetAgents(w http.ResponseWriter, r *http.Request) {
enc := json.NewEncoder(w) enc := json.NewEncoder(w)
enc.Encode(h.Operation().Hosts()) allHosts := h.Operation().Hosts()
enc.Encode(allHosts)
} }
func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request) { func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request) {
@ -84,7 +90,7 @@ func (h *houstonHandler) UploadDeploySource(w http.ResponseWriter, r *http.Reque
var filename string var filename string
if version == "config" { if version == "config" {
filename = path.Join(h.deployPath, name, version, "config.json") filename = path.Join(h.deployPath, name, version, "config"+ext)
} else { } else {
// deploys 폴더는 파일시스템 서비스이므로 다운로드 가능 // deploys 폴더는 파일시스템 서비스이므로 다운로드 가능
filename = path.Join(h.deployPath, name, version, name+ext) filename = path.Join(h.deployPath, name, version, name+ext)
@ -180,14 +186,14 @@ func (h *houstonHandler) Deploy(w http.ResponseWriter, r *http.Request) {
configPath := "" configPath := ""
if _, err := os.Stat(path.Join(h.deployPath, name, "config", "config.json")); err == nil || errors.Is(err, fs.ErrExist) { if _, err := os.Stat(path.Join(h.deployPath, name, "config", "config.json")); err == nil || errors.Is(err, fs.ErrExist) {
configPath = path.Join("deploys", name, "config", "config.json") configPath = path.Join(sub_folder_name_deploys, name, "config", "config.json")
} }
h.Operation().Deploy(MakeDeployRequest( h.Operation().Deploy(MakeDeployRequest(
shared.DeployRequest{ shared.DeployRequest{
Name: name, Name: name,
Version: version, Version: version,
Url: path.Join("deploys", name, version, latestFilename), Url: path.Join(sub_folder_name_deploys, name, version, latestFilename),
Config: configPath, Config: configPath,
}, },
targets, targets,
@ -357,7 +363,7 @@ func (h *houstonHandler) GetLogFileLinks(w http.ResponseWriter, r *http.Request)
var out []string var out []string
for _, lf := range logfiles { for _, lf := range logfiles {
out = append(out, path.Join("downloads", name, version, lf.Name())) out = append(out, path.Join(sub_folder_name_downloads, name, version, lf.Name()))
} }
enc := json.NewEncoder(w) enc := json.NewEncoder(w)

View File

@ -45,9 +45,10 @@ func NewHoustonHandler() HoustonServerWithHandler {
} }
func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string) error { func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string) error {
storagePath := loadServerConfig().StorageRoot config := loadServerConfig()
h.deployPath = path.Join(storagePath, "deploys") storagePath := config.StorageRoot
h.downloadPath = path.Join(storagePath, "downloads") h.deployPath = path.Join(storagePath, sub_folder_name_deploys)
h.downloadPath = path.Join(storagePath, sub_folder_name_downloads)
if err := os.MkdirAll(h.deployPath, 0775); err != nil { if err := os.MkdirAll(h.deployPath, 0775); err != nil {
return err return err

View File

@ -5,8 +5,10 @@ import (
"fmt" "fmt"
"net" "net"
"os" "os"
"time"
"repositories.action2quare.com/ayo/gocommon/logger" "repositories.action2quare.com/ayo/gocommon/logger"
"repositories.action2quare.com/ayo/houston/client"
"repositories.action2quare.com/ayo/houston/shared" "repositories.action2quare.com/ayo/houston/shared"
"repositories.action2quare.com/ayo/houston/shared/protos" "repositories.action2quare.com/ayo/houston/shared/protos"
@ -23,6 +25,7 @@ type HoustonServer interface {
type serverConfig struct { type serverConfig struct {
GrpcPort int `json:"grpc_port"` GrpcPort int `json:"grpc_port"`
StorageRoot string `json:"storage_path"` StorageRoot string `json:"storage_path"`
RunAsClient bool `json:"run_as_client"`
} }
type DeployRequest struct { type DeployRequest struct {
@ -173,6 +176,18 @@ func (hs *houstonServer) Start() error {
return err return err
} }
if loadServerConfig().RunAsClient {
go func() {
time.Sleep(time.Second)
hc, err := client.NewClient()
if err != nil {
logger.Fatal(err)
return
}
hc.Start()
}()
}
if err := hs.rpcServer.Serve(lis); err != nil { if err := hs.rpcServer.Serve(lis); err != nil {
return err return err
} }