forked from lucaslorentz/caddy-docker-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
containers.go
32 lines (24 loc) · 968 Bytes
/
containers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package generator
import (
"github.com/docker/docker/api/types"
"github.com/xlp/caddy-docker-proxy/v2/caddyfile"
"go.uber.org/zap"
)
func (g *CaddyfileGenerator) getContainerCaddyfile(container *types.Container, logger *zap.Logger) (*caddyfile.Container, error) {
caddyLabels := g.filterLabels(container.Labels)
return labelsToCaddyfile(caddyLabels, container, func() ([]string, error) {
return g.getContainerIPAddresses(container, logger, true)
})
}
func (g *CaddyfileGenerator) getContainerIPAddresses(container *types.Container, logger *zap.Logger, ingress bool) ([]string, error) {
ips := []string{}
for _, network := range container.NetworkSettings.Networks {
if !ingress || g.ingressNetworks[network.NetworkID] {
ips = append(ips, network.IPAddress)
}
}
if len(ips) == 0 {
logger.Warn("Container is not in same network as caddy", zap.String("container", container.ID), zap.String("container id", container.ID))
}
return ips, nil
}