From 15f38491b20c973a5c67b7a50b730dacd3ea1114 Mon Sep 17 00:00:00 2001 From: "meilin.huang" <954537473@qq.com> Date: Fri, 9 Dec 2022 22:02:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9Edocker=E9=83=A8?= =?UTF-8?q?=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/config.yml | 8 ++++---- server/docker-compose.yaml | 2 +- server/pkg/config/config.go | 36 ++++++++++++++++++++++++++++++++++++ server/shutdown.sh | 0 server/startup.sh | 0 5 files changed, 41 insertions(+), 5 deletions(-) mode change 100644 => 100755 server/shutdown.sh mode change 100644 => 100755 server/startup.sh diff --git a/server/config.yml b/server/config.yml index a2e21e12..47758973 100644 --- a/server/config.yml +++ b/server/config.yml @@ -18,7 +18,7 @@ jwt: aes: key: 1111111111111111 mysql: - host: mysql:3306 + host: localhost:3306 username: root password: 111049 db-name: mayfly-go @@ -27,6 +27,6 @@ mysql: log: # 日志等级, trace, debug, info, warn, error, fatal level: info - # file: - # path: ./ - # name: mayfly.log \ No newline at end of file + file: + path: ./ + name: mayfly-go.log \ No newline at end of file diff --git a/server/docker-compose.yaml b/server/docker-compose.yaml index 5dff0b1b..48cc46e2 100644 --- a/server/docker-compose.yaml +++ b/server/docker-compose.yaml @@ -18,7 +18,7 @@ services: restart: always server: - image: mayfly-go:v1.3.0 + image: mayfly-go:v1.3.1 build: context: . dockerfile: Dockerfile diff --git a/server/pkg/config/config.go b/server/pkg/config/config.go index 62a1879b..9937cbc0 100644 --- a/server/pkg/config/config.go +++ b/server/pkg/config/config.go @@ -5,6 +5,7 @@ import ( "fmt" "mayfly-go/pkg/utils" "mayfly-go/pkg/utils/assert" + "os" "path/filepath" ) @@ -24,6 +25,8 @@ func Init() { } // 校验配置文件内容信息 yc.Valid() + // 尝试使用系统环境变量替换配置信息 + yc.ReplaceOsEnv() Conf = yc } @@ -50,3 +53,36 @@ func (c *Config) Valid() { c.Aes.Valid() } } + +// 替换系统环境变量,如果环境变量中存在该值,则优秀使用环境变量设定的值 +func (c *Config) ReplaceOsEnv() { + dbHost := os.Getenv("MAYFLY_DB_HOST") + if dbHost != "" { + c.Mysql.Host = dbHost + } + + dbName := os.Getenv("MAYFLY_DB_NAME") + if dbName != "" { + c.Mysql.Dbname = dbName + } + + dbUser := os.Getenv("MAYFLY_DB_USER") + if dbUser != "" { + c.Mysql.Username = dbUser + } + + dbPwd := os.Getenv("MAYFLY_DB_PASS") + if dbPwd != "" { + c.Mysql.Password = dbPwd + } + + aesKey := os.Getenv("MAYFLY_AES_KEY") + if aesKey != "" { + c.Aes.Key = aesKey + } + + jwtKey := os.Getenv("MAYFLY_JWT_KEY") + if jwtKey != "" { + c.Jwt.Key = jwtKey + } +} diff --git a/server/shutdown.sh b/server/shutdown.sh old mode 100644 new mode 100755 diff --git a/server/startup.sh b/server/startup.sh old mode 100644 new mode 100755