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
491231e439
3 changed files with 48 additions and 13 deletions
|
@ -1,6 +1,7 @@
|
||||||
package docker
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -37,10 +38,11 @@ type (
|
||||||
PublicHostname string `json:"public_hostname"`
|
PublicHostname string `json:"public_hostname"`
|
||||||
PrivateHostname string `json:"private_hostname"`
|
PrivateHostname string `json:"private_hostname"`
|
||||||
|
|
||||||
Aliases []string `json:"aliases"`
|
Aliases []string `json:"aliases"`
|
||||||
IsExcluded bool `json:"is_excluded"`
|
IsExcluded bool `json:"is_excluded"`
|
||||||
IsExplicit bool `json:"is_explicit"`
|
IsExplicit bool `json:"is_explicit"`
|
||||||
Running bool `json:"running"`
|
IsHostNetworkMode bool `json:"is_host_network_mode"`
|
||||||
|
Running bool `json:"running"`
|
||||||
}
|
}
|
||||||
ContainerImage struct {
|
ContainerImage struct {
|
||||||
Author string `json:"author,omitempty"`
|
Author string `json:"author,omitempty"`
|
||||||
|
@ -76,10 +78,11 @@ func FromDocker(c *container.SummaryTrimmed, dockerHost string) (res *Container)
|
||||||
PublicPortMapping: helper.getPublicPortMapping(),
|
PublicPortMapping: helper.getPublicPortMapping(),
|
||||||
PrivatePortMapping: helper.getPrivatePortMapping(),
|
PrivatePortMapping: helper.getPrivatePortMapping(),
|
||||||
|
|
||||||
Aliases: helper.getAliases(),
|
Aliases: helper.getAliases(),
|
||||||
IsExcluded: isExcluded,
|
IsExcluded: isExcluded,
|
||||||
IsExplicit: isExplicit,
|
IsExplicit: isExplicit,
|
||||||
Running: c.Status == "running" || c.State == "running",
|
IsHostNetworkMode: c.HostConfig.NetworkMode == "host",
|
||||||
|
Running: c.Status == "running" || c.State == "running",
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.IsDockerHostAgent(dockerHost) {
|
if agent.IsDockerHostAgent(dockerHost) {
|
||||||
|
@ -201,3 +204,28 @@ func (c *Container) loadDeleteIdlewatcherLabels(helper containerHelper) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Container) UpdatePorts() error {
|
||||||
|
client, err := NewClient(c.DockerHost)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer client.Close()
|
||||||
|
|
||||||
|
inspect, err := client.ContainerInspect(context.Background(), c.ContainerID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for port := range inspect.Config.ExposedPorts {
|
||||||
|
if port.Int() == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
c.PublicPortMapping[port.Int()] = container.Port{
|
||||||
|
PublicPort: uint16(port.Int()),
|
||||||
|
PrivatePort: uint16(port.Int()),
|
||||||
|
Type: port.Proto(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -30,9 +30,8 @@ type (
|
||||||
writeLock sync.Mutex
|
writeLock sync.Mutex
|
||||||
closed bool
|
closed bool
|
||||||
|
|
||||||
wps int64
|
writeCount int64
|
||||||
bufSize int
|
bufSize int
|
||||||
lastAdjust time.Time
|
|
||||||
|
|
||||||
lineBufPool *synk.BytesPool // buffer pool for formatting a single log line
|
lineBufPool *synk.BytesPool // buffer pool for formatting a single log line
|
||||||
|
|
||||||
|
@ -69,7 +68,7 @@ const (
|
||||||
MinBufferSize = 4 * kilobyte
|
MinBufferSize = 4 * kilobyte
|
||||||
MaxBufferSize = 8 * megabyte
|
MaxBufferSize = 8 * megabyte
|
||||||
|
|
||||||
bufferAdjustInterval = time.Second // How often we check & adjust
|
bufferAdjustInterval = 5 * time.Second // How often we check & adjust
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultRotateInterval = time.Hour
|
const defaultRotateInterval = time.Hour
|
||||||
|
@ -297,11 +296,11 @@ func (l *AccessLogger) write(data []byte) {
|
||||||
} else if n < len(data) {
|
} else if n < len(data) {
|
||||||
l.handleErr(gperr.Errorf("%w, writing %d bytes, only %d written", io.ErrShortWrite, len(data), n))
|
l.handleErr(gperr.Errorf("%w, writing %d bytes, only %d written", io.ErrShortWrite, len(data), n))
|
||||||
}
|
}
|
||||||
atomic.AddInt64(&l.wps, int64(n))
|
atomic.AddInt64(&l.writeCount, int64(n))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *AccessLogger) adjustBuffer() {
|
func (l *AccessLogger) adjustBuffer() {
|
||||||
wps := int(atomic.SwapInt64(&l.wps, 0))
|
wps := int(atomic.SwapInt64(&l.writeCount, 0)) / int(bufferAdjustInterval.Seconds())
|
||||||
origBufSize := l.bufSize
|
origBufSize := l.bufSize
|
||||||
newBufSize := origBufSize
|
newBufSize := origBufSize
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,14 @@ func (p *DockerProvider) loadRoutesImpl() (route.Routes, gperr.Error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if container.IsHostNetworkMode {
|
||||||
|
err := container.UpdatePorts()
|
||||||
|
if err != nil {
|
||||||
|
errs.Add(gperr.PrependSubject(container.ContainerName, err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
newEntries, err := p.routesFromContainerLabels(container)
|
newEntries, err := p.routesFromContainerLabels(container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs.Add(err.Subject(container.ContainerName))
|
errs.Add(err.Subject(container.ContainerName))
|
||||||
|
|
Loading…
Add table
Reference in a new issue