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", "--"]
|
||||
CMD ["godns"]
|
||||
|
||||
COPY etc/godns.conf /etc/godns.conf
|
||||
COPY godns /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", "--"]
|
||||
CMD ["godns"]
|
||||
|
||||
COPY etc/godns.conf /etc/godns.conf
|
||||
COPY godns-arm /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", "--"]
|
||||
CMD ["godns"]
|
||||
|
||||
COPY etc/godns.conf /etc/godns.conf
|
||||
COPY godns-arm64 /usr/local/bin/godns
|
||||
RUN chmod +x /usr/local/bin/godns
|
||||
|
|
|
@ -16,7 +16,6 @@ port = 53
|
|||
# Semicolon separate multiple files.
|
||||
server-list-file = "./etc/apple.china.conf;./etc/google.china.conf"
|
||||
resolv-file = "/etc/resolv.conf"
|
||||
dns-over-https = "https://cloudflare-dns.com/dns-query"
|
||||
timeout = 5 # 5 seconds
|
||||
# The concurrency interval request upstream recursive server
|
||||
# Match the PR15, https://github.com/kenshinx/godns/pull/15
|
||||
|
|
|
@ -48,7 +48,13 @@ func NewRedisProvider(rc *redis.Client, key string) HostProvider {
|
|||
continue
|
||||
}
|
||||
|
||||
rh.mu.RLock()
|
||||
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 {
|
||||
rh.Refresh()
|
||||
}
|
||||
|
|
20
resolver.go
20
resolver.go
|
@ -36,8 +36,8 @@ type Resolver struct {
|
|||
domain_server *suffixTreeNode
|
||||
config *ResolvSettings
|
||||
|
||||
tcpClient *dns.Client
|
||||
udpClient *dns.Client
|
||||
tcpClient *dns.Client
|
||||
udpClient *dns.Client
|
||||
httpsClient *dns.Client
|
||||
}
|
||||
|
||||
|
@ -73,20 +73,20 @@ func NewResolver(c ResolvSettings) *Resolver {
|
|||
timeout := r.Timeout()
|
||||
|
||||
r.udpClient = &dns.Client{
|
||||
Net: "udp",
|
||||
ReadTimeout: timeout,
|
||||
Net: "udp",
|
||||
ReadTimeout: timeout,
|
||||
WriteTimeout: timeout,
|
||||
}
|
||||
|
||||
r.tcpClient = &dns.Client{
|
||||
Net: "tcp",
|
||||
ReadTimeout: timeout,
|
||||
Net: "tcp",
|
||||
ReadTimeout: timeout,
|
||||
WriteTimeout: timeout,
|
||||
}
|
||||
|
||||
r.httpsClient = &dns.Client{
|
||||
Net: "https",
|
||||
ReadTimeout: timeout,
|
||||
Net: "https",
|
||||
ReadTimeout: timeout,
|
||||
WriteTimeout: timeout,
|
||||
}
|
||||
|
||||
|
@ -250,8 +250,8 @@ func (r *Resolver) resolverFor(net, nameserver string) (*dns.Client, error) {
|
|||
} 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.
|
||||
return &dns.Client{
|
||||
Net: "tcp-tls",
|
||||
ReadTimeout: r.Timeout(),
|
||||
Net: "tcp-tls",
|
||||
ReadTimeout: r.Timeout(),
|
||||
WriteTimeout: r.Timeout(),
|
||||
TLSConfig: &tls.Config{
|
||||
ServerName: "",
|
||||
|
|
41
server.go
41
server.go
|
@ -6,6 +6,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
|
@ -16,42 +17,48 @@ type Server struct {
|
|||
}
|
||||
|
||||
func (s *Server) Addr() string {
|
||||
if addr := os.Getenv("SERVER_BIND"); addr != "" {
|
||||
return addr
|
||||
}
|
||||
|
||||
return net.JoinHostPort(s.host, strconv.Itoa(s.port))
|
||||
}
|
||||
|
||||
func (s *Server) Run() {
|
||||
Handler := NewHandler()
|
||||
handler := NewHandler()
|
||||
|
||||
tcpHandler := dns.NewServeMux()
|
||||
tcpHandler.HandleFunc(".", Handler.DoTCP)
|
||||
tcpHandler.HandleFunc(".", handler.DoTCP)
|
||||
|
||||
udpHandler := dns.NewServeMux()
|
||||
udpHandler.HandleFunc(".", Handler.DoUDP)
|
||||
udpHandler.HandleFunc(".", handler.DoUDP)
|
||||
|
||||
tcpServer := &dns.Server{Addr: s.Addr(),
|
||||
Net: "tcp",
|
||||
Handler: tcpHandler,
|
||||
ReadTimeout: s.rTimeout,
|
||||
WriteTimeout: s.wTimeout}
|
||||
tcpServer := &dns.Server{
|
||||
Addr: s.Addr(),
|
||||
Net: "tcp",
|
||||
Handler: tcpHandler,
|
||||
ReadTimeout: s.rTimeout,
|
||||
WriteTimeout: s.wTimeout,
|
||||
}
|
||||
|
||||
udpServer := &dns.Server{Addr: s.Addr(),
|
||||
Net: "udp",
|
||||
Handler: udpHandler,
|
||||
UDPSize: 65535,
|
||||
ReadTimeout: s.rTimeout,
|
||||
WriteTimeout: s.wTimeout}
|
||||
udpServer := &dns.Server{
|
||||
Addr: s.Addr(),
|
||||
Net: "udp",
|
||||
Handler: udpHandler,
|
||||
UDPSize: 65535,
|
||||
ReadTimeout: s.rTimeout,
|
||||
WriteTimeout: s.wTimeout,
|
||||
}
|
||||
|
||||
go s.start(udpServer)
|
||||
go s.start(tcpServer)
|
||||
|
||||
}
|
||||
|
||||
func (s *Server) start(ds *dns.Server) {
|
||||
|
||||
logger.Info("Start %s listener on %s", ds.Net, s.Addr())
|
||||
|
||||
err := ds.ListenAndServe()
|
||||
if err != nil {
|
||||
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"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -59,6 +60,10 @@ type MemcacheSettings struct {
|
|||
}
|
||||
|
||||
func (s RedisSettings) Addr() string {
|
||||
if addr := os.Getenv("REDIS_ADDR"); addr != "" {
|
||||
return addr
|
||||
}
|
||||
|
||||
return s.Host + ":" + strconv.Itoa(s.Port)
|
||||
}
|
||||
|
||||
|
@ -92,10 +97,9 @@ type HostsSettings struct {
|
|||
}
|
||||
|
||||
func init() {
|
||||
|
||||
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()
|
||||
|
||||
if _, err := toml.DecodeFile(configFile, &settings); err != nil {
|
||||
|
@ -104,4 +108,12 @@ func init() {
|
|||
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