mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-19 20:32:35 +02:00
Merge branch 'main' into dev
This commit is contained in:
commit
1ce607029a
8 changed files with 68 additions and 10 deletions
|
@ -1,5 +1,5 @@
|
||||||
# Stage 1: deps
|
# Stage 1: deps
|
||||||
FROM golang:1.24.2-alpine AS deps
|
FROM golang:1.24.3-alpine AS deps
|
||||||
HEALTHCHECK NONE
|
HEALTHCHECK NONE
|
||||||
|
|
||||||
# package version does not matter
|
# package version does not matter
|
||||||
|
|
16
Makefile
16
Makefile
|
@ -79,6 +79,22 @@ docker-build-test:
|
||||||
get:
|
get:
|
||||||
for dir in ${PWD} ${PWD}/agent ${PWD}/internal/dnsproviders; do cd $$dir && go get -u ./... && go mod tidy; done
|
for dir in ${PWD} ${PWD}/agent ${PWD}/internal/dnsproviders; do cd $$dir && go get -u ./... && go mod tidy; done
|
||||||
|
|
||||||
|
|
||||||
|
go_ver := $(shell go version | cut -d' ' -f3 | cut -d'o' -f2)
|
||||||
|
files := $(shell find . -name go.mod -type f -or -name Dockerfile -type f)
|
||||||
|
gomod_paths := $(shell find . -name go.mod -type f | xargs dirname)
|
||||||
|
|
||||||
|
update-go:
|
||||||
|
for file in ${files}; do \
|
||||||
|
echo "updating $$file"; \
|
||||||
|
sed -i 's|go \([0-9]\+\.[0-9]\+\.[0-9]\+\)|go ${go_ver}|g' $$file; \
|
||||||
|
sed -i 's|FROM golang:.*-alpine|FROM golang:${go_ver}-alpine|g' $$file; \
|
||||||
|
done
|
||||||
|
for path in ${gomod_paths}; do \
|
||||||
|
echo "go mod tidy $$path"; \
|
||||||
|
cd ${PWD}/$$path && go mod tidy; \
|
||||||
|
done
|
||||||
|
|
||||||
build:
|
build:
|
||||||
mkdir -p $(shell dirname ${BIN_PATH})
|
mkdir -p $(shell dirname ${BIN_PATH})
|
||||||
cd ${PWD} && go build ${BUILD_FLAGS} -o ${BIN_PATH} ${CMD_PATH}
|
cd ${PWD} && go build ${BUILD_FLAGS} -o ${BIN_PATH} ${CMD_PATH}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module github.com/yusing/go-proxy/agent
|
module github.com/yusing/go-proxy/agent
|
||||||
|
|
||||||
go 1.24.2
|
go 1.24.3
|
||||||
|
|
||||||
replace github.com/yusing/go-proxy => ..
|
replace github.com/yusing/go-proxy => ..
|
||||||
|
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -1,6 +1,6 @@
|
||||||
module github.com/yusing/go-proxy
|
module github.com/yusing/go-proxy
|
||||||
|
|
||||||
go 1.24.2
|
go 1.24.3
|
||||||
|
|
||||||
replace github.com/yusing/go-proxy/agent => ./agent
|
replace github.com/yusing/go-proxy/agent => ./agent
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module github.com/yusing/go-proxy/internal/dnsproviders
|
module github.com/yusing/go-proxy/internal/dnsproviders
|
||||||
|
|
||||||
go 1.24.2
|
go 1.24.3
|
||||||
|
|
||||||
replace github.com/yusing/go-proxy => ../..
|
replace github.com/yusing/go-proxy => ../..
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
|
"github.com/docker/go-connections/nat"
|
||||||
"github.com/yusing/go-proxy/agent/pkg/agent"
|
"github.com/yusing/go-proxy/agent/pkg/agent"
|
||||||
config "github.com/yusing/go-proxy/internal/config/types"
|
config "github.com/yusing/go-proxy/internal/config/types"
|
||||||
"github.com/yusing/go-proxy/internal/gperr"
|
"github.com/yusing/go-proxy/internal/gperr"
|
||||||
|
@ -218,13 +219,15 @@ func (c *Container) UpdatePorts() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for port := range inspect.Config.ExposedPorts {
|
for port := range inspect.Config.ExposedPorts {
|
||||||
if port.Int() == 0 {
|
proto, portStr := nat.SplitProtoPort(string(port))
|
||||||
|
portInt, _ := nat.ParsePort(portStr)
|
||||||
|
if portInt == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
c.PublicPortMapping[port.Int()] = container.Port{
|
c.PublicPortMapping[portInt] = container.Port{
|
||||||
PublicPort: uint16(port.Int()),
|
PublicPort: uint16(portInt),
|
||||||
PrivatePort: uint16(port.Int()),
|
PrivatePort: uint16(portInt),
|
||||||
Type: port.Proto(),
|
Type: proto,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -41,3 +41,38 @@ func TestContainerExplicit(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContainerHostNetworkMode(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
container *container.SummaryTrimmed
|
||||||
|
isHostNetworkMode bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "host network mode",
|
||||||
|
container: &container.SummaryTrimmed{
|
||||||
|
Names: []string{"test"},
|
||||||
|
State: "test",
|
||||||
|
HostConfig: struct {
|
||||||
|
NetworkMode string "json:\",omitempty\""
|
||||||
|
}{
|
||||||
|
NetworkMode: "host",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
isHostNetworkMode: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "not host network mode",
|
||||||
|
container: &container.SummaryTrimmed{
|
||||||
|
Names: []string{"test"},
|
||||||
|
State: "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
c := FromDocker(tt.container, "")
|
||||||
|
ExpectEqual(t, c.IsHostNetworkMode, tt.isHostNetworkMode)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -409,7 +409,11 @@ func (r *Route) Finalize() {
|
||||||
if pp == 0 {
|
if pp == 0 {
|
||||||
switch {
|
switch {
|
||||||
case isDocker:
|
case isDocker:
|
||||||
pp = preferredPort(cont.PrivatePortMapping)
|
if cont.IsHostNetworkMode {
|
||||||
|
pp = preferredPort(cont.PublicPortMapping)
|
||||||
|
} else {
|
||||||
|
pp = preferredPort(cont.PrivatePortMapping)
|
||||||
|
}
|
||||||
case r.Scheme == "https":
|
case r.Scheme == "https":
|
||||||
pp = 443
|
pp = 443
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Add table
Reference in a new issue