From 657fb7554e3d7a6584d1f61d477d0fdf304bbb0f Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Wed, 3 Jul 2019 09:59:23 +0300 Subject: [PATCH 1/3] support for "HostnameResolveMethod": "ip" --- go/inst/resolve.go | 14 +++++++++++++- go/inst/resolve_dao.go | 13 +------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/go/inst/resolve.go b/go/inst/resolve.go index a3ef377fa..c3c1432b8 100644 --- a/go/inst/resolve.go +++ b/go/inst/resolve.go @@ -276,6 +276,17 @@ func RegisterHostnameUnresolve(registration *HostnameRegistration) (err error) { return WriteHostnameUnresolve(®istration.Key, registration.Hostname) } +func extractIPs(ips []net.IP) (ipv4String string, ipv6String string) { + for _, ip := range ips { + if ip4 := ip.To4(); ip4 != nil { + ipv4String = ip.String() + } else { + ipv6String = ip.String() + } + } + return ipv4String, ipv6String +} + func ResolveHostnameIPs(hostname string) error { if _, found := hostnameIPsCache.Get(hostname); found { return nil @@ -285,5 +296,6 @@ func ResolveHostnameIPs(hostname string) error { return log.Errore(err) } hostnameIPsCache.Set(hostname, true, cache.DefaultExpiration) - return writeHostnameIPs(hostname, ips) + ipv4String, ipv6String := extractIPs(ips) + return writeHostnameIPs(hostname, ipv4String, ipv6String) } diff --git a/go/inst/resolve_dao.go b/go/inst/resolve_dao.go index 54ed09449..5fc39a174 100644 --- a/go/inst/resolve_dao.go +++ b/go/inst/resolve_dao.go @@ -17,8 +17,6 @@ package inst import ( - "net" - "github.com/github/orchestrator/go/config" "github.com/github/orchestrator/go/db" "github.com/openark/golib/log" @@ -327,16 +325,7 @@ func deleteHostnameResolves() error { } // writeHostnameIPs stroes an ipv4 and ipv6 associated witha hostname, if available -func writeHostnameIPs(hostname string, ips []net.IP) error { - ipv4String := "" - ipv6String := "" - for _, ip := range ips { - if ip4 := ip.To4(); ip4 != nil { - ipv4String = ip.String() - } else { - ipv6String = ip.String() - } - } +func writeHostnameIPs(hostname string, ipv4String string, ipv6String string) error { writeFunc := func() error { _, err := db.ExecOrchestrator(` insert into From 7faf253ffacdf0ac5642545901d4a1ce2a4b4b5c Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Wed, 3 Jul 2019 10:22:46 +0300 Subject: [PATCH 2/3] supporting 'ip' method --- go/inst/resolve.go | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/go/inst/resolve.go b/go/inst/resolve.go index c3c1432b8..9d2f3fe26 100644 --- a/go/inst/resolve.go +++ b/go/inst/resolve.go @@ -111,6 +111,8 @@ func resolveHostname(hostname string) (string, error) { return hostname, nil case "cname": return GetCNAME(hostname) + case "ip": + return getHostnameIP(hostname) } return hostname, nil } @@ -287,15 +289,38 @@ func extractIPs(ips []net.IP) (ipv4String string, ipv6String string) { return ipv4String, ipv6String } -func ResolveHostnameIPs(hostname string) error { - if _, found := hostnameIPsCache.Get(hostname); found { - return nil +func getHostnameIPs(hostname string) (ips []net.IP, fromCache bool, err error) { + if ips, found := hostnameIPsCache.Get(hostname); found { + return ips.([]net.IP), true, nil + } + ips, err = net.LookupIP(hostname) + if err != nil { + return ips, false, log.Errore(err) + } + hostnameIPsCache.Set(hostname, ips, cache.DefaultExpiration) + return ips, false, nil +} + +func getHostnameIP(hostname string) (ipString string, err error) { + ips, _, err := getHostnameIPs(hostname) + if err != nil { + return ipString, err } - ips, err := net.LookupIP(hostname) + ipv4String, ipv6String := extractIPs(ips) + if ipv4String != "" { + return ipv4String, nil + } + return ipv6String, nil +} + +func ResolveHostnameIPs(hostname string) error { + ips, fromCache, err := getHostnameIPs(hostname) if err != nil { - return log.Errore(err) + return err + } + if fromCache { + return nil } - hostnameIPsCache.Set(hostname, true, cache.DefaultExpiration) ipv4String, ipv6String := extractIPs(ips) return writeHostnameIPs(hostname, ipv4String, ipv6String) } From 959bcbb33c6ac6f309b163a471b9f38cdb6e5e6f Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Sun, 7 Jul 2019 10:19:32 +0300 Subject: [PATCH 3/3] Dockerfile.packaging: use glibc --- Dockerfile.packaging | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/Dockerfile.packaging b/Dockerfile.packaging index 81744d635..c20a9668f 100644 --- a/Dockerfile.packaging +++ b/Dockerfile.packaging @@ -14,31 +14,21 @@ # ORC_USER (default: orc_server_user): username used to login to orchestrator backend MySQL server # ORC_PASSWORD (default: orc_server_password): password used to login to orchestrator backend MySQL server -FROM alpine:3.10 +FROM golang:1.12.6 -RUN apk update -RUN apk upgrade -RUN apk add --update ruby -RUN apk add --update ruby-dev -RUN apk add --update gcc -RUN apk add --update libffi-dev -RUN apk add --update make -RUN apk add --update libc-dev -RUN apk add --update rpm +RUN apt-get update +RUN apt-get install -y ruby ruby-dev rubygems build-essential RUN gem install --no-ri --no-rdoc fpm - ENV GOPATH=/tmp/go -RUN apk add --update libcurl -RUN apk add --update rsync -RUN apk add --update gcc -RUN apk add --update g++ -RUN apk add --update build-base -RUN apk add --update bash -RUN apk add --update git -RUN apk add --update go -RUN apk add --update ruby-etc -RUN apk add --update tar +RUN apt-get install -y curl +RUN apt-get install -y rsync +RUN apt-get install -y gcc +RUN apt-get install -y g++ +RUN apt-get install -y bash +RUN apt-get install -y git +RUN apt-get install -y tar +RUN apt-get install -y rpm RUN mkdir -p $GOPATH/src/github.com/github/orchestrator WORKDIR $GOPATH/src/github.com/github/orchestrator