2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 06:47:20 +08:00

feat: 支持更新编排文件

This commit is contained in:
耗子
2025-03-21 03:20:08 +08:00
parent 422c92cca5
commit eed834bd5f
4 changed files with 35 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ type ContainerComposeRepo interface {
List() ([]string, error)
Get(name string) (string, string, error)
Create(name, compose, env string) error
Update(name, compose, env string) error
Up(name string, force bool) error
Down(name string) error
Remove(name string) error

View File

@@ -60,6 +60,19 @@ func (r *containerComposeRepo) Create(name, compose, env string) error {
return nil
}
// Update 更新编排文件
func (r *containerComposeRepo) Update(name, compose, env string) error {
dir := filepath.Join(app.Root, "server", "compose", name)
if err := os.WriteFile(filepath.Join(dir, "docker-compose.yml"), []byte(compose), 0644); err != nil {
return err
}
if err := os.WriteFile(filepath.Join(dir, ".env"), []byte(env), 0644); err != nil {
return err
}
return nil
}
// Up 启动编排
func (r *containerComposeRepo) Up(name string, force bool) error {
file := filepath.Join(app.Root, "server", "compose", name, "docker-compose.yml")

View File

@@ -10,6 +10,12 @@ type ContainerComposeCreate struct {
Env string `json:"env"`
}
type ContainerComposeUpdate struct {
Name string `uri:"name" validate:"required"`
Compose string `json:"compose" validate:"required"`
Env string `json:"env"`
}
type ContainerComposeUp struct {
Name string `uri:"name" validate:"required"`
Force bool `json:"force"`

View File

@@ -68,6 +68,21 @@ func (s *ContainerComposeService) Create(w http.ResponseWriter, r *http.Request)
Success(w, nil)
}
func (s *ContainerComposeService) Update(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerComposeUpdate](r)
if err != nil {
Error(w, http.StatusUnprocessableEntity, "%v", err)
return
}
if err = s.containerComposeRepo.Update(req.Name, req.Compose, req.Env); err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}
Success(w, nil)
}
func (s *ContainerComposeService) Up(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerComposeUp](r)
if err != nil {