Add config to docker, env overrides
This commit is contained in:
parent
725f298f2e
commit
2c0b9fb350
|
@ -8,5 +8,6 @@ RUN apk --no-cache add tini
|
||||||
ENTRYPOINT ["/sbin/tini", "-g", "--"]
|
ENTRYPOINT ["/sbin/tini", "-g", "--"]
|
||||||
CMD ["godns"]
|
CMD ["godns"]
|
||||||
|
|
||||||
|
COPY etc/godns.conf /etc/godns.conf
|
||||||
COPY godns /usr/local/bin/godns
|
COPY godns /usr/local/bin/godns
|
||||||
RUN chmod +x /usr/local/bin/godns
|
RUN chmod +x /usr/local/bin/godns
|
||||||
|
|
|
@ -10,5 +10,6 @@ RUN apk --no-cache add tini
|
||||||
ENTRYPOINT ["/sbin/tini", "-g", "--"]
|
ENTRYPOINT ["/sbin/tini", "-g", "--"]
|
||||||
CMD ["godns"]
|
CMD ["godns"]
|
||||||
|
|
||||||
|
COPY etc/godns.conf /etc/godns.conf
|
||||||
COPY godns-arm /usr/local/bin/godns
|
COPY godns-arm /usr/local/bin/godns
|
||||||
RUN chmod +x /usr/local/bin/godns
|
RUN chmod +x /usr/local/bin/godns
|
||||||
|
|
|
@ -10,5 +10,6 @@ RUN apk --no-cache add tini
|
||||||
ENTRYPOINT ["/sbin/tini", "-g", "--"]
|
ENTRYPOINT ["/sbin/tini", "-g", "--"]
|
||||||
CMD ["godns"]
|
CMD ["godns"]
|
||||||
|
|
||||||
|
COPY etc/godns.conf /etc/godns.conf
|
||||||
COPY godns-arm64 /usr/local/bin/godns
|
COPY godns-arm64 /usr/local/bin/godns
|
||||||
RUN chmod +x /usr/local/bin/godns
|
RUN chmod +x /usr/local/bin/godns
|
||||||
|
|
|
@ -16,7 +16,6 @@ port = 53
|
||||||
# Semicolon separate multiple files.
|
# Semicolon separate multiple files.
|
||||||
server-list-file = "./etc/apple.china.conf;./etc/google.china.conf"
|
server-list-file = "./etc/apple.china.conf;./etc/google.china.conf"
|
||||||
resolv-file = "/etc/resolv.conf"
|
resolv-file = "/etc/resolv.conf"
|
||||||
dns-over-https = "https://cloudflare-dns.com/dns-query"
|
|
||||||
timeout = 5 # 5 seconds
|
timeout = 5 # 5 seconds
|
||||||
# The concurrency interval request upstream recursive server
|
# The concurrency interval request upstream recursive server
|
||||||
# Match the PR15, https://github.com/kenshinx/godns/pull/15
|
# Match the PR15, https://github.com/kenshinx/godns/pull/15
|
||||||
|
|
|
@ -48,7 +48,13 @@ func NewRedisProvider(rc *redis.Client, key string) HostProvider {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rh.mu.RLock()
|
||||||
rh.hosts[recordName] = string(b)
|
rh.hosts[recordName] = string(b)
|
||||||
|
rh.mu.RUnlock()
|
||||||
|
} else if msg.Channel == "godns:remove_record" {
|
||||||
|
rh.mu.RLock()
|
||||||
|
delete(rh.hosts, string(msg.Message))
|
||||||
|
rh.mu.RUnlock()
|
||||||
} else if msg.Channel == keyspaceEvent {
|
} else if msg.Channel == keyspaceEvent {
|
||||||
rh.Refresh()
|
rh.Refresh()
|
||||||
}
|
}
|
||||||
|
|
20
resolver.go
20
resolver.go
|
@ -36,8 +36,8 @@ type Resolver struct {
|
||||||
domain_server *suffixTreeNode
|
domain_server *suffixTreeNode
|
||||||
config *ResolvSettings
|
config *ResolvSettings
|
||||||
|
|
||||||
tcpClient *dns.Client
|
tcpClient *dns.Client
|
||||||
udpClient *dns.Client
|
udpClient *dns.Client
|
||||||
httpsClient *dns.Client
|
httpsClient *dns.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,20 +73,20 @@ func NewResolver(c ResolvSettings) *Resolver {
|
||||||
timeout := r.Timeout()
|
timeout := r.Timeout()
|
||||||
|
|
||||||
r.udpClient = &dns.Client{
|
r.udpClient = &dns.Client{
|
||||||
Net: "udp",
|
Net: "udp",
|
||||||
ReadTimeout: timeout,
|
ReadTimeout: timeout,
|
||||||
WriteTimeout: timeout,
|
WriteTimeout: timeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
r.tcpClient = &dns.Client{
|
r.tcpClient = &dns.Client{
|
||||||
Net: "tcp",
|
Net: "tcp",
|
||||||
ReadTimeout: timeout,
|
ReadTimeout: timeout,
|
||||||
WriteTimeout: timeout,
|
WriteTimeout: timeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
r.httpsClient = &dns.Client{
|
r.httpsClient = &dns.Client{
|
||||||
Net: "https",
|
Net: "https",
|
||||||
ReadTimeout: timeout,
|
ReadTimeout: timeout,
|
||||||
WriteTimeout: timeout,
|
WriteTimeout: timeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,8 +250,8 @@ func (r *Resolver) resolverFor(net, nameserver string) (*dns.Client, error) {
|
||||||
} else if strings.HasSuffix(nameserver, ":853") {
|
} else if strings.HasSuffix(nameserver, ":853") {
|
||||||
// TODO We need to set the server name so we can confirm the TLS connection. This may require a rewrite of storing nameservers.
|
// TODO We need to set the server name so we can confirm the TLS connection. This may require a rewrite of storing nameservers.
|
||||||
return &dns.Client{
|
return &dns.Client{
|
||||||
Net: "tcp-tls",
|
Net: "tcp-tls",
|
||||||
ReadTimeout: r.Timeout(),
|
ReadTimeout: r.Timeout(),
|
||||||
WriteTimeout: r.Timeout(),
|
WriteTimeout: r.Timeout(),
|
||||||
TLSConfig: &tls.Config{
|
TLSConfig: &tls.Config{
|
||||||
ServerName: "",
|
ServerName: "",
|
||||||
|
|
41
server.go
41
server.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
|
@ -16,42 +17,48 @@ type Server struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Addr() string {
|
func (s *Server) Addr() string {
|
||||||
|
if addr := os.Getenv("SERVER_BIND"); addr != "" {
|
||||||
|
return addr
|
||||||
|
}
|
||||||
|
|
||||||
return net.JoinHostPort(s.host, strconv.Itoa(s.port))
|
return net.JoinHostPort(s.host, strconv.Itoa(s.port))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Run() {
|
func (s *Server) Run() {
|
||||||
Handler := NewHandler()
|
handler := NewHandler()
|
||||||
|
|
||||||
tcpHandler := dns.NewServeMux()
|
tcpHandler := dns.NewServeMux()
|
||||||
tcpHandler.HandleFunc(".", Handler.DoTCP)
|
tcpHandler.HandleFunc(".", handler.DoTCP)
|
||||||
|
|
||||||
udpHandler := dns.NewServeMux()
|
udpHandler := dns.NewServeMux()
|
||||||
udpHandler.HandleFunc(".", Handler.DoUDP)
|
udpHandler.HandleFunc(".", handler.DoUDP)
|
||||||
|
|
||||||
tcpServer := &dns.Server{Addr: s.Addr(),
|
tcpServer := &dns.Server{
|
||||||
Net: "tcp",
|
Addr: s.Addr(),
|
||||||
Handler: tcpHandler,
|
Net: "tcp",
|
||||||
ReadTimeout: s.rTimeout,
|
Handler: tcpHandler,
|
||||||
WriteTimeout: s.wTimeout}
|
ReadTimeout: s.rTimeout,
|
||||||
|
WriteTimeout: s.wTimeout,
|
||||||
|
}
|
||||||
|
|
||||||
udpServer := &dns.Server{Addr: s.Addr(),
|
udpServer := &dns.Server{
|
||||||
Net: "udp",
|
Addr: s.Addr(),
|
||||||
Handler: udpHandler,
|
Net: "udp",
|
||||||
UDPSize: 65535,
|
Handler: udpHandler,
|
||||||
ReadTimeout: s.rTimeout,
|
UDPSize: 65535,
|
||||||
WriteTimeout: s.wTimeout}
|
ReadTimeout: s.rTimeout,
|
||||||
|
WriteTimeout: s.wTimeout,
|
||||||
|
}
|
||||||
|
|
||||||
go s.start(udpServer)
|
go s.start(udpServer)
|
||||||
go s.start(tcpServer)
|
go s.start(tcpServer)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) start(ds *dns.Server) {
|
func (s *Server) start(ds *dns.Server) {
|
||||||
|
|
||||||
logger.Info("Start %s listener on %s", ds.Net, s.Addr())
|
logger.Info("Start %s listener on %s", ds.Net, s.Addr())
|
||||||
|
|
||||||
err := ds.ListenAndServe()
|
err := ds.ListenAndServe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("Start %s listener on %s failed:%s", ds.Net, s.Addr(), err.Error())
|
logger.Error("Start %s listener on %s failed:%s", ds.Net, s.Addr(), err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
16
settings.go
16
settings.go
|
@ -7,6 +7,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -59,6 +60,10 @@ type MemcacheSettings struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s RedisSettings) Addr() string {
|
func (s RedisSettings) Addr() string {
|
||||||
|
if addr := os.Getenv("REDIS_ADDR"); addr != "" {
|
||||||
|
return addr
|
||||||
|
}
|
||||||
|
|
||||||
return s.Host + ":" + strconv.Itoa(s.Port)
|
return s.Host + ":" + strconv.Itoa(s.Port)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,10 +97,9 @@ type HostsSettings struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
var configFile string
|
var configFile string
|
||||||
|
|
||||||
flag.StringVar(&configFile, "c", "./etc/godns.conf", "Look for godns toml-formatting config file in this directory")
|
flag.StringVar(&configFile, "c", "/etc/godns.conf", "Look for godns toml-formatting config file in this directory")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if _, err := toml.DecodeFile(configFile, &settings); err != nil {
|
if _, err := toml.DecodeFile(configFile, &settings); err != nil {
|
||||||
|
@ -104,4 +108,12 @@ func init() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Env overrides
|
||||||
|
if cacheBackend := os.Getenv("CACHE_BACKEND"); cacheBackend != "" {
|
||||||
|
settings.Cache.Backend = cacheBackend
|
||||||
|
}
|
||||||
|
|
||||||
|
if memcacheServers := os.Getenv("MEMCACHE_SERVERS"); memcacheServers != "" {
|
||||||
|
settings.Memcache.Servers = strings.Split(memcacheServers, ",")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue