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