1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-21 13:23:07 +01:00

fix: Use /tmp instead of ./ to ensure that user permissions can be mounted correctly. (#3797)

This commit is contained in:
Amir Raminfar
2025-04-12 13:44:21 -07:00
committed by GitHub
parent f35c472088
commit b33ae4fa4e
3 changed files with 14 additions and 27 deletions

View File

@@ -61,6 +61,7 @@ RUN mkdir /data
FROM scratch FROM scratch
COPY --from=builder /data /data 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 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /dozzle/dozzle /dozzle COPY --from=builder /dozzle/dozzle /dozzle

View File

@@ -15,7 +15,6 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
type AgentCmd struct { type AgentCmd struct {
Addr string `arg:"--agent-addr,env:DOZZLE_AGENT_ADDR" default:":7007" help:"sets the host:port to bind for the agent"` 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 { if err != nil {
return fmt.Errorf("failed to listen: %w", err) return fmt.Errorf("failed to listen: %w", err)
} }
tempFile, err := os.CreateTemp("./", "agent-*.addr") tempFile, err := os.CreateTemp("", "agent-*.addr")
if err != nil { if err != nil {
return fmt.Errorf("failed to create temp file: %w", err) return fmt.Errorf("failed to create temp file: %w", err)
} }
io.WriteString(tempFile, listener.Addr().String()) io.WriteString(tempFile, listener.Addr().String())
log.Debug().Str("file", tempFile.Name()).Msg("Created temp file")
go StartEvent(args, "", client, "agent") go StartEvent(args, "", client, "agent")
server, err := agent.NewServer(client, certs, args.Version(), args.Filter) server, err := agent.NewServer(client, certs, args.Version(), args.Filter)
if err != nil { if err != nil {

View File

@@ -8,43 +8,29 @@ import (
"path/filepath" "path/filepath"
"github.com/amir20/dozzle/internal/healthcheck" "github.com/amir20/dozzle/internal/healthcheck"
"github.com/rs/zerolog/log"
) )
type HealthcheckCmd struct { type HealthcheckCmd struct {
} }
func (h *HealthcheckCmd) Run(args Args, embeddedCerts embed.FS) error { func (h *HealthcheckCmd) Run(args Args, embeddedCerts embed.FS) error {
files, err := os.ReadDir(".") if matches, err := filepath.Glob("/tmp/agent-*.addr"); err == nil && len(matches) == 1 {
if err != nil { data, err := os.ReadFile(matches[0])
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 { if err != nil {
return fmt.Errorf("failed to read file: %w", err) return fmt.Errorf("failed to read file: %w", err)
} }
agentAddress = string(data) agentAddress := string(data)
break
}
}
if agentAddress == "" {
if err := healthcheck.HttpRequest(args.Addr, args.Base); err != nil {
return fmt.Errorf("failed to make request: %w", err)
}
} else {
certs, err := ReadCertificates(embeddedCerts) certs, err := ReadCertificates(embeddedCerts)
if err != nil { if err != nil {
return fmt.Errorf("failed to read certificates: %w", err) return fmt.Errorf("failed to read certificates: %w", err)
} }
ctx, cancel := context.WithTimeout(context.Background(), args.Timeout) ctx, cancel := context.WithTimeout(context.Background(), args.Timeout)
defer cancel() defer cancel()
if err := healthcheck.RPCRequest(ctx, agentAddress, certs); err != nil { log.Info().Str("address", agentAddress).Msg("Making RPC request to agent")
return fmt.Errorf("failed to make request: %w", err) 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
} }