diff --git a/Dockerfile b/Dockerfile index eb1598069f7353008511751c5f9d595bef1afcb2..0df4a2947139217273586781e007f62c9a9cb0a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,7 +39,5 @@ EXPOSE 14626/udp # Copy the Pre-built binary file from the previous stage COPY --from=build /go/bin/goshimmer /run/goshimmer -# Copy the default config -COPY config.default.json /config.json ENTRYPOINT ["/run/goshimmer", "--config-dir=/", "--database.directory=/tmp/mainnetdb"] diff --git a/go.mod b/go.mod index b10574b1bbd1af504bbcfec12c4e1cccc9d29a07..205183456362d396db6a60e22f56085bb46846b3 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/gobuffalo/packr/v2 v2.7.1 github.com/golang/protobuf v1.3.5 github.com/gorilla/websocket v1.4.1 - github.com/iotaledger/hive.go v0.0.0-20200430073924-0e16f8c3a522 + github.com/iotaledger/hive.go v0.0.0-20200504205557-790e3a7585f2 github.com/iotaledger/iota.go v1.0.0-beta.14 github.com/labstack/echo v3.3.10+incompatible github.com/labstack/gommon v0.3.0 diff --git a/go.sum b/go.sum index d42e398ea6321f9e6c77f0ec392097094cbda73e..fc13947f55e6bc5a57f8e233540e98f443c48500 100644 --- a/go.sum +++ b/go.sum @@ -145,8 +145,8 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/iotaledger/hive.go v0.0.0-20200430073924-0e16f8c3a522 h1:pd7D0jtsF24UKgNTPxXxuZKzPbFKKoau4r066p6GtAo= -github.com/iotaledger/hive.go v0.0.0-20200430073924-0e16f8c3a522/go.mod h1:LYUD1U+BxF+OY6zCZ4xp38vzjp/QWbUdCw9iwmxkGnc= +github.com/iotaledger/hive.go v0.0.0-20200504205557-790e3a7585f2 h1:vDcNUncyinum1ly5FJPJfYNPZczeo5OLuEpoDu+mxks= +github.com/iotaledger/hive.go v0.0.0-20200504205557-790e3a7585f2/go.mod h1:HgYsLMzyQV+eaiUrxa1c7qvH9Jwi2ncycqtlw+Lczhs= github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= github.com/iotaledger/iota.go v1.0.0-beta.14 h1:Oeb28MfBuJEeXcGrLhTCJFtbsnc8y1u7xidsAmiOD5A= github.com/iotaledger/iota.go v1.0.0-beta.14/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= diff --git a/plugins/config/plugin.go b/plugins/config/plugin.go index 596ad2b58633bc3a1b612a13b15810b77bf9bb78..ab43e6054cd4bfaff9aa9ceb373f80e75644b234 100644 --- a/plugins/config/plugin.go +++ b/plugins/config/plugin.go @@ -1,8 +1,10 @@ package config import ( + "fmt" + "os" + "github.com/iotaledger/hive.go/events" - "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/parameter" flag "github.com/spf13/pflag" @@ -17,21 +19,12 @@ var ( Plugin = node.NewPlugin(PluginName, node.Enabled) // flags - configName = flag.StringP("config", "c", "config", "Filename of the config file without the file extension") - configDirPath = flag.StringP("config-dir", "d", ".", "Path to the directory containing the config file") + configName = flag.StringP("config", "c", "config", "Filename of the config file without the file extension") + configDirPath = flag.StringP("config-dir", "d", ".", "Path to the directory containing the config file") + skipConfigAvailable = flag.Bool("skip-config", false, "Skip config file availability check") // Node is viper Node *viper.Viper - - // logger - defaultLoggerConfig = logger.Config{ - Level: "info", - DisableCaller: false, - DisableStacktrace: false, - Encoding: "console", - OutputPaths: []string{"goshimmer.log"}, - DisableEvents: false, - } ) // Init triggers the Init event. @@ -42,10 +35,17 @@ func Init() { func init() { // set the default logger config Node = viper.New() - Node.SetDefault(logger.ViperKey, defaultLoggerConfig) Plugin.Events.Init.Attach(events.NewClosure(func(*node.Plugin) { if err := fetch(false); err != nil { + if !*skipConfigAvailable { + // we wanted a config file but it was not present + // global logger instance is not initialized at this stage... + fmt.Println(err.Error()) + fmt.Println("no config file present, terminating GoShimmer. please use the provided config.default.json to create a config.json.") + // daemon is not running yet, so we just exit + os.Exit(1) + } panic(err) } })) @@ -57,7 +57,7 @@ func init() { // and ending with: .json, .toml, .yaml or .yml (in this sequence). func fetch(printConfig bool, ignoreSettingsAtPrint ...[]string) error { flag.Parse() - err := parameter.LoadConfigFile(Node, *configDirPath, *configName, true, true) + err := parameter.LoadConfigFile(Node, *configDirPath, *configName, true, *skipConfigAvailable) if err != nil { return err } diff --git a/plugins/logger/parameters.go b/plugins/logger/parameters.go new file mode 100644 index 0000000000000000000000000000000000000000..d5326d8ee3867be2f43234783b3385a36e2d6469 --- /dev/null +++ b/plugins/logger/parameters.go @@ -0,0 +1,29 @@ +package logger + +import ( + flag "github.com/spf13/pflag" +) + +const ( + // CfgLoggerLevel defines the logger's level. + CfgLoggerLevel = "logger.level" + // CfgLoggerDisableCaller defines whether to disable caller info. + CfgLoggerDisableCaller = "logger.disableCaller" + // CfgLoggerDisableStacktrace defines whether to disable stack trace info. + CfgLoggerDisableStacktrace = "logger.disableStacktrace" + // CfgLoggerEncoding defines the logger's encoding. + CfgLoggerEncoding = "logger.encoding" + // CfgLoggerOutputPaths defines the logger's output paths. + CfgLoggerOutputPaths = "logger.outputPaths" + // CfgLoggerDisableEvents defines whether to disable logger events. + CfgLoggerDisableEvents = "logger.disableEvents" +) + +func initFlags() { + flag.String(CfgLoggerLevel, "info", "log level") + flag.Bool(CfgLoggerDisableCaller, false, "disable caller info in log") + flag.Bool(CfgLoggerDisableStacktrace, false, "disable stack trace in log") + flag.String(CfgLoggerEncoding, "console", "log encoding") + flag.StringSlice(CfgLoggerOutputPaths, []string{"stdout", "goshimmer.log"}, "log output paths") + flag.Bool(CfgLoggerDisableEvents, true, "disable logger events") +} diff --git a/plugins/logger/plugin.go b/plugins/logger/plugin.go index 5ccfc62be80457fbdba956775f7a9d1d1e20467c..ebe1430995db139074114058d7774b5a4d3ba577 100644 --- a/plugins/logger/plugin.go +++ b/plugins/logger/plugin.go @@ -19,6 +19,8 @@ func Init() { } func init() { + initFlags() + Plugin.Events.Init.Attach(events.NewClosure(func(*node.Plugin) { if err := logger.InitGlobalLogger(config.Node); err != nil { panic(err) diff --git a/plugins/remotelog/plugin.go b/plugins/remotelog/plugin.go index 32f6ad6bcf5e857d7ff8fba894ea697f9a5ee55b..cd895c089183b12e4fe0e2a6dd75e1d1f803254d 100644 --- a/plugins/remotelog/plugin.go +++ b/plugins/remotelog/plugin.go @@ -23,6 +23,7 @@ import ( "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/workerpool" + flag "github.com/spf13/pflag" "gopkg.in/src-d/go-git.v4" ) @@ -38,8 +39,8 @@ type logMessage struct { } const ( - // CfgServerAddress defines the config flag of the server address. - CfgServerAddress = "logger.remotelog.serverAddress" + // CfgLoggerRemotelogServerAddress defines the config flag of the server address. + CfgLoggerRemotelogServerAddress = "logger.remotelog.serverAddress" // CfgDisableEvents defines the config flag for disabling logger events. CfgDisableEvents = "logger.disableEvents" // PluginName is the name of the remote log plugin. @@ -57,6 +58,10 @@ var ( workerPool *workerpool.WorkerPool ) +func init() { + flag.String(CfgLoggerRemotelogServerAddress, "remotelog.goshimmer.iota.cafe:5213", "RemoteLog server address") +} + func configure(plugin *node.Plugin) { log = logger.NewLogger(PluginName) @@ -65,9 +70,9 @@ func configure(plugin *node.Plugin) { return } - c, err := net.Dial("udp", config.Node.GetString(CfgServerAddress)) + c, err := net.Dial("udp", config.Node.GetString(CfgLoggerRemotelogServerAddress)) if err != nil { - log.Fatalf("Could not create UDP socket to '%s'. %v", config.Node.GetString(CfgServerAddress), err) + log.Fatalf("Could not create UDP socket to '%s'. %v", config.Node.GetString(CfgLoggerRemotelogServerAddress), err) return } conn = c diff --git a/tools/integration-tests/tester/framework/docker.go b/tools/integration-tests/tester/framework/docker.go index 19b37ce21a66485fc58352076accdb92ddab6ac0..b00dc3993e55c344cd2ba728c6ff77b2dcdbd2ac 100644 --- a/tools/integration-tests/tester/framework/docker.go +++ b/tools/integration-tests/tester/framework/docker.go @@ -59,6 +59,8 @@ func (d *DockerContainer) CreateGoShimmerEntryNode(name string, seed string) err Image: "iotaledger/goshimmer", ExposedPorts: nil, Cmd: strslice.StrSlice{ + "--skip-config=true", + "--logger.level=debug", fmt.Sprintf("--node.disablePlugins=%s", disabledPluginsEntryNode), "--autopeering.entryNodes=", fmt.Sprintf("--autopeering.seed=%s", seed), @@ -77,6 +79,8 @@ func (d *DockerContainer) CreateGoShimmerPeer(name string, seed string, entryNod nat.Port("8080/tcp"): {}, }, Cmd: strslice.StrSlice{ + "--skip-config=true", + "--logger.level=debug", fmt.Sprintf("--node.disablePlugins=%s", disabledPluginsPeer), fmt.Sprintf("--node.enablePlugins=%s", func() string { if bootstrap { diff --git a/tools/integration-tests/tester/go.mod b/tools/integration-tests/tester/go.mod index 887407414101e1e8955d4dcfee91ab92a54b19e2..188087ae659157009da36fd7d3a7809db7cc039e 100644 --- a/tools/integration-tests/tester/go.mod +++ b/tools/integration-tests/tester/go.mod @@ -9,7 +9,7 @@ require ( github.com/docker/go-connections v0.4.0 github.com/docker/go-units v0.4.0 // indirect github.com/iotaledger/goshimmer v0.1.3 - github.com/iotaledger/hive.go v0.0.0-20200430073924-0e16f8c3a522 + github.com/iotaledger/hive.go v0.0.0-20200504205557-790e3a7585f2 github.com/opencontainers/go-digest v1.0.0-rc1 // indirect github.com/stretchr/testify v1.5.1 ) diff --git a/tools/integration-tests/tester/go.sum b/tools/integration-tests/tester/go.sum index 695293a3c5529714c86f27f8128e3460d3b681cd..132fe7409fbaf7f454af63d1ce2de7f5dbe6ea96 100644 --- a/tools/integration-tests/tester/go.sum +++ b/tools/integration-tests/tester/go.sum @@ -139,8 +139,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/iotaledger/hive.go v0.0.0-20200430073924-0e16f8c3a522 h1:pd7D0jtsF24UKgNTPxXxuZKzPbFKKoau4r066p6GtAo= -github.com/iotaledger/hive.go v0.0.0-20200430073924-0e16f8c3a522/go.mod h1:LYUD1U+BxF+OY6zCZ4xp38vzjp/QWbUdCw9iwmxkGnc= +github.com/iotaledger/hive.go v0.0.0-20200504205557-790e3a7585f2 h1:vDcNUncyinum1ly5FJPJfYNPZczeo5OLuEpoDu+mxks= +github.com/iotaledger/hive.go v0.0.0-20200504205557-790e3a7585f2/go.mod h1:HgYsLMzyQV+eaiUrxa1c7qvH9Jwi2ncycqtlw+Lczhs= github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= github.com/iotaledger/iota.go v1.0.0-beta.14/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=