diff --git a/Dockerfile b/Dockerfile index 57ecf06b..a2941a29 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,6 +61,7 @@ RUN mkdir /data FROM scratch COPY --from=builder /data /data +COPY --from=builder /tmp /tmp COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt COPY --from=builder /dozzle/dozzle /dozzle diff --git a/internal/support/cli/agent_command.go b/internal/support/cli/agent_command.go index 428437bd..a17a0f53 100644 --- a/internal/support/cli/agent_command.go +++ b/internal/support/cli/agent_command.go @@ -15,7 +15,6 @@ import ( "github.com/rs/zerolog/log" ) - type AgentCmd struct { Addr string `arg:"--agent-addr,env:DOZZLE_AGENT_ADDR" default:":7007" help:"sets the host:port to bind for the agent"` } @@ -37,11 +36,12 @@ func (a *AgentCmd) Run(args Args, embeddedCerts embed.FS) error { if err != nil { return fmt.Errorf("failed to listen: %w", err) } - tempFile, err := os.CreateTemp("./", "agent-*.addr") + tempFile, err := os.CreateTemp("", "agent-*.addr") if err != nil { return fmt.Errorf("failed to create temp file: %w", err) } io.WriteString(tempFile, listener.Addr().String()) + log.Debug().Str("file", tempFile.Name()).Msg("Created temp file") go StartEvent(args, "", client, "agent") server, err := agent.NewServer(client, certs, args.Version(), args.Filter) if err != nil { diff --git a/internal/support/cli/health_command.go b/internal/support/cli/health_command.go index 02cc3127..4f3b17a5 100644 --- a/internal/support/cli/health_command.go +++ b/internal/support/cli/health_command.go @@ -8,43 +8,29 @@ import ( "path/filepath" "github.com/amir20/dozzle/internal/healthcheck" + "github.com/rs/zerolog/log" ) type HealthcheckCmd struct { } func (h *HealthcheckCmd) Run(args Args, embeddedCerts embed.FS) error { - files, err := os.ReadDir(".") - if err != nil { - return fmt.Errorf("failed to read directory: %w", err) - } - - agentAddress := "" - for _, file := range files { - if match, _ := filepath.Match("agent-*.addr", file.Name()); match { - data, err := os.ReadFile(file.Name()) - if err != nil { - return fmt.Errorf("failed to read file: %w", err) - } - agentAddress = string(data) - break + if matches, err := filepath.Glob("/tmp/agent-*.addr"); err == nil && len(matches) == 1 { + data, err := os.ReadFile(matches[0]) + if err != nil { + return fmt.Errorf("failed to read file: %w", err) } - } - if agentAddress == "" { - if err := healthcheck.HttpRequest(args.Addr, args.Base); err != nil { - return fmt.Errorf("failed to make request: %w", err) - } - } else { + agentAddress := string(data) certs, err := ReadCertificates(embeddedCerts) if err != nil { return fmt.Errorf("failed to read certificates: %w", err) } ctx, cancel := context.WithTimeout(context.Background(), args.Timeout) defer cancel() - if err := healthcheck.RPCRequest(ctx, agentAddress, certs); err != nil { - return fmt.Errorf("failed to make request: %w", err) - } + log.Info().Str("address", agentAddress).Msg("Making RPC request to agent") + return healthcheck.RPCRequest(ctx, agentAddress, certs) + } else { + log.Info().Str("address", args.Addr).Str("base", args.Base).Msg("Making HTTP request to server") + return healthcheck.HttpRequest(args.Addr, args.Base) } - - return nil }