first commit
This commit is contained in:
commit
0a1511bcbc
5 changed files with 635 additions and 0 deletions
32
Dockerfile
Normal file
32
Dockerfile
Normal file
|
@ -0,0 +1,32 @@
|
|||
# Use the official Golang image to build the application
|
||||
FROM golang:1.23 AS builder
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the Go modules manifests
|
||||
COPY go.mod go.sum ./
|
||||
|
||||
# Download Go modules
|
||||
RUN go mod download
|
||||
|
||||
# Copy the source code
|
||||
COPY . .
|
||||
|
||||
# Build the Go application
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -o main .
|
||||
|
||||
# Use a minimal image for the final container
|
||||
FROM alpine:latest
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /root/
|
||||
|
||||
# Copy the compiled Go binary from the builder stage
|
||||
COPY --from=builder /app/main .
|
||||
|
||||
# Expose the port the application runs on
|
||||
EXPOSE 8080
|
||||
|
||||
# Command to run the executable
|
||||
CMD ["./main"]
|
56
README.md
Normal file
56
README.md
Normal file
|
@ -0,0 +1,56 @@
|
|||
# Docker Network Graph Go
|
||||
|
||||
Dieses Projekt erstellt eine visuelle Darstellung von Docker-Netzwerken und Containern.
|
||||
|
||||
## Voraussetzungen
|
||||
|
||||
- Linux-System (vorzugsweise ARM64-Architektur)
|
||||
- Docker
|
||||
- Internetverbindung
|
||||
|
||||
## Installation und Einrichtung
|
||||
|
||||
1. Go 1.23.4 herunterladen und installieren:
|
||||
|
||||
```bash
|
||||
wget https://go.dev/dl/go1.23.4.linux-arm64.tar.gz
|
||||
sudo tar -C /usr/local -xzf go1.23.4.linux-arm64.tar.gz
|
||||
export PATH=$PATH:/usr/local/go/bin
|
||||
```
|
||||
|
||||
2. Überprüfen Sie die Go-Installation:
|
||||
|
||||
```bash
|
||||
go version
|
||||
```
|
||||
|
||||
3. Klonen Sie das Repository:
|
||||
|
||||
```bash
|
||||
git clone https://code.brothertec.eu/simono41/docker-network-graph-go.git
|
||||
cd docker-network-graph-go
|
||||
```
|
||||
|
||||
4. Bauen Sie das Docker-Image:
|
||||
|
||||
```bash
|
||||
docker build -t code.brothertec.eu/simono41/docker-network-graph-go:latest .
|
||||
```
|
||||
|
||||
## Verwendung
|
||||
|
||||
Führen Sie den Container aus, um die Docker-Netzwerkgrafik zu generieren:
|
||||
|
||||
```bash
|
||||
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock code.brothertec.eu/simono41/docker-network-graph-go:latest
|
||||
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock code.brothertec.eu/simono41/docker-network-graph:latest | dot -Tsvg -o /opt/containers/picture-uploader/uploads/network.svg
|
||||
```
|
||||
|
||||
## Hinweise
|
||||
|
||||
- Stellen Sie sicher, dass Sie die neueste Version von Docker installiert haben.
|
||||
- Für die Ausführung des Containers sind Root-Rechte oder Mitgliedschaft in der Docker-Gruppe erforderlich.
|
||||
- Die generierte Grafik wird standardmäßig auf der Konsole ausgegeben. Verwenden Sie Umleitungen, um die Ausgabe in eine Datei zu speichern.
|
||||
|
||||
Citations:
|
||||
[1] https://go.dev/dl/go1.23.4.linux-arm64.tar.gz
|
43
go.mod
Normal file
43
go.mod
Normal file
|
@ -0,0 +1,43 @@
|
|||
module docker-network-graph-go
|
||||
|
||||
go 1.23.4
|
||||
|
||||
require (
|
||||
github.com/docker/docker v27.3.1+incompatible
|
||||
github.com/goccy/go-graphviz v0.2.9
|
||||
golang.org/x/net v0.32.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Microsoft/go-winio v0.4.14 // indirect
|
||||
github.com/containerd/log v0.1.0 // indirect
|
||||
github.com/disintegration/imaging v1.6.2 // indirect
|
||||
github.com/distribution/reference v0.6.0 // indirect
|
||||
github.com/docker/go-connections v0.5.0 // indirect
|
||||
github.com/docker/go-units v0.5.0 // indirect
|
||||
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||
github.com/flopp/go-findfont v0.1.0 // indirect
|
||||
github.com/fogleman/gg v1.3.0 // indirect
|
||||
github.com/go-logr/logr v1.4.2 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||
github.com/moby/docker-image-spec v1.3.1 // indirect
|
||||
github.com/moby/term v0.5.0 // indirect
|
||||
github.com/morikuni/aec v1.0.0 // indirect
|
||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||
github.com/opencontainers/image-spec v1.1.0 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/tetratelabs/wazero v1.8.1 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0 // indirect
|
||||
go.opentelemetry.io/otel v1.32.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.32.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.32.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.32.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.32.0 // indirect
|
||||
golang.org/x/image v0.21.0 // indirect
|
||||
golang.org/x/sys v0.28.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
golang.org/x/time v0.8.0 // indirect
|
||||
gotest.tools/v3 v3.5.1 // indirect
|
||||
)
|
142
go.sum
Normal file
142
go.sum
Normal file
|
@ -0,0 +1,142 @@
|
|||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
|
||||
github.com/Microsoft/go-winio v0.4.14 h1:+hMXMk01us9KgxGb7ftKQt2Xpf5hH/yky+TDA+qxleU=
|
||||
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
|
||||
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
|
||||
github.com/corona10/goimagehash v1.1.0 h1:teNMX/1e+Wn/AYSbLHX8mj+mF9r60R1kBeqE9MkoYwI=
|
||||
github.com/corona10/goimagehash v1.1.0/go.mod h1:VkvE0mLn84L4aF8vCb6mafVajEb6QYMHl2ZJLn0mOGI=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c=
|
||||
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
|
||||
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
|
||||
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
|
||||
github.com/docker/docker v27.3.1+incompatible h1:KttF0XoteNTicmUtBO0L2tP+J7FGRFTjaEF4k6WdhfI=
|
||||
github.com/docker/docker v27.3.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
||||
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
|
||||
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
|
||||
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
|
||||
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
|
||||
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||
github.com/flopp/go-findfont v0.1.0 h1:lPn0BymDUtJo+ZkV01VS3661HL6F4qFlkhcJN55u6mU=
|
||||
github.com/flopp/go-findfont v0.1.0/go.mod h1:wKKxRDjD024Rh7VMwoU90i6ikQRCr+JTHB5n4Ejkqvw=
|
||||
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
|
||||
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/goccy/go-graphviz v0.2.9 h1:4yD2MIMpxNt+sOEARDh5jTE2S/jeAKi92w72B83mWGg=
|
||||
github.com/goccy/go-graphviz v0.2.9/go.mod h1:hssjl/qbvUXGmloY81BwXt2nqoApKo7DFgDj5dLJGb8=
|
||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 h1:ad0vkEBuk23VJzZR9nkLVG0YAoN9coASF1GusYX6AlU=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0/go.mod h1:igFoXX2ELCW06bol23DWPB5BEWfZISOzSP5K2sbLea0=
|
||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
|
||||
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
|
||||
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
|
||||
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
|
||||
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
|
||||
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
|
||||
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
|
||||
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
|
||||
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/tetratelabs/wazero v1.8.1 h1:NrcgVbWfkWvVc4UtT4LRLDf91PsOzDzefMdwhLfA550=
|
||||
github.com/tetratelabs/wazero v1.8.1/go.mod h1:yAI0XTsMBhREkM/YDAK/zNou3GoiAce1P6+rp/wQhjs=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0 h1:DheMAlT6POBP+gh8RUH19EOTnQIor5QE0uSRPtzCpSw=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0/go.mod h1:wZcGmeVO9nzP67aYSLDqXNWK87EZWhi7JWj1v7ZXf94=
|
||||
go.opentelemetry.io/otel v1.32.0 h1:WnBN+Xjcteh0zdk01SVqV55d/m62NJLJdIyb4y/WO5U=
|
||||
go.opentelemetry.io/otel v1.32.0/go.mod h1:00DCVSB0RQcnzlwyTfqtxSm+DRr9hpYrHjNGiBHVQIg=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0 h1:IJFEoHiytixx8cMiVAO+GmHR6Frwu+u5Ur8njpFO6Ac=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0/go.mod h1:3rHrKNtLIoS0oZwkY2vxi+oJcwFRWdtUyRII+so45p8=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.32.0 h1:cMyu9O88joYEaI47CnQkxO1XZdpoTF9fEnW2duIddhw=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.32.0/go.mod h1:6Am3rn7P9TVVeXYG+wtcGE7IE1tsQ+bP3AuWcKt/gOI=
|
||||
go.opentelemetry.io/otel/metric v1.32.0 h1:xV2umtmNcThh2/a/aCP+h64Xx5wsj8qqnkYZktzNa0M=
|
||||
go.opentelemetry.io/otel/metric v1.32.0/go.mod h1:jH7CIbbK6SH2V2wE16W05BHCtIDzauciCRLoc/SyMv8=
|
||||
go.opentelemetry.io/otel/sdk v1.32.0 h1:RNxepc9vK59A8XsgZQouW8ue8Gkb4jpWtJm9ge5lEG4=
|
||||
go.opentelemetry.io/otel/sdk v1.32.0/go.mod h1:LqgegDBjKMmb2GC6/PrTnteJG39I8/vJCAP9LlJXEjU=
|
||||
go.opentelemetry.io/otel/trace v1.32.0 h1:WIC9mYrXf8TmY/EXuULKc8hR17vE+Hjv2cssQDe03fM=
|
||||
go.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8=
|
||||
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
|
||||
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.21.0 h1:c5qV36ajHpdj4Qi0GnE0jUc/yuo33OLFaa0d+crTD5s=
|
||||
golang.org/x/image v0.21.0/go.mod h1:vUbsLavqK/W303ZroQQVKQ+Af3Yl6Uz1Ppu5J/cLz78=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
|
||||
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
|
||||
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
|
||||
golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 h1:M0KvPgPmDZHPlbRbaNU1APr28TvwvvdUPlSv7PUvy8g=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:dguCy7UOdZhTvLzDyt15+rOrawrpM4q7DD9dQ1P11P4=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 h1:XVhgTWWV3kGQlwJHR3upFWZeTsei6Oks1apkZSeonIE=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
|
||||
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
|
||||
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
|
||||
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
|
||||
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
|
||||
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
|
362
main.go
Normal file
362
main.go
Normal file
|
@ -0,0 +1,362 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/goccy/go-graphviz"
|
||||
"github.com/goccy/go-graphviz/cgraph"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// COLORS enthält eine Liste von Farben für die Netzwerke
|
||||
var COLORS = []string{
|
||||
"#1f78b4", "#33a02c", "#e31a1c", "#ff7f00", "#6a3d9a", "#b15928",
|
||||
"#a6cee3", "#b2df8a", "#fdbf6f", "#cab2d6", "#90f530", "#0d8bad",
|
||||
"#e98420", "#0e9997", "#6a5164", "#afa277", "#149ead", "#a54a56",
|
||||
}
|
||||
|
||||
var i = 0
|
||||
|
||||
// Network repräsentiert ein Docker-Netzwerk
|
||||
type Network struct {
|
||||
Name string
|
||||
Gateway string
|
||||
Internal bool
|
||||
Isolated bool
|
||||
Color string
|
||||
}
|
||||
|
||||
// Interface repräsentiert eine Netzwerkschnittstelle eines Containers
|
||||
type Interface struct {
|
||||
EndpointID string
|
||||
Address string
|
||||
Aliases []string
|
||||
}
|
||||
|
||||
// Port repräsentiert einen Port eines Containers
|
||||
type Port struct {
|
||||
Port string
|
||||
}
|
||||
|
||||
// Container repräsentiert einen Docker-Container
|
||||
type Container struct {
|
||||
ContainerID string
|
||||
Name string
|
||||
Interfaces []Interface
|
||||
Ports []Port
|
||||
}
|
||||
|
||||
// Link repräsentiert eine Verbindung zwischen einem Container und einem Netzwerk
|
||||
type Link struct {
|
||||
ContainerID string
|
||||
EndpointID string
|
||||
NetworkName string
|
||||
}
|
||||
|
||||
func getUniqueColor() string {
|
||||
if i < len(COLORS) {
|
||||
c := COLORS[i]
|
||||
i++
|
||||
return c
|
||||
}
|
||||
return fmt.Sprintf("#%06x", rand.Intn(0xFFFFFF))
|
||||
}
|
||||
|
||||
func getNetworks(cli *client.Client, verbose bool) (map[string]Network, error) {
|
||||
networks := make(map[string]Network)
|
||||
ctx := context.Background()
|
||||
|
||||
netList, err := cli.NetworkList(ctx, types.NetworkListOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, net := range netList {
|
||||
gateway := ""
|
||||
if len(net.IPAM.Config) > 0 {
|
||||
gateway = net.IPAM.Config[0].Subnet
|
||||
}
|
||||
|
||||
if gateway == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
internal := net.Internal
|
||||
isolated := false
|
||||
if val, ok := net.Options["com.docker.network.bridge.enable_icc"]; ok && val == "false" {
|
||||
isolated = true
|
||||
}
|
||||
|
||||
if verbose {
|
||||
fmt.Printf("Network: %s %s %s gw:%s\n", net.Name,
|
||||
map[bool]string{true: "internal", false: ""}[internal],
|
||||
map[bool]string{true: "isolated", false: ""}[isolated],
|
||||
gateway)
|
||||
}
|
||||
|
||||
color := getUniqueColor()
|
||||
networks[net.Name] = Network{net.Name, gateway, internal, isolated, color}
|
||||
}
|
||||
|
||||
networks["host"] = Network{"host", "0.0.0.0", false, false, "#808080"}
|
||||
return networks, nil
|
||||
}
|
||||
|
||||
func getContainers(cli *client.Client, verbose bool) ([]Container, []Link, error) {
|
||||
var containers []Container
|
||||
var links []Link
|
||||
ctx := context.Background()
|
||||
|
||||
contList, err := cli.ContainerList(ctx, container.ListOptions{})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
for _, cont := range contList {
|
||||
var interfaces []Interface
|
||||
var ports []Port
|
||||
|
||||
contInspect, err := cli.ContainerInspect(ctx, cont.ID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
for portName := range contInspect.NetworkSettings.Ports {
|
||||
ports = append(ports, Port{portName.Port()})
|
||||
}
|
||||
|
||||
for netName, netInfo := range contInspect.NetworkSettings.Networks {
|
||||
aliases := []string{}
|
||||
for _, alias := range netInfo.Aliases {
|
||||
if alias != cont.ID[:12] && alias != cont.Names[0][1:] {
|
||||
aliases = append(aliases, alias)
|
||||
}
|
||||
}
|
||||
|
||||
interfaces = append(interfaces, Interface{
|
||||
EndpointID: netInfo.EndpointID,
|
||||
Address: netInfo.IPAddress,
|
||||
Aliases: aliases,
|
||||
})
|
||||
|
||||
links = append(links, Link{
|
||||
ContainerID: cont.ID,
|
||||
EndpointID: netInfo.EndpointID,
|
||||
NetworkName: netName,
|
||||
})
|
||||
}
|
||||
|
||||
if verbose {
|
||||
fmt.Printf("Container: %s %v %s\n", cont.Names[0][1:], ports, interfaces)
|
||||
}
|
||||
|
||||
containers = append(containers, Container{
|
||||
ContainerID: cont.ID,
|
||||
Name: cont.Names[0][1:],
|
||||
Interfaces: interfaces,
|
||||
Ports: ports,
|
||||
})
|
||||
}
|
||||
|
||||
return containers, links, nil
|
||||
}
|
||||
|
||||
func drawNetwork(graph *cgraph.Graph, net Network) error {
|
||||
label := fmt.Sprintf("{%s", net.Name)
|
||||
if net.Internal {
|
||||
label += " | Internal"
|
||||
}
|
||||
if net.Isolated {
|
||||
label += " | Containers isolated"
|
||||
}
|
||||
label += "}"
|
||||
|
||||
n, err := graph.CreateNodeByName(net.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n.SetShape(cgraph.BoxShape)
|
||||
n.SetLabel(label)
|
||||
n.SetColor(net.Color + "60")
|
||||
n.SetStyle("rounded")
|
||||
return nil
|
||||
}
|
||||
|
||||
func drawContainer(graph *cgraph.Graph, c Container) error {
|
||||
var ifaceLabels []string
|
||||
var portLabels []string
|
||||
|
||||
for _, port := range c.Ports {
|
||||
portLabels = append(portLabels, fmt.Sprintf("{%s}}", port.Port))
|
||||
}
|
||||
|
||||
for _, iface := range c.Interfaces {
|
||||
ifaceLabel := "{"
|
||||
for _, alias := range iface.Aliases {
|
||||
ifaceLabel += fmt.Sprintf(" %s |", alias)
|
||||
}
|
||||
ifaceLabel += fmt.Sprintf("<%s> %s }}", iface.EndpointID, iface.Address)
|
||||
ifaceLabels = append(ifaceLabels, ifaceLabel)
|
||||
}
|
||||
|
||||
label := fmt.Sprintf("{{ %s ", c.Name)
|
||||
if len(portLabels) > 0 {
|
||||
label += fmt.Sprintf("| {{ %s }} ", strings.Join(portLabels, " | "))
|
||||
}
|
||||
label += fmt.Sprintf("| {{ %s }} }}", strings.Join(ifaceLabels, " | "))
|
||||
|
||||
n, err := graph.CreateNodeByName(c.ContainerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n.SetShape(cgraph.BoxShape)
|
||||
n.SetLabel(label)
|
||||
n.SetFillColor("#cdcdcd")
|
||||
n.SetStyle("filled")
|
||||
return nil
|
||||
}
|
||||
|
||||
func drawLink(graph *cgraph.Graph, networks map[string]Network, link Link) error {
|
||||
style := cgraph.SolidEdgeStyle
|
||||
if networks[link.NetworkName].Isolated {
|
||||
style = cgraph.DashedEdgeStyle
|
||||
} else if networks[link.NetworkName].Name == "host" {
|
||||
style = cgraph.BoldEdgeStyle
|
||||
}
|
||||
|
||||
n, err := graph.NodeByName(link.ContainerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m, err := graph.NodeByName(link.NetworkName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
e, err := graph.CreateEdgeByName("", n, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
e.SetColor(networks[link.NetworkName].Color)
|
||||
e.SetStyle(style)
|
||||
return nil
|
||||
}
|
||||
|
||||
func generateGraph(verbose bool, file string, url bool) error {
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
networks, err := getNetworks(cli, verbose)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
containers, links, err := getContainers(cli, verbose)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
g, err := graphviz.New(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
graph, err := g.Graph()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
graph.SetLayout("sfdp")
|
||||
graph.SetRankDir("LR")
|
||||
//graph.SetBackground("transparent")
|
||||
|
||||
for _, network := range networks {
|
||||
if err := drawNetwork(graph, network); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, container := range containers {
|
||||
if err := drawContainer(graph, container); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, link := range links {
|
||||
if link.NetworkName != "none" {
|
||||
if err := drawLink(graph, networks, link); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, network := range networks {
|
||||
if !network.Internal && network.Name != "host" {
|
||||
startNode, err := graph.CreateNodeByName("start")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
endNode, err := graph.CreateNodeByName("end")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
e, err := graph.CreateEdgeByName("e", startNode, endNode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
e.SetColor("#808080")
|
||||
e.SetStyle("dotted")
|
||||
}
|
||||
}
|
||||
|
||||
if file != "" {
|
||||
if err := g.RenderFilename(ctx, graph, graphviz.Format(filepath.Ext(file)[1:]), file); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if url {
|
||||
// URL-Generierung ist in dieser Go-Version nicht implementiert
|
||||
fmt.Println("URL generation is not implemented in this Go version")
|
||||
} else {
|
||||
if err := g.Render(ctx, graph, graphviz.Format("dot"), os.Stdout); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
verbose := false
|
||||
file := ""
|
||||
url := false
|
||||
|
||||
// Einfache Argumentverarbeitung (kann durch ein Argument-Parsing-Paket ersetzt werden)
|
||||
for i := 1; i < len(os.Args); i++ {
|
||||
switch os.Args[i] {
|
||||
case "-v", "--verbose":
|
||||
verbose = true
|
||||
case "-o", "--out":
|
||||
if i+1 < len(os.Args) {
|
||||
file = os.Args[i+1]
|
||||
i++
|
||||
}
|
||||
case "-u", "--url":
|
||||
url = true
|
||||
}
|
||||
}
|
||||
|
||||
if err := generateGraph(verbose, file, url); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue