Fix bug that deploy api cannot create service

This commit is contained in:
cuigh
2021-12-24 19:52:29 +08:00
parent 16888e54ee
commit ab550f8748
8 changed files with 32 additions and 19 deletions

View File

@@ -8,7 +8,6 @@ import (
"github.com/cuigh/auxo/log"
"github.com/cuigh/auxo/net/web"
"github.com/cuigh/swirl/biz"
"github.com/cuigh/swirl/docker"
"github.com/gobwas/ws"
"github.com/gobwas/ws/wsutil"
)
@@ -72,10 +71,9 @@ func containerFind(b biz.ContainerBiz) web.HandlerFunc {
id := ctx.Query("id")
container, raw, err := b.Find(node, id)
if err != nil {
if docker.IsErrNotFound(err) {
return web.NewError(http.StatusNotFound, err.Error())
}
return err
} else if container == nil {
return web.NewError(http.StatusNotFound)
}
return success(ctx, data.Map{"container": container, "raw": raw})
}
@@ -127,9 +125,11 @@ func containerConnect(b biz.ContainerBiz) web.HandlerFunc {
cmd = ctx.Query("cmd")
)
_, _, err := b.Find(node, id)
container, _, err := b.Find(node, id)
if err != nil {
return err
} else if container == nil {
return web.NewError(http.StatusNotFound)
}
conn, _, _, err := ws.UpgradeHTTP(ctx.Request(), ctx.Response())

View File

@@ -6,7 +6,6 @@ import (
"github.com/cuigh/auxo/data"
"github.com/cuigh/auxo/net/web"
"github.com/cuigh/swirl/biz"
"github.com/cuigh/swirl/docker"
)
// ServiceHandler encapsulates service related handlers.
@@ -73,10 +72,9 @@ func serviceFind(b biz.ServiceBiz) web.HandlerFunc {
status := ctx.Query("status") == "true"
service, raw, err := b.Find(name, status)
if err != nil {
if docker.IsErrNotFound(err) {
return web.NewError(http.StatusNotFound, err.Error())
}
return err
} else if service == nil {
return web.NewError(http.StatusNotFound)
}
return success(ctx, data.Map{"service": service, "raw": raw})
}
@@ -153,6 +151,7 @@ func serviceSave(b biz.ServiceBiz) web.HandlerFunc {
func serviceDeploy(b biz.ServiceBiz) web.HandlerFunc {
return func(ctx web.Context) error {
//mode := ctx.Query("mode") // update/replace
service := &biz.Service{}
err := ctx.Bind(service, true)
if err != nil {

View File

@@ -6,7 +6,6 @@ import (
"github.com/cuigh/auxo/data"
"github.com/cuigh/auxo/net/web"
"github.com/cuigh/swirl/biz"
"github.com/cuigh/swirl/docker"
)
// TaskHandler encapsulates node related handlers.
@@ -60,10 +59,9 @@ func taskFind(b biz.TaskBiz) web.HandlerFunc {
id := ctx.Query("id")
task, raw, err := b.Find(id)
if err != nil {
if docker.IsErrNotFound(err) {
return web.NewError(http.StatusNotFound, err.Error())
}
return err
} else if task == nil {
return web.NewError(http.StatusNotFound)
}
return success(ctx, data.Map{"task": task, "raw": raw})
}