support viewing docker compose config from status panel

This commit is contained in:
Jesse Duffield 2019-06-09 12:50:17 +10:00
parent d81c407dd2
commit 84090bcb94
4 changed files with 47 additions and 42 deletions

View file

@ -401,3 +401,12 @@ func (c *DockerCommand) ViewAllLogs() (*exec.Cmd, error) {
return cmd, nil
}
// DockerComposeConfig returns the result of 'docker-compose config'
func (c *DockerCommand) DockerComposeConfig() string {
output, err := c.OSCommand.RunCommandWithOutput(c.OSCommand.Config.UserConfig.CommandTemplates.DockerComposeConfig)
if err != nil {
output = err.Error()
}
return output
}

View file

@ -110,11 +110,12 @@ type CommandTemplatesConfig struct {
RebuildService string `yaml:"rebuildService,omitempty"`
// ViewContainerLogs is for viewing the container logs in a subprocess. We have this as a separate command in case you want to show all the logs rather than just tail them for the sake of reducing CPU load when in the lazydocker GUI
ViewContainerLogs string `yaml:"viewContainerLogs,omitempty"`
ContainerLogs string `yaml:"containerLogs,omitempty"`
ContainerTTYLogs string `yaml:"containerTTYLogs,omitempty"`
AllLogs string `yaml:"allLogs,omitempty"`
ViewAllLogs string `yaml:"viewAlLogs,omitempty"`
ViewContainerLogs string `yaml:"viewContainerLogs,omitempty"`
ContainerLogs string `yaml:"containerLogs,omitempty"`
ContainerTTYLogs string `yaml:"containerTTYLogs,omitempty"`
AllLogs string `yaml:"allLogs,omitempty"`
ViewAllLogs string `yaml:"viewAlLogs,omitempty"`
DockerComposeConfig string `yaml:"dockerComposeConfig,omitempty"`
}
type OSConfig struct {
@ -162,16 +163,17 @@ func GetDefaultConfig() UserConfig {
Reporting: "undetermined",
ConfirmOnQuit: false,
CommandTemplates: CommandTemplatesConfig{
RestartService: "docker-compose restart {{ .Name }}",
RebuildService: "docker-compose up -d --build {{ .Name }}",
DockerCompose: "apdev compose",
StopService: "apdev stop {{ .Name }}",
ServiceLogs: "apdev logs {{ .Name }}",
ContainerLogs: "docker logs --timestamps --follow --tail=100 {{ .ID }}",
ViewContainerLogs: "docker logs --timestamps --follow --tail=100 {{ .ID }}",
ContainerTTYLogs: "docker logs --follow --tail=100 {{ .ID }}",
AllLogs: "apdev logs --tail=100",
ViewAllLogs: "apdev logs",
RestartService: "docker-compose restart {{ .Name }}",
RebuildService: "docker-compose up -d --build {{ .Name }}",
DockerCompose: "apdev compose",
StopService: "apdev stop {{ .Name }}",
ServiceLogs: "apdev logs {{ .Name }}",
ContainerLogs: "docker logs --timestamps --follow --tail=100 {{ .ID }}",
ViewContainerLogs: "docker logs --timestamps --follow --tail=100 {{ .ID }}",
ContainerTTYLogs: "docker logs --follow --tail=100 {{ .ID }}",
AllLogs: "apdev logs --tail=100",
ViewAllLogs: "apdev logs",
DockerComposeConfig: "apdev compose config",
},
OS: GetPlatformDefaultConfig(),
Update: UpdateConfig{

View file

@ -1,7 +1,6 @@
package gui
import (
"encoding/json"
"fmt"
"github.com/fatih/color"
@ -14,11 +13,11 @@ import (
// list panel functions
func (gui *Gui) getServiceContexts() []string {
return []string{"logs", "stats", "config", "container-config"}
return []string{"logs", "stats", "container-config"}
}
func (gui *Gui) getServiceContextTitles() []string {
return []string{gui.Tr.LogsTitle, gui.Tr.StatsTitle, gui.Tr.ConfigTitle, gui.Tr.ContainerConfigTitle}
return []string{gui.Tr.LogsTitle, gui.Tr.StatsTitle, gui.Tr.ContainerConfigTitle}
}
func (gui *Gui) getSelectedService() (*commands.Service, error) {
@ -85,10 +84,6 @@ func (gui *Gui) handleServiceSelect(g *gocui.Gui, v *gocui.View) error {
if err := gui.renderServiceLogs(service); err != nil {
return err
}
case "config":
if err := gui.renderServiceConfig(service); err != nil {
return err
}
case "stats":
if err := gui.renderServiceStats(service); err != nil {
return err
@ -107,24 +102,6 @@ func (gui *Gui) handleServiceSelect(g *gocui.Gui, v *gocui.View) error {
return nil
}
func (gui *Gui) renderServiceConfig(service *commands.Service) error {
mainView := gui.getMainView()
mainView.Autoscroll = false
mainView.Wrap = true
go gui.T.NewTask(func(stop chan struct{}) {
// TODO: actually show service config
data, err := json.MarshalIndent(&service.Container.Container, "", " ")
if err != nil {
gui.Log.Error(err)
return
}
gui.renderString(gui.g, "main", string(data))
})
return nil
}
func (gui *Gui) renderServiceStats(service *commands.Service) error {
if service.Container == nil {
return nil

View file

@ -9,11 +9,11 @@ import (
)
func (gui *Gui) getStatusContexts() []string {
return []string{"logs", "credits"}
return []string{"logs", "credits", "config"}
}
func (gui *Gui) getStatusContextTitles() []string {
return []string{gui.Tr.LogsTitle, gui.Tr.CreditsTitle}
return []string{gui.Tr.LogsTitle, gui.Tr.CreditsTitle, gui.Tr.ConfigTitle}
}
func (gui *Gui) refreshStatus() error {
@ -59,6 +59,10 @@ func (gui *Gui) handleStatusSelect(g *gocui.Gui, v *gocui.View) error {
if err := gui.renderAllLogs(); err != nil {
return err
}
case "config":
if err := gui.renderDockerComposeConfig(); err != nil {
return err
}
default:
return errors.New("Unknown context for status panel")
}
@ -116,6 +120,19 @@ func (gui *Gui) renderAllLogs() error {
return nil
}
func (gui *Gui) renderDockerComposeConfig() error {
mainView := gui.getMainView()
mainView.Autoscroll = false
mainView.Wrap = true
go gui.T.NewTask(func(stop chan struct{}) {
config := gui.DockerCommand.DockerComposeConfig()
gui.renderString(gui.g, "main", config)
})
return nil
}
func (gui *Gui) handleOpenConfig(g *gocui.Gui, v *gocui.View) error {
return gui.openFile(gui.Config.ConfigFilename())
}