From eb87d5cb0ea5ce5f0fc61cf1585f6f92a47685f9 Mon Sep 17 00:00:00 2001 From: Ying Li Date: Wed, 21 Sep 2016 19:49:13 -0700 Subject: [PATCH 1/6] Do not support SIGUSR1 and SIGUSR2 syscall handling in windows Signed-off-by: Ying Li --- cmd/notary-server/config.go | 31 ---------------------- cmd/notary-server/main.go | 7 ++++- cmd/notary-server/main_test.go | 30 --------------------- cmd/notary-signer/main.go | 7 +++++ const.go | 14 +--------- const_nowindows.go | 16 +++++++++++ const_windows.go | 8 ++++++ docs/reference/server-config.md | 4 ++- docs/reference/signer-config.md | 38 +++++++++++++++++++++++++++ utils/configuration.go | 19 ++++++++++++++ utils/configuration_nowindows.go | 29 ++++++++++++++++++++ utils/configuration_nowindows_test.go | 33 +++++++++++++++++++++++ utils/configuration_test.go | 27 +++++++++++++++++++ utils/configuration_windows.go | 9 +++++++ 14 files changed, 196 insertions(+), 76 deletions(-) create mode 100644 const_nowindows.go create mode 100644 const_windows.go create mode 100644 utils/configuration_nowindows.go create mode 100644 utils/configuration_nowindows_test.go create mode 100644 utils/configuration_windows.go diff --git a/cmd/notary-server/config.go b/cmd/notary-server/config.go index 91eb6c0c6..daff08550 100644 --- a/cmd/notary-server/config.go +++ b/cmd/notary-server/config.go @@ -3,12 +3,9 @@ package main import ( "crypto/tls" "fmt" - "os" - "os/signal" "path" "strconv" "strings" - "syscall" "time" "github.com/Sirupsen/logrus" @@ -293,31 +290,3 @@ func parseServerConfig(configFilePath string, hRegister healthRegister, doBootst ConsistentCacheControlConfig: consistentCache, }, nil } - -func setupSignalTrap() { - c := make(chan os.Signal, 1) - signal.Notify(c, notary.NotarySupportedSignals...) - go func() { - for { - signalHandle(<-c) - } - }() -} - -// signalHandle will increase/decrease the logging level via the signal we get. -func signalHandle(sig os.Signal) { - switch sig { - case syscall.SIGUSR1: - if err := utils.AdjustLogLevel(true); err != nil { - fmt.Printf("Attempt to increase log level failed, will remain at %s level, error: %s\n", logrus.GetLevel(), err) - return - } - case syscall.SIGUSR2: - if err := utils.AdjustLogLevel(false); err != nil { - fmt.Printf("Attempt to decrease log level failed, will remain at %s level, error: %s\n", logrus.GetLevel(), err) - return - } - } - - fmt.Println("Successfully setting log level to ", logrus.GetLevel()) -} diff --git a/cmd/notary-server/main.go b/cmd/notary-server/main.go index c2cdf56e7..232e486c7 100644 --- a/cmd/notary-server/main.go +++ b/cmd/notary-server/main.go @@ -7,10 +7,12 @@ import ( "net/http" _ "net/http/pprof" "os" + "os/signal" "github.com/Sirupsen/logrus" "github.com/docker/distribution/health" "github.com/docker/notary/server" + "github.com/docker/notary/utils" "github.com/docker/notary/version" ) @@ -61,7 +63,10 @@ func main() { logrus.Fatal(err.Error()) } - setupSignalTrap() + c := utils.SetupSignalTrap(utils.LogLevelSignalHandle) + if c != nil { + defer signal.Stop(c) + } if flagStorage.doBootstrap { err = bootstrap(ctx) diff --git a/cmd/notary-server/main_test.go b/cmd/notary-server/main_test.go index 14fbd69bc..4bcc0c3fb 100644 --- a/cmd/notary-server/main_test.go +++ b/cmd/notary-server/main_test.go @@ -6,14 +6,11 @@ import ( "fmt" "io/ioutil" "os" - "path/filepath" "reflect" "strings" - "syscall" "testing" "time" - "github.com/Sirupsen/logrus" "github.com/docker/distribution/health" "github.com/docker/notary" "github.com/docker/notary/server/storage" @@ -416,30 +413,3 @@ func TestSampleConfig(t *testing.T) { // once for the DB, once for the trust service require.Equal(t, registerCalled, 2) } - -func TestSignalHandle(t *testing.T) { - tempdir, err := ioutil.TempDir("", "test-signal-handle") - require.NoError(t, err) - defer os.RemoveAll(tempdir) - f, err := os.Create(filepath.Join(tempdir, "testSignalHandle.json")) - require.NoError(t, err) - - f.WriteString(`{"logging": {"level": "info"}}`) - - v := viper.New() - utils.SetupViper(v, "envPrefix") - err = utils.ParseViper(v, f.Name()) - require.NoError(t, err) - - // Info + SIGUSR1 -> Debug - signalHandle(syscall.SIGUSR1) - require.Equal(t, logrus.GetLevel(), logrus.DebugLevel) - - // Debug + SIGUSR1 -> Debug - signalHandle(syscall.SIGUSR1) - require.Equal(t, logrus.GetLevel(), logrus.DebugLevel) - - // Debug + SIGUSR2-> Info - signalHandle(syscall.SIGUSR2) - require.Equal(t, logrus.GetLevel(), logrus.InfoLevel) -} diff --git a/cmd/notary-signer/main.go b/cmd/notary-signer/main.go index d15f124ae..d7459fc62 100644 --- a/cmd/notary-signer/main.go +++ b/cmd/notary-signer/main.go @@ -6,8 +6,10 @@ import ( "log" "net/http" "os" + "os/signal" "github.com/Sirupsen/logrus" + "github.com/docker/notary/utils" "github.com/docker/notary/version" _ "github.com/go-sql-driver/mysql" ) @@ -66,6 +68,11 @@ func main() { log.Println("RPC server listening on", signerConfig.GRPCAddr) } + c := utils.SetupSignalTrap(utils.LogLevelSignalHandle) + if c != nil { + defer signal.Stop(c) + } + grpcServer.Serve(lis) } diff --git a/const.go b/const.go index 19752072b..0c4d4037b 100644 --- a/const.go +++ b/const.go @@ -1,10 +1,6 @@ package notary -import ( - "os" - "syscall" - "time" -) +import "time" // application wide constants const ( @@ -72,11 +68,3 @@ var NotaryDefaultExpiries = map[string]time.Duration{ "snapshot": NotarySnapshotExpiry, "timestamp": NotaryTimestampExpiry, } - -// NotarySupportedSignals contains the signals we would like to capture: -// - SIGUSR1, indicates a increment of the log level. -// - SIGUSR2, indicates a decrement of the log level. -var NotarySupportedSignals = []os.Signal{ - syscall.SIGUSR1, - syscall.SIGUSR2, -} diff --git a/const_nowindows.go b/const_nowindows.go new file mode 100644 index 000000000..67551717a --- /dev/null +++ b/const_nowindows.go @@ -0,0 +1,16 @@ +// +build !windows + +package notary + +import ( + "os" + "syscall" +) + +// NotarySupportedSignals contains the signals we would like to capture: +// - SIGUSR1, indicates a increment of the log level. +// - SIGUSR2, indicates a decrement of the log level. +var NotarySupportedSignals = []os.Signal{ + syscall.SIGUSR1, + syscall.SIGUSR2, +} diff --git a/const_windows.go b/const_windows.go new file mode 100644 index 000000000..e2dff0e4b --- /dev/null +++ b/const_windows.go @@ -0,0 +1,8 @@ +// +build windows + +package notary + +import "os" + +// NotarySupportedSignals does not contain any signals, because SIGUSR1/2 are not supported on windows +var NotarySupportedSignals = []os.Signal{} diff --git a/docs/reference/server-config.md b/docs/reference/server-config.md index 2143bbe5f..d1cab23b9 100644 --- a/docs/reference/server-config.md +++ b/docs/reference/server-config.md @@ -362,10 +362,12 @@ Example: ## Hot logging level reload -We don't support completely reloading notary configuration files yet at present. What we support for now is: +We don't support completely reloading notary configuration files yet at present. What we support for Linux and OSX now is: - increase logging level by signaling `SIGUSR1` - decrease logging level by signaling `SIGUSR2` +No signals and no dynamic logging level changes are supported for Windows yet. + Example: To increase logging level diff --git a/docs/reference/signer-config.md b/docs/reference/signer-config.md index 7ced28e17..f5c35e0ae 100644 --- a/docs/reference/signer-config.md +++ b/docs/reference/signer-config.md @@ -210,6 +210,44 @@ The environment variables for the older passwords are optional, but Notary Signer will not be able to decrypt older keys if they are not provided, and attempts to sign data using those keys will fail. +## Hot logging level reload +We don't support completely reloading notary signer configuration files yet at present. What we support for Linux and OSX now is: +- increase logging level by signaling `SIGUSR1` +- decrease logging level by signaling `SIGUSR2` + +No signals and no dynamic logging level changes are supported for Windows yet. + +Example: + +To increase logging level +``` +$ kill -s SIGUSR1 PID + +or + +$ docker exec -i CONTAINER_ID kill -s SIGUSR1 PID +``` + +To decrease logging level +``` +$ kill -s SIGUSR2 PID + +or + +$ docker exec -i CONTAINER_ID kill -s SIGUSR2 PID +``` +PID is the process id of `notary-signer` and it may not the PID 1 process if you are running +the container with some kind of wrapper startup script or something. + +You can get the PID of `notary-signer` through +``` +$ docker exec CONTAINER_ID ps aux + +or + +$ ps aux | grep "notary-signer -config" | grep -v "grep" +``` + ## Related information diff --git a/utils/configuration.go b/utils/configuration.go index f94b73a27..cc97810da 100644 --- a/utils/configuration.go +++ b/utils/configuration.go @@ -5,6 +5,8 @@ package utils import ( "crypto/tls" "fmt" + "os" + "os/signal" "path/filepath" "strings" @@ -244,3 +246,20 @@ func AdjustLogLevel(increment bool) error { logrus.SetLevel(lvl) return nil } + +// SetupSignalTrap is a utility to trap supported signals hand handle them (currently by increasing logging) +func SetupSignalTrap(handler func(os.Signal)) chan os.Signal { + if len(notary.NotarySupportedSignals) == 0 { + return nil + + } + c := make(chan os.Signal, 1) + signal.Notify(c, notary.NotarySupportedSignals...) + go func() { + for { + handler(<-c) + } + }() + + return c +} diff --git a/utils/configuration_nowindows.go b/utils/configuration_nowindows.go new file mode 100644 index 000000000..22c7528dd --- /dev/null +++ b/utils/configuration_nowindows.go @@ -0,0 +1,29 @@ +// +build !windows + +package utils + +import ( + "fmt" + "os" + "syscall" + + "github.com/Sirupsen/logrus" +) + +// LogLevelSignalHandle will increase/decrease the logging level via the signal we get. +func LogLevelSignalHandle(sig os.Signal) { + switch sig { + case syscall.SIGUSR1: + if err := AdjustLogLevel(true); err != nil { + fmt.Printf("Attempt to increase log level failed, will remain at %s level, error: %s\n", logrus.GetLevel(), err) + return + } + case syscall.SIGUSR2: + if err := AdjustLogLevel(false); err != nil { + fmt.Printf("Attempt to decrease log level failed, will remain at %s level, error: %s\n", logrus.GetLevel(), err) + return + } + } + + fmt.Println("Successfully setting log level to ", logrus.GetLevel()) +} diff --git a/utils/configuration_nowindows_test.go b/utils/configuration_nowindows_test.go new file mode 100644 index 000000000..d414af8fc --- /dev/null +++ b/utils/configuration_nowindows_test.go @@ -0,0 +1,33 @@ +// +build !windows + +package utils + +import ( + "io/ioutil" + "os" + "syscall" + "testing" + + "github.com/Sirupsen/logrus" + "github.com/stretchr/testify/require" +) + +func TestLogLevelSignalHandle(t *testing.T) { + tempdir, err := ioutil.TempDir("", "test-signal-handle") + require.NoError(t, err) + defer os.RemoveAll(tempdir) + + logrus.SetLevel(logrus.InfoLevel) + + // Info + SIGUSR1 -> Debug + LogLevelSignalHandle(syscall.SIGUSR1) + require.Equal(t, logrus.GetLevel(), logrus.DebugLevel) + + // Debug + SIGUSR1 -> Debug + LogLevelSignalHandle(syscall.SIGUSR1) + require.Equal(t, logrus.GetLevel(), logrus.DebugLevel) + + // Debug + SIGUSR2-> Info + LogLevelSignalHandle(syscall.SIGUSR2) + require.Equal(t, logrus.GetLevel(), logrus.InfoLevel) +} diff --git a/utils/configuration_test.go b/utils/configuration_test.go index bf0c5f71a..7dbaf859d 100644 --- a/utils/configuration_test.go +++ b/utils/configuration_test.go @@ -6,8 +6,10 @@ import ( "fmt" "io/ioutil" "os" + "os/signal" "path/filepath" "reflect" + "syscall" "testing" "github.com/Sirupsen/logrus" @@ -560,3 +562,28 @@ func TestAdjustLogLevel(t *testing.T) { err = AdjustLogLevel(optDecrement) require.Error(t, err) } + +func TestSetSignalTrap(t *testing.T) { + var signalsPassedOn map[string]struct{} + + signalHandler := func(s os.Signal) { + signalsPassedOn := make(map[string]struct{}) + signalsPassedOn[s.String()] = struct{}{} + } + c := SetupSignalTrap(signalHandler) + + if len(notary.NotarySupportedSignals) == 0 { // currently, windows only + require.Nil(t, c) + } else { + require.NotNil(t, c) + defer signal.Stop(c) + } + + for _, s := range notary.NotarySupportedSignals { + syscallSignal, ok := s.(syscall.Signal) + require.True(t, ok) + require.NoError(t, syscall.Kill(syscall.Getpid(), syscallSignal)) + require.Len(t, signalsPassedOn, 0) + require.NotNil(t, signalsPassedOn[s.String()]) + } +} diff --git a/utils/configuration_windows.go b/utils/configuration_windows.go new file mode 100644 index 000000000..bb43c7e3b --- /dev/null +++ b/utils/configuration_windows.go @@ -0,0 +1,9 @@ +// +build windows + +package utils + +import "os" + +// LogLevelSignalHandle will do nothing, because we aren't currently supporting signal handling in windows +func LogLevelSignalHandle(sig os.Signal) { +} From 39b42d9ee298007b0ba224985d44ba1733d1c11d Mon Sep 17 00:00:00 2001 From: Ying Li Date: Thu, 22 Sep 2016 14:45:56 -0700 Subject: [PATCH 2/6] Update tests so the same set of log level expectations can be tested both for using with handles and with AdjustLogLevel Signed-off-by: Ying Li --- utils/configuration_nowindows.go | 2 +- utils/configuration_nowindows_test.go | 29 +++----- utils/configuration_test.go | 103 ++++++++++---------------- 3 files changed, 49 insertions(+), 85 deletions(-) diff --git a/utils/configuration_nowindows.go b/utils/configuration_nowindows.go index 22c7528dd..dc586a669 100644 --- a/utils/configuration_nowindows.go +++ b/utils/configuration_nowindows.go @@ -25,5 +25,5 @@ func LogLevelSignalHandle(sig os.Signal) { } } - fmt.Println("Successfully setting log level to ", logrus.GetLevel()) + fmt.Println("Successfully setting log level to", logrus.GetLevel()) } diff --git a/utils/configuration_nowindows_test.go b/utils/configuration_nowindows_test.go index d414af8fc..eb02e64d6 100644 --- a/utils/configuration_nowindows_test.go +++ b/utils/configuration_nowindows_test.go @@ -3,8 +3,6 @@ package utils import ( - "io/ioutil" - "os" "syscall" "testing" @@ -13,21 +11,14 @@ import ( ) func TestLogLevelSignalHandle(t *testing.T) { - tempdir, err := ioutil.TempDir("", "test-signal-handle") - require.NoError(t, err) - defer os.RemoveAll(tempdir) - - logrus.SetLevel(logrus.InfoLevel) - - // Info + SIGUSR1 -> Debug - LogLevelSignalHandle(syscall.SIGUSR1) - require.Equal(t, logrus.GetLevel(), logrus.DebugLevel) - - // Debug + SIGUSR1 -> Debug - LogLevelSignalHandle(syscall.SIGUSR1) - require.Equal(t, logrus.GetLevel(), logrus.DebugLevel) - - // Debug + SIGUSR2-> Info - LogLevelSignalHandle(syscall.SIGUSR2) - require.Equal(t, logrus.GetLevel(), logrus.InfoLevel) + signalOperation := map[bool]syscall.Signal{ + optIncrement: syscall.SIGUSR1, + optDecrement: syscall.SIGUSR2, + } + + for _, expt := range logLevelExpectations { + logrus.SetLevel(expt.startLevel) + LogLevelSignalHandle(signalOperation[expt.increment]) + require.Equal(t, expt.endLevel, logrus.GetLevel()) + } } diff --git a/utils/configuration_test.go b/utils/configuration_test.go index 7dbaf859d..0e1357d74 100644 --- a/utils/configuration_test.go +++ b/utils/configuration_test.go @@ -492,75 +492,48 @@ func TestParseViperWithValidFile(t *testing.T) { require.Equal(t, "debug", v.GetString("logging.level")) } -func TestAdjustLogLevel(t *testing.T) { - - // To indicate increment or decrement the logging level - optIncrement := true - optDecrement := false - - // Debug is the highest level for now, so we expected a error here - logrus.SetLevel(logrus.DebugLevel) - err := AdjustLogLevel(optIncrement) - require.Error(t, err) - // Debug -> Info - logrus.SetLevel(logrus.DebugLevel) - err = AdjustLogLevel(optDecrement) - require.NoError(t, err) - require.Equal(t, logrus.InfoLevel, logrus.GetLevel()) - - // Info -> Debug - logrus.SetLevel(logrus.InfoLevel) - err = AdjustLogLevel(optIncrement) - require.NoError(t, err) - require.Equal(t, logrus.DebugLevel, logrus.GetLevel()) - // Info -> Warn - logrus.SetLevel(logrus.InfoLevel) - err = AdjustLogLevel(optDecrement) - require.NoError(t, err) - require.Equal(t, logrus.WarnLevel, logrus.GetLevel()) +type logLevelTests struct { + startLevel logrus.Level + endLevel logrus.Level + increment bool +} - // Warn -> Info - logrus.SetLevel(logrus.WarnLevel) - err = AdjustLogLevel(optIncrement) - require.NoError(t, err) - require.Equal(t, logrus.InfoLevel, logrus.GetLevel()) - // Warn -> Error - logrus.SetLevel(logrus.WarnLevel) - err = AdjustLogLevel(optDecrement) - require.NoError(t, err) - require.Equal(t, logrus.ErrorLevel, logrus.GetLevel()) +const ( + optIncrement = true + optDecrement = false +) - // Error -> Warn - logrus.SetLevel(logrus.ErrorLevel) - err = AdjustLogLevel(optIncrement) - require.NoError(t, err) - require.Equal(t, logrus.WarnLevel, logrus.GetLevel()) - // Error -> Fatal - logrus.SetLevel(logrus.ErrorLevel) - err = AdjustLogLevel(optDecrement) - require.NoError(t, err) - require.Equal(t, logrus.FatalLevel, logrus.GetLevel()) +var logLevelExpectations = []logLevelTests{ + // highest: Debug, lowest: Panic. Incrementing brings everything up one level, except debug which is max level + {startLevel: logrus.DebugLevel, increment: optIncrement, endLevel: logrus.DebugLevel}, + {startLevel: logrus.InfoLevel, increment: optIncrement, endLevel: logrus.DebugLevel}, + {startLevel: logrus.WarnLevel, increment: optIncrement, endLevel: logrus.InfoLevel}, + {startLevel: logrus.ErrorLevel, increment: optIncrement, endLevel: logrus.WarnLevel}, + {startLevel: logrus.FatalLevel, increment: optIncrement, endLevel: logrus.ErrorLevel}, + {startLevel: logrus.PanicLevel, increment: optIncrement, endLevel: logrus.FatalLevel}, + + // highest: Debug, lowest: Panic. Decrementing brings everything down one level, except panic which is min level + {startLevel: logrus.DebugLevel, increment: optDecrement, endLevel: logrus.InfoLevel}, + {startLevel: logrus.InfoLevel, increment: optDecrement, endLevel: logrus.WarnLevel}, + {startLevel: logrus.WarnLevel, increment: optDecrement, endLevel: logrus.ErrorLevel}, + {startLevel: logrus.ErrorLevel, increment: optDecrement, endLevel: logrus.FatalLevel}, + {startLevel: logrus.FatalLevel, increment: optDecrement, endLevel: logrus.PanicLevel}, + {startLevel: logrus.PanicLevel, increment: optDecrement, endLevel: logrus.PanicLevel}, +} - // Fatal -> Error - logrus.SetLevel(logrus.FatalLevel) - err = AdjustLogLevel(optIncrement) - require.NoError(t, err) - require.Equal(t, logrus.ErrorLevel, logrus.GetLevel()) - // Fatal -> Panic - logrus.SetLevel(logrus.FatalLevel) - err = AdjustLogLevel(optDecrement) - require.NoError(t, err) - require.Equal(t, logrus.PanicLevel, logrus.GetLevel()) +func TestAdjustLogLevel(t *testing.T) { + for _, expt := range logLevelExpectations { + logrus.SetLevel(expt.startLevel) + err := AdjustLogLevel(expt.increment) + + if expt.startLevel == expt.endLevel { + require.Error(t, err) // because if it didn't change, that means AdjustLogLevel failed + } else { + require.NoError(t, err) + } - // Panic -> Fatal - logrus.SetLevel(logrus.PanicLevel) - err = AdjustLogLevel(optIncrement) - require.NoError(t, err) - require.Equal(t, logrus.FatalLevel, logrus.GetLevel()) - // Panic is the lowest level for now, so we expected a error here - logrus.SetLevel(logrus.PanicLevel) - err = AdjustLogLevel(optDecrement) - require.Error(t, err) + require.Equal(t, expt.endLevel, logrus.GetLevel()) + } } func TestSetSignalTrap(t *testing.T) { From e4f55003fc7f82350de986c7de49da9743422997 Mon Sep 17 00:00:00 2001 From: Ying Li Date: Thu, 22 Sep 2016 00:20:45 -0700 Subject: [PATCH 3/6] Add windows as a supported cross-compile platform. Add cross-compiling for supported platforms to our CircleCI builders. Signed-off-by: Ying Li --- Makefile | 2 +- buildscripts/circle_parallelism.sh | 1 + buildscripts/cross.sh | 24 +++++++++++++++--------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index e415c053a..c5fcbcc92 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ endif CTIMEVAR=-X $(NOTARY_PKG)/version.GitCommit=$(GITCOMMIT) -X $(NOTARY_PKG)/version.NotaryVersion=$(NOTARY_VERSION) GO_LDFLAGS=-ldflags "-w $(CTIMEVAR)" GO_LDFLAGS_STATIC=-ldflags "-w $(CTIMEVAR) -extldflags -static" -GOOSES = darwin linux +GOOSES = darwin linux windows NOTARY_BUILDTAGS ?= pkcs11 NOTARYDIR := /go/src/github.com/docker/notary diff --git a/buildscripts/circle_parallelism.sh b/buildscripts/circle_parallelism.sh index cc07fdc2d..961d90a6a 100755 --- a/buildscripts/circle_parallelism.sh +++ b/buildscripts/circle_parallelism.sh @@ -8,6 +8,7 @@ case $CIRCLE_NODE_INDEX in ;; 2) SKIPENVCHECK=1 make TESTDB=mysql testdb SKIPENVCHECK=1 make TESTDB=mysql integration + SKIPENVCHECK=1 make cross # just trying not to exceed 5 builders ;; 3) SKIPENVCHECK=1 make TESTDB=rethink testdb SKIPENVCHECK=1 make TESTDB=rethink integration diff --git a/buildscripts/cross.sh b/buildscripts/cross.sh index 840a751aa..3e257da33 100755 --- a/buildscripts/cross.sh +++ b/buildscripts/cross.sh @@ -7,15 +7,10 @@ GOARCH="amd64" -if [[ "${NOTARY_BUILDTAGS}" == *pkcs11* ]]; then - export CGO_ENABLED=1 -else - export CGO_ENABLED=0 -fi - - for os in "$@"; do export GOOS="${os}" + BUILDTAGS="${NOTARY_BUILDTAGS}" + OUTFILE=notary if [[ "${GOOS}" == "darwin" ]]; then export CC="o64-clang" @@ -24,18 +19,29 @@ for os in "$@"; do # darwin binaries can't be compiled to be completely static with the -static flag LDFLAGS="-s" else + # no building with Cgo. Also no building with pkcs11 + if [[ "${GOOS}" == "windows" ]]; then + BUILDTAGS= + OUTFILE=notary.exe + fi unset CC unset CXX LDFLAGS="-extldflags -static" fi + if [[ "${BUILDTAGS}" == *pkcs11* ]]; then + export CGO_ENABLED=1 + else + export CGO_ENABLED=0 + fi + mkdir -p "${NOTARYDIR}/cross/${GOOS}/${GOARCH}"; set -x; go build \ - -o "${NOTARYDIR}/cross/${GOOS}/${GOARCH}/notary" \ + -o "${NOTARYDIR}/cross/${GOOS}/${GOARCH}/${OUTFILE}" \ -a \ - -tags "${NOTARY_BUILDTAGS}" \ + -tags "${BUILDTAGS}" \ -ldflags "-w ${CTIMEVAR} ${LDFLAGS}" \ ./cmd/notary; set +x; From 89acf3b93b0e3c0b645ffa61d4ba80b7e51de67a Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Thu, 22 Sep 2016 11:15:25 -0700 Subject: [PATCH 4/6] fixing path escaping in JSON for TestConfigFileTLSCanBeRelativeToConfigOrAbsolute Signed-off-by: David Lawrence (github: endophage) --- cmd/notary/main_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/notary/main_test.go b/cmd/notary/main_test.go index 5b9f916e7..3d8541ec4 100644 --- a/cmd/notary/main_test.go +++ b/cmd/notary/main_test.go @@ -8,6 +8,7 @@ import ( "net/http/httptest" "os" "path/filepath" + "strconv" "strings" "testing" "time" @@ -343,10 +344,10 @@ func TestConfigFileTLSCanBeRelativeToConfigOrAbsolute(t *testing.T) { "remote_server": { "url": "%s", "root_ca": "root-ca.crt", - "tls_client_cert": "%s", + "tls_client_cert": %s, "tls_client_key": "notary-server.key" } - }`, s.URL, filepath.Join(tempDir, "notary-server.crt")) + }`, s.URL, strconv.Quote(filepath.Join(tempDir, "notary-server.crt"))) configFile.Close() // copy the certs to be relative to the config directory From eb802aa2db380e1698f9937a079b9e1b004f36df Mon Sep 17 00:00:00 2001 From: Ying Li Date: Thu, 22 Sep 2016 14:53:47 -0700 Subject: [PATCH 5/6] Add an extra mocking test for what happens if running under windows where no signals are supported. Revert this commit when we have actual CI tests running under windows. Signed-off-by: Ying Li --- utils/configuration_test.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/utils/configuration_test.go b/utils/configuration_test.go index 0e1357d74..fb77c8542 100644 --- a/utils/configuration_test.go +++ b/utils/configuration_test.go @@ -536,7 +536,7 @@ func TestAdjustLogLevel(t *testing.T) { } } -func TestSetSignalTrap(t *testing.T) { +func testSetSignalTrap(t *testing.T) { var signalsPassedOn map[string]struct{} signalHandler := func(s os.Signal) { @@ -560,3 +560,16 @@ func TestSetSignalTrap(t *testing.T) { require.NotNil(t, signalsPassedOn[s.String()]) } } + +// TODO: undo this extra indirection, needed for mocking notary.NotarySupportedSignals being empty, when we have +// a windows CI system running +func TestSetSignalTrap(t *testing.T) { + testSetSignalTrap(t) +} + +func TestSetSignalTrapMockWindows(t *testing.T) { + old := notary.NotarySupportedSignals + notary.NotarySupportedSignals = nil + testSetSignalTrap(t) + notary.NotarySupportedSignals = old +} From b91f1822bda9271f2a825be83ca632319f664fb4 Mon Sep 17 00:00:00 2001 From: Ying Li Date: Thu, 22 Sep 2016 21:14:55 -0700 Subject: [PATCH 6/6] covermode should be atomic if there are goroutines Signed-off-by: Ying Li --- buildscripts/covertest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildscripts/covertest.py b/buildscripts/covertest.py index ee2f22e67..99fec4101 100755 --- a/buildscripts/covertest.py +++ b/buildscripts/covertest.py @@ -32,7 +32,7 @@ def get_coverprofile_filename(pkg, buildtags): buildtags = "." + buildtags.replace(' ', '.') return pkg.replace('/', '-').replace(' ', '_') + buildtags + ".coverage.txt" -def run_test_with_coverage(buildtags="", coverdir=".cover", pkgs=None, opts="", covermode="count"): +def run_test_with_coverage(buildtags="", coverdir=".cover", pkgs=None, opts="", covermode="atomic"): """ Run go test with coverage over the the given packages, with the following options """