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

@ -6,6 +6,7 @@
* feat: Refactor UI with vue3.
* feat: Add support to agent. Swirl can connect to any container even in swarm mode now.
* feat: Support token authentication.
* feat: Switch to official MongoDB driver.
* feat: Allow set chart margins.
* fix: Some args are incorrect when generating service command line.

View File

@ -60,7 +60,6 @@ web:
swirl:
db_type: mongo
db_address: mongodb://localhost:27017/swirl
# token_key: 80fe9a6d5c6d5dd39f27cd37a77faf8a
# token_expiry: 30m
# docker_api_version: '1.41'
# docker_endpoint: tcp://docker-proxy:2375

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})
}

View File

@ -37,11 +37,15 @@ func (b *containerBiz) Find(node, id string) (c *Container, raw string, err erro
r []byte
)
if cj, r, err = b.d.ContainerInspect(context.TODO(), node, id); err == nil {
raw, err = indentJSON(r)
cj, r, err = b.d.ContainerInspect(context.TODO(), node, id)
if err != nil {
if docker.IsErrNotFound(err) {
err = nil
}
return
}
if err == nil {
if raw, err = indentJSON(r); err == nil {
c = newContainerDetail(&cj)
}
return

View File

@ -50,7 +50,15 @@ func (b *serviceBiz) Find(name string, status bool) (service *Service, raw strin
s swarm.Service
r []byte
)
s, r, err = b.d.ServiceInspect(context.TODO(), name, status)
if err != nil {
if docker.IsErrNotFound(err) {
err = nil
}
return
}
if err == nil {
raw, err = indentJSON(r)
}

View File

@ -30,10 +30,14 @@ func (b *taskBiz) Find(id string) (task *Task, raw string, err error) {
)
t, r, err = b.d.TaskInspect(context.TODO(), id)
if err == nil {
raw, err = indentJSON(r)
if err != nil {
if docker.IsErrNotFound(err) {
err = nil
}
return
}
raw, err = indentJSON(r)
if err == nil {
m, _ := b.d.NodeMap()
task = newTask(&t, m)