Skip to content

Commit 7163603

Browse files
committed
feat(mount on services)
1 parent 9d9f850 commit 7163603

9 files changed

Lines changed: 792 additions & 27 deletions

File tree

internal/dao/docker.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,23 @@ import (
2020
clicontext "github.com/docker/cli/cli/context"
2121
"github.com/docker/cli/cli/context/docker"
2222
dcontainer "github.com/docker/docker/api/types/container"
23+
"github.com/docker/docker/api/types/mount"
2324
"github.com/docker/docker/api/types/swarm"
2425
"github.com/docker/docker/client"
2526
"github.com/jr-k/d4s/internal/dao/common"
2627
"github.com/jr-k/d4s/internal/dao/compose"
2728
"github.com/jr-k/d4s/internal/dao/docker/container"
29+
"github.com/jr-k/d4s/internal/dao/docker/dconfig"
2830
"github.com/jr-k/d4s/internal/dao/docker/image"
2931
"github.com/jr-k/d4s/internal/dao/docker/network"
30-
"github.com/jr-k/d4s/internal/dao/docker/dconfig"
3132
"github.com/jr-k/d4s/internal/dao/docker/secret"
3233
"github.com/jr-k/d4s/internal/dao/docker/stack"
3334
"github.com/jr-k/d4s/internal/dao/docker/volume"
3435
"github.com/jr-k/d4s/internal/dao/swarm/node"
3536
"github.com/jr-k/d4s/internal/dao/swarm/service"
37+
"github.com/jr-k/d4s/internal/dao/swarm/task"
3638
"github.com/jr-k/d4s/internal/secrets"
3739
"github.com/jr-k/d4s/internal/sshutil"
38-
"github.com/jr-k/d4s/internal/dao/swarm/task"
3940
)
4041

4142
// Re-export types for backward compatibility / convenience
@@ -1002,6 +1003,14 @@ func (d *DockerClient) SetServiceNetworks(id string, networks []swarm.NetworkAtt
10021003
return d.Service.SetNetworks(id, networks)
10031004
}
10041005

1006+
func (d *DockerClient) GetServiceMounts(id string) ([]mount.Mount, error) {
1007+
return d.Service.GetMounts(id)
1008+
}
1009+
1010+
func (d *DockerClient) SetServiceMounts(id string, mounts []mount.Mount) error {
1011+
return d.Service.SetMounts(id, mounts)
1012+
}
1013+
10051014
func (d *DockerClient) ListServicesForSecret(secretID string) ([]common.Resource, error) {
10061015
services, err := d.Service.List()
10071016
if err != nil {

internal/dao/swarm/service/service.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
dt "github.com/docker/docker/api/types"
1010
"github.com/docker/docker/api/types/container"
1111
"github.com/docker/docker/api/types/filters"
12+
"github.com/docker/docker/api/types/mount"
1213
"github.com/docker/docker/api/types/swarm"
1314
"github.com/docker/docker/client"
1415
"github.com/gdamore/tcell/v2"
@@ -147,7 +148,7 @@ func (m *Manager) List() ([]common.Resource, error) {
147148
if idx := strings.LastIndex(imageName, "@"); idx != -1 {
148149
imageName = imageName[:idx]
149150
}
150-
151+
151152
// Style tag
152153
if idx := strings.LastIndex(imageName, ":"); idx != -1 {
153154
tag := imageName[idx:]
@@ -182,7 +183,7 @@ func (m *Manager) Scale(id string, replicas uint64) error {
182183
}
183184

184185
service.Spec.Mode.Replicated.Replicas = &replicas
185-
186+
186187
// Update
187188
_, err = m.cli.ServiceUpdate(m.ctx, id, service.Version, service.Spec, swarm.ServiceUpdateOptions{})
188189
return err
@@ -333,6 +334,19 @@ func (m *Manager) GetNetworks(id string) ([]swarm.NetworkAttachmentConfig, error
333334
return service.Spec.TaskTemplate.Networks, nil
334335
}
335336

337+
func (m *Manager) GetMounts(id string) ([]mount.Mount, error) {
338+
service, _, err := m.cli.ServiceInspectWithRaw(m.ctx, id, swarm.ServiceInspectOptions{})
339+
if err != nil {
340+
return nil, err
341+
}
342+
343+
if service.Spec.TaskTemplate.ContainerSpec == nil {
344+
return []mount.Mount{}, nil
345+
}
346+
347+
return service.Spec.TaskTemplate.ContainerSpec.Mounts, nil
348+
}
349+
336350
func (m *Manager) ListTasks(serviceID string) ([]swarm.Task, error) {
337351
filter := filters.NewArgs()
338352
filter.Add("service", serviceID)
@@ -351,3 +365,19 @@ func (m *Manager) SetNetworks(id string, networks []swarm.NetworkAttachmentConfi
351365
_, err = m.cli.ServiceUpdate(m.ctx, id, service.Version, service.Spec, swarm.ServiceUpdateOptions{})
352366
return err
353367
}
368+
369+
func (m *Manager) SetMounts(id string, mounts []mount.Mount) error {
370+
service, _, err := m.cli.ServiceInspectWithRaw(m.ctx, id, swarm.ServiceInspectOptions{})
371+
if err != nil {
372+
return err
373+
}
374+
375+
if service.Spec.TaskTemplate.ContainerSpec == nil {
376+
return fmt.Errorf("service has no container spec")
377+
}
378+
379+
service.Spec.TaskTemplate.ContainerSpec.Mounts = mounts
380+
381+
_, err = m.cli.ServiceUpdate(m.ctx, id, service.Version, service.Spec, swarm.ServiceUpdateOptions{})
382+
return err
383+
}

internal/ui/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ func (a *App) initUI() {
485485
// Don't intercept global keys if a modal/dialog is open
486486
frontPage, _ := a.Pages.GetFrontPage()
487487
switch frontPage {
488-
case "input", "confirm", "form", "picker", "env_editor", "textview", "result", "portforward":
488+
case "input", "confirm", "form", "picker", "env_editor", "secret_editor", "mount_editor", "mount_type_picker", "textview", "result", "portforward":
489489
return event
490490
}
491491

internal/ui/dialogs/env_editor.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func ShowEnvEditor(app common.AppController, subject string, items []EnvItem, on
121121
content += fmt.Sprintf("%s%s %s[-]\n", color, checkbox, display)
122122
}
123123
list.SetText(content)
124+
list.ScrollTo(currentIndex, 0)
124125
}
125126
updateList()
126127

@@ -139,7 +140,7 @@ func ShowEnvEditor(app common.AppController, subject string, items []EnvItem, on
139140
// Separator
140141
separator := tview.NewTextView().
141142
SetDynamicColors(true).
142-
SetText("[" + styles.TagDim + "]" + strings.Repeat("─", 66) + "[-]").
143+
SetText("[" + styles.TagDim + "]" + strings.Repeat("─", 50) + "[-]").
143144
SetTextAlign(tview.AlignCenter)
144145
separator.SetBackgroundColor(styles.ColorBlack)
145146

@@ -285,7 +286,7 @@ func ShowEnvEditor(app common.AppController, subject string, items []EnvItem, on
285286
setFocus(1)
286287
return nil
287288
}
288-
if event.Key() == tcell.KeyBacktab {
289+
if event.Key() == tcell.KeyBacktab || event.Key() == tcell.KeyUp {
289290
if len(items) > 0 {
290291
setFocus(3)
291292
}
@@ -307,7 +308,7 @@ func ShowEnvEditor(app common.AppController, subject string, items []EnvItem, on
307308
setFocus(2)
308309
return nil
309310
}
310-
if event.Key() == tcell.KeyBacktab {
311+
if event.Key() == tcell.KeyBacktab || event.Key() == tcell.KeyUp {
311312
setFocus(0)
312313
return nil
313314
}
@@ -331,7 +332,7 @@ func ShowEnvEditor(app common.AppController, subject string, items []EnvItem, on
331332
}
332333
return nil
333334
}
334-
if event.Key() == tcell.KeyBacktab {
335+
if event.Key() == tcell.KeyBacktab || event.Key() == tcell.KeyUp {
335336
setFocus(1)
336337
return nil
337338
}
@@ -399,6 +400,9 @@ func ShowEnvEditor(app common.AppController, subject string, items []EnvItem, on
399400
case tcell.KeyBacktab:
400401
setFocus(3)
401402
return nil
403+
case tcell.KeyUp:
404+
setFocus(3)
405+
return nil
402406
}
403407
return event
404408
})

0 commit comments

Comments
 (0)