Skip to content

Commit

Permalink
chore: fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed May 23, 2019
1 parent 41a88a5 commit 12a8b13
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2.3'
version: '3'

services:
server:
Expand All @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -87,7 +90,5 @@ func newRootCommand() *cobra.Command {
cmd.AddCommand(command.CobraCommand(commands))
}

viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
return cmd
}
6 changes: 5 additions & 1 deletion sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 12a8b13

Please sign in to comment.