mirror of
https://github.com/vmorganp/Lazytainer.git
synced 2025-12-21 13:23:02 +01:00
fix: hostname issues (#82)
Some checks failed
Docker Build and Publish / build (push) Has been cancelled
Some checks failed
Docker Build and Publish / build (push) Has been cancelled
This commit is contained in:
29
src/go.mod
29
src/go.mod
@@ -1,22 +1,37 @@
|
||||
module github.com/lazytainer
|
||||
|
||||
go 1.16
|
||||
go 1.23.0
|
||||
|
||||
require (
|
||||
github.com/Microsoft/go-winio v0.6.1 // indirect
|
||||
github.com/cakturk/go-netstat v0.0.0-20200220111822-e5b49efee7a5
|
||||
github.com/containerd/log v0.1.0 // indirect
|
||||
github.com/distribution/reference v0.5.0 // indirect
|
||||
github.com/docker/docker v27.5.1+incompatible
|
||||
github.com/docker/go-connections v0.4.0 // indirect
|
||||
github.com/distribution/reference v0.6.0 // indirect
|
||||
github.com/docker/docker v28.0.1+incompatible
|
||||
github.com/docker/go-connections v0.5.0 // indirect
|
||||
github.com/docker/go-units v0.5.0 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/google/gopacket v1.1.19
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Microsoft/go-winio v0.6.2 // indirect
|
||||
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||
github.com/go-logr/logr v1.4.2 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/moby/docker-image-spec v1.3.1 // indirect
|
||||
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
|
||||
github.com/morikuni/aec v1.0.0 // indirect
|
||||
github.com/opencontainers/image-spec v1.1.0-rc3 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect
|
||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||
github.com/opencontainers/image-spec v1.1.1 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect
|
||||
go.opentelemetry.io/otel v1.35.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.22.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.35.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.35.0 // indirect
|
||||
golang.org/x/net v0.37.0 // indirect
|
||||
golang.org/x/sys v0.31.0 // indirect
|
||||
golang.org/x/time v0.3.0 // indirect
|
||||
gotest.tools/v3 v3.0.3 // indirect
|
||||
)
|
||||
|
||||
1876
src/go.sum
1876
src/go.sum
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/client"
|
||||
)
|
||||
|
||||
@@ -24,6 +23,7 @@ func main() {
|
||||
flags := log.LstdFlags | log.Lshortfile
|
||||
infoLogger = log.New(os.Stdout, "INFO: ", flags)
|
||||
debugLogger = log.New(os.Stdout, "DEBUG: ", flags)
|
||||
debugLogger.Println("Starting Lazytainer")
|
||||
|
||||
// if the verbose flag isn't set to true, don't log debug logs
|
||||
verbose, verboseFlagSet := os.LookupEnv("VERBOSE")
|
||||
@@ -58,9 +58,6 @@ func main() {
|
||||
}
|
||||
|
||||
func configureFromLabels() map[string]LazyGroup {
|
||||
// theoretically this could create an issue if people manually hostname their lazytainer instances the same
|
||||
// for now the solution is "don't do that"
|
||||
// we could do something clever to get around this, but not right now.
|
||||
container_id, err := os.Hostname()
|
||||
check(err)
|
||||
|
||||
@@ -70,12 +67,36 @@ func configureFromLabels() map[string]LazyGroup {
|
||||
//negotiate API version to prevent "client version is too new" error
|
||||
dockerClient.NegotiateAPIVersion(context.Background())
|
||||
|
||||
filter := filters.NewArgs(filters.Arg("id", container_id))
|
||||
containers, err := dockerClient.ContainerList(context.Background(), container.ListOptions{All: true, Filters: filter})
|
||||
containers, err := dockerClient.ContainerList(context.Background(), container.ListOptions{All: true})
|
||||
check(err)
|
||||
|
||||
// Figure out which container we are currently running in
|
||||
var thisLazytainer container.Summary
|
||||
for c := range containers {
|
||||
thisContainer := containers[c]
|
||||
// Only further investigate those which are running lazytainer
|
||||
if containers[c].Command != "./app/lazytainer" {
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.HasPrefix(thisContainer.ID, container_id) {
|
||||
// if the hostname matches, that's the one
|
||||
thisLazytainer = thisContainer
|
||||
break
|
||||
} else if strings.HasPrefix(thisContainer.HostConfig.NetworkMode, "container:"+container_id) {
|
||||
// otherwise, if the network mode matches the hostname, that's the one
|
||||
thisLazytainer = thisContainer
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// this should never happen
|
||||
if thisLazytainer.ID == "" {
|
||||
panic("Could not determine container ID of lazytainer")
|
||||
}
|
||||
|
||||
groups := make(map[string]LazyGroup)
|
||||
labels := containers[0].Labels
|
||||
labels := thisLazytainer.Labels
|
||||
|
||||
// iterate through labels, building out config for each group
|
||||
prefix := "lazytainer.group."
|
||||
|
||||
Reference in New Issue
Block a user