Skip to content

Commit cb764a2

Browse files
committed
debug
1 parent 6a437b3 commit cb764a2

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

cmd/extensions.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7+
"log/slog"
78
"os"
89
"path/filepath"
910
"sort"
1011
"strconv"
1112
"strings"
1213

1314
"charm.land/lipgloss/v2"
15+
"github.com/kballard/go-shellquote"
1416
"github.com/libops/sitectl/pkg/config"
1517
"github.com/libops/sitectl/pkg/docker"
1618
"github.com/libops/sitectl/pkg/plugin"
@@ -112,20 +114,25 @@ func init() {
112114
}
113115

114116
func renderDrupalDebug() (string, error) {
117+
slog.Debug("starting plugin debug", "plugin", "drupal")
115118
if sdk == nil {
116119
return "", fmt.Errorf("plugin sdk is not initialized")
117120
}
118121
ctx, err := sdk.GetContext()
119122
if err != nil {
120123
return "", err
121124
}
125+
slog.Debug("resolved plugin context", "plugin", "drupal", "context", ctx.Name, "project_dir", ctx.ProjectDir)
126+
slog.Debug("creating file accessor", "plugin", "drupal")
122127
files, err := plugin.NewFileAccessor(ctx)
123128
if err != nil {
124129
return "", err
125130
}
126131
defer files.Close()
127132

133+
slog.Debug("resolving drupal root", "plugin", "drupal", "rootfs", drupalRootfsPath)
128134
drupalRoot := resolveDrupalRoot(files, ctx.ProjectDir, drupalRootfsPath)
135+
slog.Debug("resolved drupal root", "plugin", "drupal", "drupal_root", drupalRoot)
129136
configDir := filepath.Join(drupalRoot, "config", "sync")
130137
body := []string{
131138
debugDivider(),
@@ -141,14 +148,18 @@ func renderDrupalDebug() (string, error) {
141148
}
142149

143150
if strings.TrimSpace(drupalRoot) == "" {
151+
slog.Debug("drupal root unavailable; skipping extension scan", "plugin", "drupal")
144152
body = append(body, "", "Installed modules: unavailable")
145153
return renderDebugPanel("drupal", strings.Join(body, "\n")), nil
146154
}
147155

156+
slog.Debug("reading core.extension.yml", "plugin", "drupal", "path", filepath.Join(configDir, "core.extension.yml"))
148157
modules, themes, err := readCoreExtension(files, filepath.Join(configDir, "core.extension.yml"))
149158
if err != nil {
150159
return "", err
151160
}
161+
slog.Debug("read installed extensions", "plugin", "drupal", "modules", len(modules), "themes", len(themes))
162+
slog.Debug("rendering cache_page summary", "plugin", "drupal")
152163
cachePageSummary, err := renderCachePageSummary()
153164
if err != nil {
154165
body = append(body, "", debugDivider(), "", debugTitleStyle.Render("Cache Page"), "", formatDebugRows([]debugRow{
@@ -166,6 +177,7 @@ func renderDrupalDebug() (string, error) {
166177
configLines = append(configLines, formatListLines(themes, 3)...)
167178
body = append(body, "", strings.Join(configLines, "\n"))
168179

180+
slog.Debug("finished plugin debug", "plugin", "drupal")
169181
return renderDebugPanel("drupal", strings.Join(body, "\n")), nil
170182
}
171183

@@ -177,7 +189,7 @@ func renderCachePageSummary() (string, error) {
177189
defer cli.Close()
178190

179191
query := "SELECT COALESCE(data_length + index_length, 0) FROM information_schema.TABLES WHERE table_schema = DATABASE() AND table_name = 'cache_page';"
180-
output, err := execDrupalCommandCapture(cli, containerName, []string{"drush", "sql:query", query, "--extra=--batch --skip-column-names"})
192+
output, err := execDrupalCommandCapture(cli, containerName, []string{"drush", "sql:query", query, "--extra=--batch", "--extra=--skip-column-names"})
181193
if err != nil {
182194
return "", err
183195
}
@@ -223,12 +235,16 @@ func getDrupalContainerForSDK() (ctx *config.Context, cli *docker.DockerClient,
223235
}
224236

225237
func execDrupalCommandCapture(cli *docker.DockerClient, containerName string, cmd []string) (string, error) {
238+
slog.Debug(strings.Join(cmd, " "), "plugin", "drupal", "container", containerName)
226239
var stdout bytes.Buffer
227240
var stderr bytes.Buffer
228241

242+
wrappedCmd := []string{"bash", "-lc", fmt.Sprintf("cd /var/www/drupal && %s", shellquote.Join(cmd...))}
243+
229244
exitCode, err := cli.Exec(context.Background(), docker.ExecOptions{
230245
Container: containerName,
231-
Cmd: cmd,
246+
Cmd: wrappedCmd,
247+
WorkingDir: "/var/www/drupal",
232248
AttachStdout: true,
233249
AttachStderr: true,
234250
Stdout: &stdout,

0 commit comments

Comments
 (0)