1Panel/agent/utils/compose/compose.go

40 lines
1.0 KiB
Go
Raw Normal View History

2024-07-23 14:48:37 +08:00
package compose
import (
"github.com/1Panel-dev/1Panel/agent/utils/cmd"
)
func Up(filePath string) (string, error) {
stdout, err := cmd.Execf("docker compose -f %s up -d", filePath)
2024-07-23 14:48:37 +08:00
return stdout, err
}
func Down(filePath string) (string, error) {
stdout, err := cmd.Execf("docker compose -f %s down --remove-orphans", filePath)
2024-07-23 14:48:37 +08:00
return stdout, err
}
func Stop(filePath string) (string, error) {
stdout, err := cmd.Execf("docker compose -f %s stop", filePath)
2024-07-23 14:48:37 +08:00
return stdout, err
}
func Restart(filePath string) (string, error) {
stdout, err := cmd.Execf("docker compose -f %s restart", filePath)
2024-07-23 14:48:37 +08:00
return stdout, err
}
func Operate(filePath, operation string) (string, error) {
stdout, err := cmd.Execf("docker compose -f %s %s", filePath, operation)
2024-07-23 14:48:37 +08:00
return stdout, err
}
func DownAndUp(filePath string) (string, error) {
stdout, err := cmd.Execf("docker compose -f %s down", filePath)
if err != nil {
return stdout, err
}
stdout, err = cmd.Execf("docker compose -f %s up -d", filePath)
return stdout, err
}