From 12a8b13abf7cca3b5c53d15021d8ee13bfd7e2ab Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Thu, 23 May 2019 22:48:58 +0200 Subject: [PATCH] chore: fixup --- Makefile | 2 +- docker-compose.yml | 6 ++---- main.go | 5 +++-- sql/sql.go | 6 +++++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index a423100c8..35bb1b9bb 100644 --- a/Makefile +++ b/Makefile @@ -137,7 +137,7 @@ integration.build: integration.run: docker-compose up -d --no-build server docker-compose run server "./wait-for-it.sh mysql:3306 -- echo server ready" - docker-compose run server "pathwar.pw sql adduser --email=integration@example.com --username=integration --password=integration" + docker-compose run server "pathwar.pw sql adduser --sql-config=$$SQL_CONFIG --email=integration@example.com --username=integration --password=integration" docker-compose run web npm test .PHONY: lint diff --git a/docker-compose.yml b/docker-compose.yml index c166fe83e..ca1e54467 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '2.3' +version: '3' services: server: @@ -9,10 +9,8 @@ services: - "-c" environment: - SQL_CONFIG='root:uns3cur3@tcp(mysql:3306)/pathwar?charset=utf8&parseTime=true' - - HTTP_BIND=0.0.0.0:8000 - - GRPC_BIND=0.0.0.0:9111 command: - - "./wait-for-it.sh mysql:3306 -- /bin/pathwar.pw server" + - "./wait-for-it.sh mysql:3306 -- /bin/pathwar.pw server --http-bind=0.0.0.0:8000 --grpc-bind=0.0.0.0:9111" depends_on: - mysql ports: diff --git a/main.go b/main.go index c10b474a4..47524aa27 100644 --- a/main.go +++ b/main.go @@ -65,6 +65,9 @@ func newRootCommand() *cobra.Command { // setup viper viper.AddConfigPath(".") viper.SetConfigName(".pathwar") + viper.SetEnvPrefix("PATHWAR") + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) + viper.AutomaticEnv() if err := viper.MergeInConfig(); err != nil { if _, ok := err.(viper.ConfigFileNotFoundError); !ok { return errors.Wrap(err, "failed to apply viper config") @@ -87,7 +90,5 @@ func newRootCommand() *cobra.Command { cmd.AddCommand(command.CobraCommand(commands)) } - viper.AutomaticEnv() - viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) return cmd } diff --git a/sql/sql.go b/sql/sql.go index d46a6fc8d..3d84cb8a9 100644 --- a/sql/sql.go +++ b/sql/sql.go @@ -16,7 +16,11 @@ import ( ) func FromOpts(opts *Options) (*gorm.DB, error) { - db, err := gorm.Open("mysql", opts.Config) + sqlConfig := opts.Config + if envConfig := os.Getenv("SQL_CONFIG"); envConfig != "" { // this should be done using viper's built-in env support + sqlConfig = envConfig + } + db, err := gorm.Open("mysql", sqlConfig) if err != nil { return nil, err }