From 423268f485f22f0ebcb29eae21cdfeeda35e516b Mon Sep 17 00:00:00 2001 From: Emile Vauge Date: Thu, 2 Jun 2016 11:37:51 +0200 Subject: [PATCH 1/3] Fix default configuration Signed-off-by: Emile Vauge --- examples/k8s.rc.yaml | 2 +- traefik.go | 29 ++++++++++++++--------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/examples/k8s.rc.yaml b/examples/k8s.rc.yaml index d7232b37d..43d3029d5 100644 --- a/examples/k8s.rc.yaml +++ b/examples/k8s.rc.yaml @@ -16,7 +16,7 @@ spec: spec: terminationGracePeriodSeconds: 60 containers: - - image: containous/traefik + - image: traefik name: traefik-ingress-lb imagePullPolicy: Always ports: diff --git a/traefik.go b/traefik.go index c440fd39c..68d1af1b3 100644 --- a/traefik.go +++ b/traefik.go @@ -97,27 +97,26 @@ func run(traefikConfiguration *TraefikConfiguration) { loggerMiddleware := middlewares.NewLogger(globalConfiguration.AccessLogsFile) defer loggerMiddleware.Close() + if globalConfiguration.File != nil && len(globalConfiguration.File.Filename) == 0 { + // no filename, setting to global config file + if len(traefikConfiguration.ConfigFile) != 0 { + globalConfiguration.File.Filename = traefikConfiguration.ConfigFile + } else { + log.Errorln("Error using file configuration backend, no filename defined") + } + } + + if len(globalConfiguration.EntryPoints) == 0 { + globalConfiguration.EntryPoints = map[string]*EntryPoint{"http": {Address: ":80"}} + globalConfiguration.DefaultEntryPoints = []string{"http"} + } + // logging level, err := log.ParseLevel(strings.ToLower(globalConfiguration.LogLevel)) if err != nil { log.Fatal("Error getting level", err) } log.SetLevel(level) - - if traefikConfiguration.File != nil && len(traefikConfiguration.File.Filename) == 0 { - // no filename, setting to global config file - if len(traefikConfiguration.ConfigFile) != 0 { - traefikConfiguration.File.Filename = traefikConfiguration.ConfigFile - } else { - log.Errorln("Error using file configuration backend, no filename defined") - } - } - - if len(traefikConfiguration.EntryPoints) == 0 { - traefikConfiguration.EntryPoints = map[string]*EntryPoint{"http": {Address: ":80"}} - traefikConfiguration.DefaultEntryPoints = []string{"http"} - } - if len(globalConfiguration.TraefikLogsFile) > 0 { fi, err := os.OpenFile(globalConfiguration.TraefikLogsFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) defer func() { From 3f08bb4cdf0bcd8828145a296591d0f841fcf7b4 Mon Sep 17 00:00:00 2001 From: Emile Vauge Date: Thu, 2 Jun 2016 15:17:04 +0200 Subject: [PATCH 2/3] Fix panic on help, Better version Signed-off-by: Emile Vauge --- configuration.go | 39 ++---------------------------------- glide.lock | 42 +++++++++++++++++++-------------------- glide.yaml | 4 ++-- integration/basic_test.go | 31 +++++++++++++++++++++++++++++ provider/provider.go | 6 +++--- traefik.go | 39 +++++++++++++++++++++++++++++++++--- types/types.go | 36 +++++++++++++++++++++++++++++++++ version.go | 4 ++-- 8 files changed, 133 insertions(+), 68 deletions(-) diff --git a/configuration.go b/configuration.go index 2df24ca82..aa91a16f9 100644 --- a/configuration.go +++ b/configuration.go @@ -26,7 +26,7 @@ type GlobalConfiguration struct { TraefikLogsFile string `description:"Traefik logs file"` LogLevel string `short:"l" description:"Log level"` EntryPoints EntryPoints `description:"Entrypoints definition using format: --entryPoints='Name:http Address::8000 Redirect.EntryPoint:https' --entryPoints='Name:https Address::4442 TLS:tests/traefik.crt,tests/traefik.key'"` - Constraints Constraints `description:"Filter services by constraint, matching with service tags."` + Constraints types.Constraints `description:"Filter services by constraint, matching with service tags."` ACME *acme.ACME `description:"Enable ACME (Let's Encrypt): automatic SSL"` DefaultEntryPoints DefaultEntryPoints `description:"Entrypoints to be used by frontends that do not specify any entrypoint"` ProvidersThrottleDuration time.Duration `description:"Backends throttle duration: minimum duration between 2 events from providers before applying a new configuration. It avoids unnecessary reloads if multiples events are sent in a short amount of time."` @@ -143,42 +143,7 @@ func (ep *EntryPoints) SetValue(val interface{}) { // Type is type of the struct func (ep *EntryPoints) Type() string { - return fmt.Sprint("entrypoints²") -} - -// Constraints holds a Constraint parser -type Constraints []types.Constraint - -//Set []*Constraint -func (cs *Constraints) Set(str string) error { - exps := strings.Split(str, ",") - if len(exps) == 0 { - return errors.New("Bad Constraint format: " + str) - } - for _, exp := range exps { - constraint, err := types.NewConstraint(exp) - if err != nil { - return err - } - *cs = append(*cs, *constraint) - } - return nil -} - -//Get []*Constraint -func (cs *Constraints) Get() interface{} { return []types.Constraint(*cs) } - -//String returns []*Constraint in string -func (cs *Constraints) String() string { return fmt.Sprintf("%+v", *cs) } - -//SetValue sets []*Constraint into the parser -func (cs *Constraints) SetValue(val interface{}) { - *cs = Constraints(val.([]types.Constraint)) -} - -// Type exports the Constraints type as a string -func (cs *Constraints) Type() string { - return fmt.Sprint("constraint²") + return fmt.Sprint("entrypoints") } // EntryPoint holds an entry point configuration of the reverse proxy (ip, port, TLS...) diff --git a/glide.lock b/glide.lock index 69e24ab89..05374f993 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: 1d42530971835a5a1e593e8efc54f28f2714cb8d1dfcb333e3b9ba92ef1917cc -updated: 2016-05-30T16:53:17.058435869+02:00 +hash: dc59755b72e71945a21135c5a37e4a5c11ae511ac7404d1440166ea0aed736c4 +updated: 2016-06-02T15:11:52.77657652+02:00 imports: - name: github.com/boltdb/bolt version: dfb21201d9270c1082d5fb0f07f500311ff72f18 @@ -10,15 +10,15 @@ imports: subpackages: - fun - name: github.com/cenkalti/backoff - version: c29158af31815ccc31ca29c86c121bc39e00d3d8 + version: a6030178a585d5972d4d33ce61f4a1fa40eaaed0 - name: github.com/codahale/hdrhistogram version: 9208b142303c12d8899bae836fd524ac9338b4fd - name: github.com/codegangsta/cli version: bf4a526f48af7badd25d2cb02d587e1b01be3b50 - name: github.com/codegangsta/negroni - version: ffbc66b612ee3eac2eba29aedce4c3a65e4dd0a1 + version: fb7b7c045dfb05dc81a5c3688c568550b5bd6e36 - name: github.com/containous/flaeg - version: a208db24c0e580be76efed167736fe3204c7c954 + version: b98687da5c323650f4513fda6b6203fcbdec9313 - name: github.com/containous/oxy version: 183212964e13e7b8afe01a08b193d04300554a68 subpackages: @@ -29,7 +29,7 @@ imports: - stream - utils - name: github.com/containous/staert - version: 9f815ef829b66de3519fea6c0b8d4708eb9472d4 + version: e2aa88e235a02dd52aa1d5d9de75f9d9139d1602 - name: github.com/coreos/etcd version: c400d05d0aa73e21e431c16145e558d624098018 subpackages: @@ -43,7 +43,7 @@ imports: subpackages: - spew - name: github.com/docker/distribution - version: 5bbf65499960b184fe8e0f045397375e1a6722b8 + version: bb330cd684eb4afab9cc4f2453d7c8918099d7ee subpackages: - reference - digest @@ -75,7 +75,7 @@ imports: - tlsconfig - nat - name: github.com/docker/go-units - version: 5d2041e26a699eaca682e2ea41c8f891e1060444 + version: 09dda9d4b0d748c57c14048906d3d094a58ec0c9 - name: github.com/docker/libcompose version: 8ee7bcc364f7b8194581a3c6bd9fa019467c7873 - name: github.com/docker/libkv @@ -87,7 +87,7 @@ imports: - store/etcd - store/zookeeper - name: github.com/donovanhide/eventsource - version: c3f57f280ec708df24886d9e62f2fd178d69d8e8 + version: fd1de70867126402be23c306e1ce32828455d85b - name: github.com/elazarl/go-bindata-assetfs version: 57eb5e1fc594ad4b0b1dbea7b286d299e0cb43c2 - name: github.com/gambol99/go-marathon @@ -99,11 +99,11 @@ imports: subpackages: - query - name: github.com/gorilla/context - version: a8d44e7d8e4d532b6a27a02dd82abb31cc1b01bd + version: aed02d124ae4a0e94fea4541c8effd05bf0c8296 - name: github.com/gorilla/mux - version: 9c19ed558d5df4da88e2ade9c8940d742aef0e7e + version: bd09be08ed4377796d312df0a45314e11b8f5dc1 - name: github.com/hashicorp/consul - version: f6fef66e1bf17be4f3c9855fbec6de802ca6bd7d + version: ebf7ea1d759184c02a5bb5263a7c52d29838ffc3 subpackages: - api - name: github.com/hashicorp/go-cleanhttp @@ -136,27 +136,29 @@ imports: - name: github.com/ogier/pflag version: 45c278ab3607870051a2ea9040bb85fcb8557481 - name: github.com/opencontainers/runc - version: d2d09b9bcd0573c58d7cd94e57bd7555af0c2072 + version: 6c485e6902bb9dd77b8234042b8f00e20ef87a18 subpackages: - libcontainer/user - name: github.com/parnurzeal/gorequest - version: 2169dfca686cfcbefc983a98a25e9c22a2815be4 + version: f17fef20c518e688f4edb3eb2af148462ecab3ef - name: github.com/pmezard/go-difflib version: d8ed2627bdf02c080bf22230dbb337003b7aba2d subpackages: - difflib +- name: github.com/ryanuber/go-glob + version: 572520ed46dbddaed19ea3d9541bdd0494163693 - name: github.com/samuel/go-zookeeper - version: 6eb1b09c6ce23f305f4c81bf748b22fbc6f3f9e9 + version: 4b20de542e40ed2b89d65ae195fc20a330919b92 subpackages: - zk - name: github.com/Sirupsen/logrus - version: 6d9ae300aaf85d6acd2e5424081c7fcddb21dab8 + version: f3cfb454f4c209e6668c95216c4744b8fddb2356 - name: github.com/streamrail/concurrent-map version: 65a174a3a4188c0b7099acbc6cfa0c53628d3287 - name: github.com/stretchr/objx version: cbeaeb16a013161a98496fad62933b1d21786672 - name: github.com/stretchr/testify - version: 6cb3b85ef5a0efef77caef88363ec4d4b5c0976d + version: 8d64eb7173c7753d6419fd4a9caf057398611364 subpackages: - mock - assert @@ -165,7 +167,7 @@ imports: - name: github.com/unrolled/render version: 198ad4d8b8a4612176b804ca10555b222a086b40 - name: github.com/vdemeester/docker-events - version: b308d2e8d639d928c882913bcb4f85b3a84c7a07 + version: 20e6d2db238723e68197a9e3c6c34c99a9893a9c - name: github.com/vdemeester/shakers version: 24d7f1d6a71aa5d9cbe7390e4afb66b7eef9e1b3 - name: github.com/vulcand/oxy @@ -184,7 +186,7 @@ imports: - plugin - router - name: github.com/xenolf/lego - version: b119bc45fbd1cc71348003541aac9d3a7da63654 + version: 30a7a8e8821de3532192d1240a45e53c6204f603 subpackages: - acme - name: golang.org/x/crypto @@ -213,6 +215,4 @@ imports: subpackages: - cipher - json -- name: github.com/ryanuber/go-glob - version: 572520ed46dbddaed19ea3d9541bdd0494163693 devImports: [] diff --git a/glide.yaml b/glide.yaml index 4636007ae..9a1e4385c 100644 --- a/glide.yaml +++ b/glide.yaml @@ -8,7 +8,7 @@ import: - package: github.com/cenkalti/backoff - package: github.com/codegangsta/negroni - package: github.com/containous/flaeg - version: a208db24c0e580be76efed167736fe3204c7c954 + version: b98687da5c323650f4513fda6b6203fcbdec9313 - package: github.com/containous/oxy subpackages: - cbreaker @@ -18,7 +18,7 @@ import: - stream - utils - package: github.com/containous/staert - version: 9f815ef829b66de3519fea6c0b8d4708eb9472d4 + version: e2aa88e235a02dd52aa1d5d9de75f9d9139d1602 - package: github.com/docker/engine-api version: 3d3d0b6c9d2651aac27f416a6da0224c1875b3eb subpackages: diff --git a/integration/basic_test.go b/integration/basic_test.go index 7e5549174..1ef8521cc 100644 --- a/integration/basic_test.go +++ b/integration/basic_test.go @@ -57,3 +57,34 @@ func (s *SimpleSuite) TestWithWebConfig(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(resp.StatusCode, checker.Equals, 200) } + +func (s *SimpleSuite) TestDefaultEntryPoints(c *check.C) { + cmd := exec.Command(traefikBinary, "--debug") + + var b bytes.Buffer + cmd.Stdout = &b + cmd.Stderr = &b + + cmd.Start() + time.Sleep(500 * time.Millisecond) + defer cmd.Process.Kill() + output := b.Bytes() + + c.Assert(string(output), checker.Contains, "\\\"DefaultEntryPoints\\\":[\\\"http\\\"]") +} + +func (s *SimpleSuite) TestPrintHelp(c *check.C) { + cmd := exec.Command(traefikBinary, "--help") + + var b bytes.Buffer + cmd.Stdout = &b + cmd.Stderr = &b + + cmd.Start() + time.Sleep(500 * time.Millisecond) + defer cmd.Process.Kill() + output := b.Bytes() + + c.Assert(string(output), checker.Not(checker.Contains), "panic:") + c.Assert(string(output), checker.Contains, "Usage:") +} diff --git a/provider/provider.go b/provider/provider.go index d983ae7ca..fafc39c7e 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -22,9 +22,9 @@ type Provider interface { // BaseProvider should be inherited by providers type BaseProvider struct { - Watch bool `description:"Watch provider"` - Filename string `description:"Override default configuration template. For advanced users :)"` - Constraints []types.Constraint `description:"Filter services by constraint, matching with Traefik tags."` + Watch bool `description:"Watch provider"` + Filename string `description:"Override default configuration template. For advanced users :)"` + Constraints types.Constraints `description:"Filter services by constraint, matching with Traefik tags."` } // MatchConstraints must match with EVERY single contraint diff --git a/traefik.go b/traefik.go index 68d1af1b3..a8be2edd1 100644 --- a/traefik.go +++ b/traefik.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "fmt" log "github.com/Sirupsen/logrus" "github.com/containous/flaeg" "github.com/containous/staert" @@ -15,8 +16,14 @@ import ( "reflect" "runtime" "strings" + "text/template" ) +var versionTemplate = `Version: {{.Version}} +Go version: {{.GoVersion}} +Built: {{.BuildTime}} +OS/Arch: {{.Os}}/{{.Arch}}` + func main() { runtime.GOMAXPROCS(runtime.NumCPU()) @@ -43,8 +50,31 @@ Complete documentation is available at https://traefik.io`, Config: struct{}{}, DefaultPointersConfig: struct{}{}, Run: func() error { - fmtlog.Println(Version + " built on the " + BuildDate) + tmpl, err := template.New("").Parse(versionTemplate) + if err != nil { + return err + } + + v := struct { + Version string + GoVersion string + BuildTime string + Os string + Arch string + }{ + Version: Version, + GoVersion: runtime.Version(), + BuildTime: BuildDate, + Os: runtime.GOOS, + Arch: runtime.GOARCH, + } + + if err := tmpl.Execute(os.Stdout, v); err != nil { + return err + } + fmt.Printf("\n") return nil + }, } @@ -53,8 +83,7 @@ Complete documentation is available at https://traefik.io`, //add custom parsers f.AddParser(reflect.TypeOf(EntryPoints{}), &EntryPoints{}) f.AddParser(reflect.TypeOf(DefaultEntryPoints{}), &DefaultEntryPoints{}) - f.AddParser(reflect.TypeOf([]types.Constraint{}), &Constraints{}) - f.AddParser(reflect.TypeOf(Constraints{}), &Constraints{}) + f.AddParser(reflect.TypeOf(types.Constraints{}), &types.Constraints{}) f.AddParser(reflect.TypeOf(provider.Namespaces{}), &provider.Namespaces{}) f.AddParser(reflect.TypeOf([]acme.Domain{}), &acme.Domains{}) @@ -111,6 +140,10 @@ func run(traefikConfiguration *TraefikConfiguration) { globalConfiguration.DefaultEntryPoints = []string{"http"} } + if globalConfiguration.Debug { + globalConfiguration.LogLevel = "DEBUG" + } + // logging level, err := log.ParseLevel(strings.ToLower(globalConfiguration.LogLevel)) if err != nil { diff --git a/types/types.go b/types/types.go index 557a31b20..dcac6bd46 100644 --- a/types/types.go +++ b/types/types.go @@ -2,6 +2,7 @@ package types import ( "errors" + "fmt" "github.com/ryanuber/go-glob" "strings" ) @@ -150,3 +151,38 @@ func (c *Constraint) MatchConstraintWithAtLeastOneTag(tags []string) bool { } return false } + +//Set []*Constraint +func (cs *Constraints) Set(str string) error { + exps := strings.Split(str, ",") + if len(exps) == 0 { + return errors.New("Bad Constraint format: " + str) + } + for _, exp := range exps { + constraint, err := NewConstraint(exp) + if err != nil { + return err + } + *cs = append(*cs, *constraint) + } + return nil +} + +// Constraints holds a Constraint parser +type Constraints []Constraint + +//Get []*Constraint +func (cs *Constraints) Get() interface{} { return []Constraint(*cs) } + +//String returns []*Constraint in string +func (cs *Constraints) String() string { return fmt.Sprintf("%+v", *cs) } + +//SetValue sets []*Constraint into the parser +func (cs *Constraints) SetValue(val interface{}) { + *cs = Constraints(val.(Constraints)) +} + +// Type exports the Constraints type as a string +func (cs *Constraints) Type() string { + return fmt.Sprint("constraint") +} diff --git a/version.go b/version.go index 15a6ee9dd..10f7cdb3c 100644 --- a/version.go +++ b/version.go @@ -2,7 +2,7 @@ package main var ( // Version holds the current version of traefik. - Version = "" + Version = "dev" // BuildDate holds the build date of traefik. - BuildDate = "" + BuildDate = "I don't remember exactly" ) From 3c3b179c290e0ef4f5dacfee81652144c4b50a04 Mon Sep 17 00:00:00 2001 From: Emile Vauge Date: Thu, 2 Jun 2016 15:29:36 +0200 Subject: [PATCH 3/3] Deploy PR Docker image Signed-off-by: Emile Vauge --- .travis.yml | 1 + Makefile | 3 +++ script/deploy-pr.sh | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100755 script/deploy-pr.sh diff --git a/.travis.yml b/.travis.yml index 74fcb4bcc..adcc5e2c8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,3 +29,4 @@ script: - make image after_success: - make deploy +- make deploy-pr diff --git a/Makefile b/Makefile index 9e6a5d15d..8ca374210 100644 --- a/Makefile +++ b/Makefile @@ -85,5 +85,8 @@ fmt: deploy: ./script/deploy.sh +deploy-pr: + ./script/deploy-pr.sh + help: ## this help @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) diff --git a/script/deploy-pr.sh b/script/deploy-pr.sh new file mode 100755 index 000000000..7fd79407c --- /dev/null +++ b/script/deploy-pr.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -e + +if ([ "$TRAVIS_BRANCH" = "master" ] && [ -z "$TRAVIS_TAG" ]) && [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ "$DOCKER_VERSION" = "1.10.1" ]; then + echo "Deploying PR..." +else + echo "Skipping deploy PR" + exit 0 +fi + +COMMENT=$(git log -1 --pretty=%B) +PR=$(echo $COMMENT | grep -oP "Merge pull request #\K(([0-9]*))(?=.*)") + +if [ -z "$PR" ]; then + echo "Unable to get PR number: $PR from: $COMMENT" + exit 0 +fi + +# create docker image containous/traefik +echo "Updating docker containous/traefik image..." +docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS +docker tag containous/traefik containous/traefik:pr-${PR} +docker push containous/traefik:pr-${PR} + +echo "Deployed"