Add initial project structure

With this commit I have prepared a full basic project structure, so far it doesn't embed phoenix itself and also no kit parts. It includes the whole Drone pipeline to continously publish binaries on push and on tag to our download mirrors (will be available at https://download.owncloud.com/reva/phoenix) and also publishes Docker images at owncloud/reva-phonix. For the Docker image auto_tag is enabled, which means latest is always based on the master branch and tags are automatically converted to minor, major and patch release tags.
This commit is contained in:
Thomas Boerger
2019-09-04 10:33:03 +02:00
parent ca30dd04da
commit 6dbfb09f4b
23 changed files with 1840 additions and 112 deletions
+102
View File
@@ -0,0 +1,102 @@
package command
import (
"os"
"strings"
"github.com/owncloud/reva-hyper/pkg/version"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// Root is the entry point for the reva-phoenix command.
func Root() *cobra.Command {
cmd := &cobra.Command{
Use: "reva-hyper",
Short: "ownCloud infinite scale stack",
Long: ``,
Version: version.String,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
setupLogger()
setupConfig()
},
}
cmd.PersistentFlags().String("log-level", "", "Set logging level")
viper.BindPFlag("log.level", cmd.PersistentFlags().Lookup("log-level"))
viper.SetDefault("log.level", "info")
viper.BindEnv("log.level", "HYPER_LOG_LEVEL")
cmd.PersistentFlags().Bool("log-pretty", false, "Enable pretty logging")
viper.BindPFlag("log.pretty", cmd.PersistentFlags().Lookup("log-pretty"))
viper.SetDefault("log.pretty", true)
viper.BindEnv("log.pretty", "HYPER_LOG_PRETTY")
cmd.PersistentFlags().Bool("log-color", false, "Enable colored logging")
viper.BindPFlag("log.color", cmd.PersistentFlags().Lookup("log-color"))
viper.SetDefault("log.color", true)
viper.BindEnv("log.color", "HYPER_LOG_COLOR")
cmd.AddCommand(Phoenix())
cmd.AddCommand(Health())
return cmd
}
func setupLogger() {
switch strings.ToLower(viper.GetString("log.level")) {
case "panic":
zerolog.SetGlobalLevel(zerolog.PanicLevel)
case "fatal":
zerolog.SetGlobalLevel(zerolog.FatalLevel)
case "error":
zerolog.SetGlobalLevel(zerolog.ErrorLevel)
case "warn":
zerolog.SetGlobalLevel(zerolog.WarnLevel)
case "info":
zerolog.SetGlobalLevel(zerolog.InfoLevel)
case "debug":
zerolog.SetGlobalLevel(zerolog.DebugLevel)
default:
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
if viper.GetBool("log.pretty") {
log.Logger = log.Output(
zerolog.ConsoleWriter{
Out: os.Stderr,
NoColor: !viper.GetBool("log.color"),
},
)
}
}
func setupConfig() {
viper.SetConfigName("hyper")
viper.AddConfigPath("/etc/reva")
viper.AddConfigPath("$HOME/.reva")
viper.AddConfigPath("./config")
if err := viper.ReadInConfig(); err != nil {
switch err.(type) {
case viper.ConfigFileNotFoundError:
log.Debug().
Msg("Continue without config")
case viper.UnsupportedConfigError:
log.Fatal().
Msg("Unsupported config type")
default:
if e := log.Debug(); e.Enabled() {
log.Fatal().
Err(err).
Msg("Failed to read config")
} else {
log.Fatal().
Msg("Failed to read config")
}
}
}
}
+27
View File
@@ -0,0 +1,27 @@
package command
import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// Health is the entrypoint for the health command.
func Health() *cobra.Command {
cmd := &cobra.Command{
Use: "health",
Short: "Check health status",
Long: "",
Run: func(cmd *cobra.Command, args []string) {
log.Info().
Str("addr", viper.GetString("metrics.addr")).
Msg("Executed health command")
},
}
cmd.Flags().String("metrics-addr", "", "Address to metrics endpoint")
viper.BindPFlag("metrics.addr", cmd.Flags().Lookup("metrics-addr"))
viper.BindEnv("metrics.addr", "HYPER_METRICS_ADDR")
return cmd
}
+15
View File
@@ -0,0 +1,15 @@
package command
import (
phoenix "github.com/owncloud/reva-phoenix/pkg/command"
"github.com/spf13/cobra"
)
// Phoenix is the entry point for the phoenix command.
func Phoenix() *cobra.Command {
cmd := phoenix.Server()
cmd.Use = "phoenix"
cmd.Short = "Start phoenix server"
return cmd
}
+9
View File
@@ -0,0 +1,9 @@
package version
var (
// String gets defined by the build system.
String = "0.0.0"
// Date indicates the build date.
Date = "00000000"
)