diff --git a/Rockerfile b/Rockerfile index 3d7b72a..d434782 100644 --- a/Rockerfile +++ b/Rockerfile @@ -39,6 +39,7 @@ ENV CGO_ENABLED=0 RUN go get -v github.com/tools/godep RUN go get -u github.com/golang/lint/golint +RUN go get github.com/ahmetb/govvv RUN mkdir -p /go/src/github.com/aacebedo/dnsdock WORKDIR /go/src/github.com/aacebedo/dnsdock @@ -60,7 +61,7 @@ RUN godep restore ENV GOARCH={{$ARCH}} WORKDIR /go/src/github.com/aacebedo/dnsdock/src ATTACH sh -RUN go build -o /tmp/output/dnsdock -ldflags "-X main.version=$(if version=$(git describe --contains HEAD 2>/dev/null); then echo $version; else echo "dev"; fi)" +RUN govvv build -o /tmp/output/dnsdock RUN golint -set_exit_status {{if eq $ARCH "amd64"}} RUN go vet diff --git a/src/core/cmdline.go b/src/core/cmdline.go index 421d8e3..0e2f634 100644 --- a/src/core/cmdline.go +++ b/src/core/cmdline.go @@ -15,38 +15,39 @@ import ( "strconv" ) -const ( - // VERSION dnsdock version - VERSION = "1.16.1" -) - // CommandLine structure handling parameter parsing -type CommandLine struct{} +type CommandLine struct{ + app *kingpin.Application +} + +func NewCommandLine(version string) (res *CommandLine) { + res = &CommandLine{} + res.app = kingpin.New("dnsdock", "Automatic DNS for docker containers.") + res.app.Version(version) + res.app.HelpFlag.Short('h') + return +} // ParseParameters Parse parameters func (cmdline *CommandLine) ParseParameters(rawParams []string) (res *utils.Config, err error) { res = utils.NewConfig() - app := kingpin.New("dnsdock", "Automatic DNS for docker containers.") - app.Version(VERSION) - app.HelpFlag.Short('h') - - nameservers := app.Flag("nameserver", "Comma separated list of DNS server(s) for unmatched requests").Default("8.8.8.8:53").Strings() - dns := app.Flag("dns", "Listen DNS requests on this address").Default(res.DnsAddr).Short('d').String() - http := app.Flag("http", "Listen HTTP requests on this address").Default(res.HttpAddr).Short('t').String() - domain := app.Flag("domain", "Domain that is appended to all requests").Default(res.Domain.String()).String() - environment := app.Flag("environment", "Optional context before domain suffix").Default("").String() - docker := app.Flag("docker", "Path to the docker socket").Default(res.DockerHost).String() - tlsverify := app.Flag("tlsverify", "Enable mTLS when connecting to docker").Default(strconv.FormatBool(res.TlsVerify)).Bool() - tlscacert := app.Flag("tlscacert", "Path to CA certificate").Default(res.TlsCaCert).String() - tlscert := app.Flag("tlscert", "Path to Client certificate").Default(res.TlsCert).String() - tlskey := app.Flag("tlskey", "Path to client certificate private key").Default(res.TlsKey).String() - ttl := app.Flag("ttl", "TTL for matched requests").Default(strconv.FormatInt(int64(res.Ttl), 10)).Int() - createAlias := app.Flag("alias", "Automatically create an alias with just the container name.").Default(strconv.FormatBool(res.CreateAlias)).Bool() - verbose := app.Flag("verbose", "Verbose mode.").Default(strconv.FormatBool(res.Verbose)).Short('v').Bool() - quiet := app.Flag("quiet", "Quiet mode.").Default(strconv.FormatBool(res.Quiet)).Short('q').Bool() + nameservers := cmdline.app.Flag("nameserver", "Comma separated list of DNS server(s) for unmatched requests").Default("8.8.8.8:53").Strings() + dns := cmdline.app.Flag("dns", "Listen DNS requests on this address").Default(res.DnsAddr).Short('d').String() + http := cmdline.app.Flag("http", "Listen HTTP requests on this address").Default(res.HttpAddr).Short('t').String() + domain := cmdline.app.Flag("domain", "Domain that is appended to all requests").Default(res.Domain.String()).String() + environment := cmdline.app.Flag("environment", "Optional context before domain suffix").Default("").String() + docker := cmdline.app.Flag("docker", "Path to the docker socket").Default(res.DockerHost).String() + tlsverify := cmdline.app.Flag("tlsverify", "Enable mTLS when connecting to docker").Default(strconv.FormatBool(res.TlsVerify)).Bool() + tlscacert := cmdline.app.Flag("tlscacert", "Path to CA certificate").Default(res.TlsCaCert).String() + tlscert := cmdline.app.Flag("tlscert", "Path to Client certificate").Default(res.TlsCert).String() + tlskey := cmdline.app.Flag("tlskey", "Path to client certificate private key").Default(res.TlsKey).String() + ttl := cmdline.app.Flag("ttl", "TTL for matched requests").Default(strconv.FormatInt(int64(res.Ttl), 10)).Int() + createAlias := cmdline.app.Flag("alias", "Automatically create an alias with just the container name.").Default(strconv.FormatBool(res.CreateAlias)).Bool() + verbose := cmdline.app.Flag("verbose", "Verbose mode.").Default(strconv.FormatBool(res.Verbose)).Short('v').Bool() + quiet := cmdline.app.Flag("quiet", "Quiet mode.").Default(strconv.FormatBool(res.Quiet)).Short('q').Bool() - kingpin.MustParse(app.Parse(rawParams)) + kingpin.MustParse(cmdline.app.Parse(rawParams)) res.Verbose = *verbose res.Quiet = *quiet diff --git a/src/main.go b/src/main.go index 9de423b..538d887 100644 --- a/src/main.go +++ b/src/main.go @@ -18,12 +18,13 @@ import ( "io/ioutil" "os" ) - +// GitSummary contains the version number +var GitSummary string var logger = logging.MustGetLogger("dnsdock.main") func main() { - var cmdLine core.CommandLine + var cmdLine = core.NewCommandLine(GitSummary) config, err := cmdLine.ParseParameters(os.Args[1:]) if err != nil { logger.Fatalf(err.Error())