Skip to content

Commit

Permalink
adds agent test
Browse files Browse the repository at this point in the history
  • Loading branch information
amir20 committed Nov 15, 2024
1 parent b06078d commit bcb7e4c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ FROM --platform=$BUILDPLATFORM golang:1.23.3-alpine AS builder

# install gRPC dependencies
RUN apk add --no-cache ca-certificates protoc protobuf-dev\
&& mkdir /dozzle \
&& go install google.golang.org/protobuf/cmd/protoc-gen-go@latest \
&& go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
&& mkdir /dozzle \
&& go install google.golang.org/protobuf/cmd/protoc-gen-go@latest \
&& go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

WORKDIR /dozzle

Expand Down
2 changes: 1 addition & 1 deletion examples/docker.swarm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
environment:
- DOZZLE_LEVEL=debug
- DOZZLE_MODE=swarm
- DOZZLE_REMOTE_AGENT=198.19.248.6:7070
- DOZZLE_REMOTE_AGENT=198.19.248.6:7007
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ports:
Expand Down
5 changes: 5 additions & 0 deletions internal/support/cli/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Args struct {
Healthcheck *HealthcheckCmd `arg:"subcommand:healthcheck" help:"checks if the server is running"`
Generate *GenerateCmd `arg:"subcommand:generate" help:"generates a configuration file for simple auth"`
Agent *AgentCmd `arg:"subcommand:agent" help:"starts the agent"`
AgentTest *AgentTestCmd `arg:"subcommand:agent-test" help:"tests an agent"`
}

type HealthcheckCmd struct {
Expand All @@ -40,6 +41,10 @@ type AgentCmd struct {
Addr string `arg:"env:DOZZLE_AGENT_ADDR" default:":7007" help:"sets the host:port to bind for the agent"`
}

type AgentTestCmd struct {
Address string `arg:"positional"`
}

type GenerateCmd struct {
Username string `arg:"positional"`
Password string `arg:"--password, -p" help:"sets the password for the user"`
Expand Down
18 changes: 18 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,24 @@ func main() {
if _, err := os.Stdout.Write(buffer.Bytes()); err != nil {
log.Fatal().Err(err).Msg("Failed to write to stdout")
}

case *cli.AgentTestCmd:
certs, err := cli.ReadCertificates(certs)
if err != nil {
log.Fatal().Err(err).Msg("Could not read certificates")
}

log.Info().Str("endpoint", args.AgentTest.Address).Msg("Connecting to agent")

agent, err := agent.NewClient(args.AgentTest.Address, certs)

Check failure on line 138 in main.go

View workflow job for this annotation

GitHub Actions / Go Staticcheck

this value of err is never used (SA4006)
ctx, cancel := context.WithTimeout(context.Background(), args.Timeout)
defer cancel()
host, err := agent.Host(ctx)
if err != nil {
log.Fatal().Err(err).Str("endpoint", args.AgentTest.Address).Msg("error fetching host info for agent")
}

log.Info().Str("endpoint", args.AgentTest.Address).Str("version", host.AgentVersion).Str("name", host.Name).Str("id", host.ID).Msg("Successfully connected to agent")
}

os.Exit(0)
Expand Down

0 comments on commit bcb7e4c

Please sign in to comment.