houston server config에 storagepath 추가
This commit is contained in:
@ -6,7 +6,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@ -81,11 +80,11 @@ func unzip(fname string) error {
|
|||||||
filePath := path.Join(verpath, name)
|
filePath := path.Join(verpath, name)
|
||||||
|
|
||||||
if f.FileInfo().IsDir() {
|
if f.FileInfo().IsDir() {
|
||||||
os.MkdirAll(filePath, os.ModePerm)
|
os.MkdirAll(filePath, 0775)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.MkdirAll(path.Dir(filePath), os.ModePerm); err != nil {
|
if err := os.MkdirAll(path.Dir(filePath), 0775); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +132,7 @@ func untar(fname string) error {
|
|||||||
|
|
||||||
switch header.Typeflag {
|
switch header.Typeflag {
|
||||||
case tar.TypeDir:
|
case tar.TypeDir:
|
||||||
if err := os.MkdirAll(path.Join(verpath, header.Name), 0755); err != nil {
|
if err := os.MkdirAll(path.Join(verpath, header.Name), 0775); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case tar.TypeReg:
|
case tar.TypeReg:
|
||||||
@ -171,7 +170,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) {
|
if _, err := os.Stat(verpath); os.IsNotExist(err) {
|
||||||
// 없네? 만들면 된다.
|
// 없네? 만들면 된다.
|
||||||
err = os.MkdirAll(verpath, fs.FileMode(os.O_WRONLY))
|
err = os.MkdirAll(verpath, 0775)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -177,6 +177,8 @@ func prepareProcessLaunch(req *shared.StartProcessRequest) *procmeta {
|
|||||||
|
|
||||||
if err == nil && fi.IsDir() {
|
if err == nil && fi.IsDir() {
|
||||||
args[0] = "./" + path.Clean(strings.TrimPrefix(args[0], "/"))
|
args[0] = "./" + path.Clean(strings.TrimPrefix(args[0], "/"))
|
||||||
|
os.Chmod(path.Join(verpath, args[0]), 0777)
|
||||||
|
|
||||||
cmd := exec.Command(args[0], args[1:]...)
|
cmd := exec.Command(args[0], args[1:]...)
|
||||||
cmd.Dir = verpath
|
cmd.Dir = verpath
|
||||||
stdin, _ := cmd.StdinPipe()
|
stdin, _ := cmd.StdinPipe()
|
||||||
@ -204,7 +206,7 @@ func (hc *houstonClient) launch(meta *procmeta) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.MkdirAll(path.Join(meta.cmd.Dir, "logs"), os.ModePerm)
|
err = os.MkdirAll(path.Join(meta.cmd.Dir, "logs"), 0775)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -73,7 +73,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ent.IsDir() {
|
if ent.IsDir() {
|
||||||
if err := os.MkdirAll(ent.Name(), os.ModePerm); err != nil {
|
if err := os.MkdirAll(ent.Name(), 0775); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -29,7 +29,7 @@ func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request
|
|||||||
files, err := os.ReadDir("deploys")
|
files, err := os.ReadDir("deploys")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, fs.ErrNotExist) {
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
err = os.MkdirAll("deploys", os.ModePerm)
|
err = os.MkdirAll("deploys", 0775)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ func (h *houstonHandler) UploadDeploySource(w http.ResponseWriter, r *http.Reque
|
|||||||
filename = path.Join("deploys", name, version, name+ext)
|
filename = path.Join("deploys", name, version, name+ext)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = os.MkdirAll(path.Dir(filename), os.ModePerm); err != nil {
|
if err = os.MkdirAll(path.Dir(filename), 0775); err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -43,16 +43,22 @@ func NewHoustonHandler() HoustonServerWithHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string) error {
|
func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string) error {
|
||||||
logger.Println("houstonHandler registed")
|
storagePath := loadConfig().StoragePath
|
||||||
|
|
||||||
|
logger.Println("houstonHandler registed. storage_path :", storagePath)
|
||||||
|
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("deploys"))
|
fsx := http.FileServer(http.Dir(storagePath + "deploys"))
|
||||||
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("downloads"))
|
ufsx := http.FileServer(http.Dir(storagePath + "downloads"))
|
||||||
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) {
|
||||||
@ -69,8 +75,8 @@ 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("downloads/%s/%s", name, version)
|
dir := fmt.Sprintf(storagePath+"downloads/%s/%s", name, version)
|
||||||
if err := os.MkdirAll(dir, os.ModePerm); 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 {
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|||||||
@ -22,6 +22,7 @@ type HoustonServer interface {
|
|||||||
|
|
||||||
type serverConfig struct {
|
type serverConfig struct {
|
||||||
GrpcPort int `json:"grpc_port"`
|
GrpcPort int `json:"grpc_port"`
|
||||||
|
StoragePath string `json:"storage_path"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type totalConfig struct {
|
type totalConfig struct {
|
||||||
@ -110,17 +111,27 @@ type Operation interface {
|
|||||||
Hosts() map[string]hostSnapshot
|
Hosts() map[string]hostSnapshot
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer() HoustonServer {
|
func loadConfig() serverConfig {
|
||||||
port := 8080
|
|
||||||
if bt, err := os.ReadFile("config.json"); err == nil {
|
|
||||||
var config totalConfig
|
var config totalConfig
|
||||||
if err := json.Unmarshal(bt, &config); err == nil {
|
|
||||||
if config.Server.GrpcPort != 0 {
|
config.Server.GrpcPort = 8080
|
||||||
port = config.Server.GrpcPort
|
configFile, err := os.Open("config.json")
|
||||||
}
|
if err != nil {
|
||||||
|
logger.Error(err)
|
||||||
|
return config.Server
|
||||||
}
|
}
|
||||||
|
defer configFile.Close()
|
||||||
|
dec := json.NewDecoder(configFile)
|
||||||
|
err = dec.Decode(&config)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err)
|
||||||
|
return config.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return config.Server
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewServer() HoustonServer {
|
||||||
var opts []grpc.ServerOption
|
var opts []grpc.ServerOption
|
||||||
grpcServer := grpc.NewServer(opts...)
|
grpcServer := grpc.NewServer(opts...)
|
||||||
|
|
||||||
@ -133,7 +144,7 @@ func NewServer() HoustonServer {
|
|||||||
rpcServer: grpcServer,
|
rpcServer: grpcServer,
|
||||||
os: os,
|
os: os,
|
||||||
ms: ms,
|
ms: ms,
|
||||||
port: port,
|
port: loadConfig().GrpcPort,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user