deploy, download 경로 지정
This commit is contained in:
@ -26,7 +26,7 @@ func (h *houstonHandler) GetAgents(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request) {
|
func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request) {
|
||||||
files, err := os.ReadDir("deploys")
|
files, err := os.ReadDir(h.deployPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, fs.ErrNotExist) {
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
err = os.MkdirAll("deploys", 0775)
|
err = os.MkdirAll("deploys", 0775)
|
||||||
@ -41,7 +41,7 @@ func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request
|
|||||||
|
|
||||||
getVersions := func(name string) []string {
|
getVersions := func(name string) []string {
|
||||||
var out []string
|
var out []string
|
||||||
files, _ := os.ReadDir(path.Join("deploys", name))
|
files, _ := os.ReadDir(path.Join(h.deployPath, name))
|
||||||
for _, fd := range files {
|
for _, fd := range files {
|
||||||
if fd.IsDir() {
|
if fd.IsDir() {
|
||||||
out = append(out, fd.Name())
|
out = append(out, fd.Name())
|
||||||
@ -90,10 +90,10 @@ 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("deploys", name, version, "config.json")
|
filename = path.Join(h.deployPath, name, version, "config.json")
|
||||||
} else {
|
} else {
|
||||||
// deploys 폴더는 파일시스템 서비스이므로 다운로드 가능
|
// deploys 폴더는 파일시스템 서비스이므로 다운로드 가능
|
||||||
filename = path.Join("deploys", name, version, name+ext)
|
filename = path.Join(h.deployPath, name, version, name+ext)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = os.MkdirAll(path.Dir(filename), 0775); err != nil {
|
if err = os.MkdirAll(path.Dir(filename), 0775); err != nil {
|
||||||
@ -125,7 +125,7 @@ func (h *houstonHandler) DeleteDeploySource(w http.ResponseWriter, r *http.Reque
|
|||||||
}
|
}
|
||||||
|
|
||||||
// deploys 폴더는 파일시스템 서비스이므로 다운로드 가능
|
// deploys 폴더는 파일시스템 서비스이므로 다운로드 가능
|
||||||
targetpath := path.Join("deploys", name, version)
|
targetpath := path.Join(h.deployPath, name, version)
|
||||||
if err := os.RemoveAll(targetpath); err != nil {
|
if err := os.RemoveAll(targetpath); err != nil {
|
||||||
logger.Println("deleteDeploySource failed :", err)
|
logger.Println("deleteDeploySource failed :", err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
@ -158,7 +158,7 @@ func (h *houstonHandler) Deploy(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
relPath := path.Join("deploys", name, version)
|
relPath := path.Join(h.deployPath, name, version)
|
||||||
files, err := os.ReadDir(relPath)
|
files, err := os.ReadDir(relPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
@ -189,7 +189,7 @@ func (h *houstonHandler) Deploy(w http.ResponseWriter, r *http.Request) {
|
|||||||
Name: name,
|
Name: name,
|
||||||
Version: version,
|
Version: version,
|
||||||
Url: path.Join(relPath, latestFilename),
|
Url: path.Join(relPath, latestFilename),
|
||||||
Config: path.Join("deploys", name, "config", "config.json"),
|
Config: path.Join(h.deployPath, name, "config", "config.json"),
|
||||||
},
|
},
|
||||||
targets,
|
targets,
|
||||||
))
|
))
|
||||||
@ -346,10 +346,10 @@ func (h *houstonHandler) GetLogFileLinks(w http.ResponseWriter, r *http.Request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if version == "latest" {
|
if version == "latest" {
|
||||||
version, _ = shared.FindLastestVersion(path.Join("downloads", name))
|
version, _ = shared.FindLastestVersion(path.Join(h.downloadPath, name))
|
||||||
}
|
}
|
||||||
|
|
||||||
root := path.Join("downloads", name, version)
|
root := path.Join(h.downloadPath, name, version)
|
||||||
logfiles, err := os.ReadDir(root)
|
logfiles, err := os.ReadDir(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
|||||||
@ -24,7 +24,9 @@ type HoustonServerWithHandler interface {
|
|||||||
|
|
||||||
type houstonHandler struct {
|
type houstonHandler struct {
|
||||||
HoustonServer
|
HoustonServer
|
||||||
methods map[string]reflect.Method
|
methods map[string]reflect.Method
|
||||||
|
deployPath string
|
||||||
|
downloadPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHoustonHandler() HoustonServerWithHandler {
|
func NewHoustonHandler() HoustonServerWithHandler {
|
||||||
@ -44,21 +46,20 @@ func NewHoustonHandler() HoustonServerWithHandler {
|
|||||||
|
|
||||||
func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string) error {
|
func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string) error {
|
||||||
storagePath := loadConfig().StoragePath
|
storagePath := loadConfig().StoragePath
|
||||||
|
h.deployPath = path.Join(storagePath, "deploys")
|
||||||
|
h.downloadPath = path.Join(storagePath, "downloads")
|
||||||
|
|
||||||
logger.Println("houstonHandler registed. storage_path :", storagePath)
|
logger.Printf("houstonHandler registed. deployPath : %s, downloadPath : %s", h.deployPath, h.downloadPath)
|
||||||
if len(storagePath) > 0 {
|
|
||||||
storagePath = storagePath + "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(prefix) > 0 {
|
if len(prefix) > 0 {
|
||||||
prefix = "/" + prefix
|
prefix = "/" + prefix
|
||||||
}
|
}
|
||||||
serveMux.Handle(prefix, h)
|
serveMux.Handle(prefix, h)
|
||||||
|
|
||||||
fsx := http.FileServer(http.Dir(storagePath + "deploys"))
|
fsx := http.FileServer(http.Dir(h.deployPath))
|
||||||
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(storagePath + "downloads"))
|
ufsx := http.FileServer(http.Dir(h.downloadPath))
|
||||||
serveMux.Handle(fmt.Sprintf("%s/downloads/", prefix), http.StripPrefix(fmt.Sprintf("%s/downloads/", prefix), ufsx))
|
serveMux.Handle(fmt.Sprintf("%s/downloads/", prefix), http.StripPrefix(fmt.Sprintf("%s/downloads/", prefix), ufsx))
|
||||||
|
|
||||||
serveMux.HandleFunc(fmt.Sprintf("%s/upload", prefix), func(w http.ResponseWriter, r *http.Request) {
|
serveMux.HandleFunc(fmt.Sprintf("%s/upload", prefix), func(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -75,7 +76,7 @@ func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string
|
|||||||
name := r.Header.Get("Houston-Service-Name")
|
name := r.Header.Get("Houston-Service-Name")
|
||||||
version := r.Header.Get("Houston-Service-Version")
|
version := r.Header.Get("Houston-Service-Version")
|
||||||
filename := r.Header.Get("Houston-Service-Filename")
|
filename := r.Header.Get("Houston-Service-Filename")
|
||||||
dir := fmt.Sprintf(storagePath+"downloads/%s/%s", name, version)
|
dir := path.Join(h.downloadPath, name, version)
|
||||||
if err := os.MkdirAll(dir, 0775); err == nil {
|
if err := os.MkdirAll(dir, 0775); err == nil {
|
||||||
file, _ := os.Create(path.Join(dir, filename))
|
file, _ := os.Create(path.Join(dir, filename))
|
||||||
if file != nil {
|
if file != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user