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()
|
||||||
}
|
}
|
||||||
|
|
27
server.go
27
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{
|
||||||
|
Addr: s.Addr(),
|
||||||
Net: "tcp",
|
Net: "tcp",
|
||||||
Handler: tcpHandler,
|
Handler: tcpHandler,
|
||||||
ReadTimeout: s.rTimeout,
|
ReadTimeout: s.rTimeout,
|
||||||
WriteTimeout: s.wTimeout}
|
WriteTimeout: s.wTimeout,
|
||||||
|
}
|
||||||
|
|
||||||
udpServer := &dns.Server{Addr: s.Addr(),
|
udpServer := &dns.Server{
|
||||||
|
Addr: s.Addr(),
|
||||||
Net: "udp",
|
Net: "udp",
|
||||||
Handler: udpHandler,
|
Handler: udpHandler,
|
||||||
UDPSize: 65535,
|
UDPSize: 65535,
|
||||||
ReadTimeout: s.rTimeout,
|
ReadTimeout: s.rTimeout,
|
||||||
WriteTimeout: s.wTimeout}
|
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