diff --git a/Dockerfile b/Dockerfile index 93b5b4b..013c27d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,4 +2,4 @@ FROM alpine:3.9 COPY mittnite /usr/bin/mittnite EXPOSE 9102 ENTRYPOINT ["mittnite"] -CMD ["--config-dir", "/etc/mittnite.d"] \ No newline at end of file +CMD ["up","--config-dir", "/etc/mittnite.d"] \ No newline at end of file diff --git a/README.md b/README.md index 7ea500f..9591a35 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ It offers the following features: Start as follows: ``` -$ mittnite --config-dir /etc/mittnite.d +$ mittnite up --config-dir /etc/mittnite.d ``` Or use it in a container image: @@ -25,10 +25,10 @@ Or use it in a container image: FROM quay.io/mittwald/mittnite:stable COPY nginx.hcl /etc/mittnite.d/webserver.hcl COPY fpm.hcl /etc/mittnite.d/fpm.hcl -CMD ["-.config-dir", "/etc/mittnite.d"] +CMD ["up", "--config-dir", "/etc/mittnite.d"] ``` -The directory specified with `--config-dir` can contain any number of `.hcl` configuration files; all files in that directory are loaded by Mittnite on startup and can contain any of the configuration directives described in the following section: +The directory specified with `--config-dir` or the shorthand `-c` can contain any number of `.hcl` configuration files; all files in that directory are loaded by Mittnite on startup and can contain any of the configuration directives described in the following section: ## Configuration directives diff --git a/cmd/root.go b/cmd/root.go index 330b73b..3c8a6f2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -16,6 +16,7 @@ var rootCmd = &cobra.Command{ Short: "Mittnite - Smart init system for containers", Long: "Mittnite is a small, but smart init system designed for usage as `ENTRYPOINT` in container images.", Run: func(cmd *cobra.Command, args []string) { + log.Warn("Using mittnite without 'up'. This will change in future releases!") up.Run(cmd, args) }, } diff --git a/go.mod b/go.mod index d3630bb..2712f61 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( github.com/onsi/gomega v1.5.0 // indirect github.com/sirupsen/logrus v1.4.2 github.com/spf13/cobra v0.0.5 - github.com/spf13/viper v1.3.2 github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94 github.com/stretchr/testify v1.3.0 // indirect github.com/tidwall/pretty v0.0.0-20190325153808-1166b9ac2b65 // indirect diff --git a/pkg/probe/helper.go b/internal/helper/helper.go similarity index 68% rename from pkg/probe/helper.go rename to internal/helper/helper.go index 1e9919c..00620e7 100644 --- a/pkg/probe/helper.go +++ b/internal/helper/helper.go @@ -1,11 +1,11 @@ -package probe +package helper import ( "os" "strings" ) -func resolveEnv(in string) string { +func ResolveEnv(in string) string { if strings.HasPrefix(in, "ENV:") { return os.Getenv(in[4:]) } diff --git a/internal/types/types.go b/internal/types/types.go index 5b9ec55..3661670 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -6,8 +6,8 @@ type Credentials struct { } type Host struct { - URL string - Port string + Hostname string + Port string } type MySQLConfig struct { diff --git a/pkg/probe/probe_amqp.go b/pkg/probe/probe_amqp.go index e9831d6..9283b57 100644 --- a/pkg/probe/probe_amqp.go +++ b/pkg/probe/probe_amqp.go @@ -2,6 +2,7 @@ package probe import ( "fmt" + "github.com/mittwald/mittnite/internal/helper" "github.com/mittwald/mittnite/internal/types" log "github.com/sirupsen/logrus" "github.com/streadway/amqp" @@ -21,11 +22,11 @@ type amqpProbe struct { } func NewAmqpProbe(cfg *types.AmqpConfig) *amqpProbe { - cfg.User = resolveEnv(cfg.User) - cfg.Password = resolveEnv(cfg.Password) - cfg.URL = resolveEnv(cfg.URL) - cfg.Port = resolveEnv(cfg.Port) - cfg.VirtualHost = resolveEnv(cfg.VirtualHost) + cfg.User = helper.ResolveEnv(cfg.User) + cfg.Password = helper.ResolveEnv(cfg.Password) + cfg.Hostname = helper.ResolveEnv(cfg.Hostname) + cfg.Port = helper.ResolveEnv(cfg.Port) + cfg.VirtualHost = helper.ResolveEnv(cfg.VirtualHost) if cfg.VirtualHost == "" { cfg.VirtualHost = defaultVirtualHost } @@ -33,7 +34,7 @@ func NewAmqpProbe(cfg *types.AmqpConfig) *amqpProbe { connCfg := amqpProbe{ user: cfg.User, password: cfg.Password, - hostname: cfg.URL, + hostname: cfg.Hostname, virtualHost: cfg.VirtualHost, port: cfg.Port, } diff --git a/pkg/probe/probe_http.go b/pkg/probe/probe_http.go index fb23806..3029730 100644 --- a/pkg/probe/probe_http.go +++ b/pkg/probe/probe_http.go @@ -2,6 +2,7 @@ package probe import ( "fmt" + "github.com/mittwald/mittnite/internal/helper" "github.com/mittwald/mittnite/internal/types" log "github.com/sirupsen/logrus" "net/http" @@ -17,19 +18,19 @@ type httpGetProbe struct { } func NewHttpProbe(cfg *types.HttpGetConfig) *httpGetProbe { - cfg.Scheme = resolveEnv(cfg.Scheme) - cfg.URL = resolveEnv(cfg.URL) - cfg.Port = resolveEnv(cfg.Port) - cfg.Path = resolveEnv(cfg.Path) - cfg.Timeout = resolveEnv(cfg.Timeout) + cfg.Scheme = helper.ResolveEnv(cfg.Scheme) + cfg.Hostname = helper.ResolveEnv(cfg.Hostname) + cfg.Port = helper.ResolveEnv(cfg.Port) + cfg.Path = helper.ResolveEnv(cfg.Path) + cfg.Timeout = helper.ResolveEnv(cfg.Timeout) if cfg.Scheme == "" { cfg.Scheme = "http" } - host := cfg.Host.URL + host := cfg.Host.Hostname if cfg.Host.Port != "" { - host += fmt.Sprintf("%s:%s", cfg.URL, cfg.Port) + host += fmt.Sprintf("%s:%s", cfg.Hostname, cfg.Port) } connCfg := httpGetProbe{ diff --git a/pkg/probe/probe_mongodb.go b/pkg/probe/probe_mongodb.go index 754bbd7..d1463e6 100644 --- a/pkg/probe/probe_mongodb.go +++ b/pkg/probe/probe_mongodb.go @@ -3,6 +3,7 @@ package probe import ( "context" "fmt" + "github.com/mittwald/mittnite/internal/helper" "github.com/mittwald/mittnite/internal/types" log "github.com/sirupsen/logrus" "go.mongodb.org/mongo-driver/mongo" @@ -21,15 +22,15 @@ type mongoDBProbe struct { } func NewMongoDBProbe(cfg *types.MongoDBConfig) *mongoDBProbe { - cfg.User = resolveEnv(cfg.User) - cfg.Password = resolveEnv(cfg.Password) - cfg.URL = resolveEnv(cfg.URL) - cfg.Database = resolveEnv(cfg.Database) + cfg.User = helper.ResolveEnv(cfg.User) + cfg.Password = helper.ResolveEnv(cfg.Password) + cfg.Hostname = helper.ResolveEnv(cfg.Hostname) + cfg.Database = helper.ResolveEnv(cfg.Database) connCfg := mongoDBProbe{ user: cfg.User, password: cfg.Password, - hostname: cfg.URL, + hostname: cfg.Hostname, database: cfg.Database, port: cfg.Port, } diff --git a/pkg/probe/probe_mysql.go b/pkg/probe/probe_mysql.go index dbb952f..96de04c 100644 --- a/pkg/probe/probe_mysql.go +++ b/pkg/probe/probe_mysql.go @@ -4,6 +4,7 @@ import ( "database/sql" "fmt" "github.com/go-sql-driver/mysql" + "github.com/mittwald/mittnite/internal/helper" "github.com/mittwald/mittnite/internal/types" log "github.com/sirupsen/logrus" ) @@ -13,11 +14,11 @@ type mySQLProbe struct { } func NewMySQLProbe(cfg *types.MySQLConfig) *mySQLProbe { - cfg.User = resolveEnv(cfg.User) - cfg.Database = resolveEnv(cfg.Database) - cfg.Password = resolveEnv(cfg.Password) - cfg.URL = resolveEnv(cfg.URL) - cfg.Port = resolveEnv(cfg.Port) + cfg.User = helper.ResolveEnv(cfg.User) + cfg.Database = helper.ResolveEnv(cfg.Database) + cfg.Password = helper.ResolveEnv(cfg.Password) + cfg.Hostname = helper.ResolveEnv(cfg.Hostname) + cfg.Port = helper.ResolveEnv(cfg.Port) connCfg := mysql.Config{ User: cfg.User, diff --git a/pkg/probe/probe_redis.go b/pkg/probe/probe_redis.go index 4fe67b9..e3723b3 100644 --- a/pkg/probe/probe_redis.go +++ b/pkg/probe/probe_redis.go @@ -3,6 +3,7 @@ package probe import ( "fmt" "github.com/go-redis/redis" + "github.com/mittwald/mittnite/internal/helper" "github.com/mittwald/mittnite/internal/types" log "github.com/sirupsen/logrus" ) @@ -13,12 +14,12 @@ type redisProbe struct { } func NewRedisProbe(cfg *types.RedisConfig) *redisProbe { - cfg.URL = resolveEnv(cfg.URL) - cfg.Password = resolveEnv(cfg.Password) - cfg.Port = resolveEnv(cfg.Port) + cfg.Hostname = helper.ResolveEnv(cfg.Hostname) + cfg.Password = helper.ResolveEnv(cfg.Password) + cfg.Port = helper.ResolveEnv(cfg.Port) return &redisProbe{ - addr: fmt.Sprintf("%s:%s", cfg.URL, cfg.Port), + addr: fmt.Sprintf("%s:%s", cfg.Hostname, cfg.Port), password: cfg.Password, } }