From 09d857f2b449fc4bb0a502ca60fe10d92afcac5a Mon Sep 17 00:00:00 2001 From: eryajf Date: Thu, 4 Apr 2024 17:31:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=87=A0=E4=B8=AA?= =?UTF-8?q?=E9=87=8D=E8=A6=81=E9=85=8D=E7=BD=AE=E6=94=AF=E6=8C=81=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 4 ++-- config/config.go | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0328438..9a569f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,14 +4,14 @@ WORKDIR /app RUN sed -i "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g" /etc/apk/repositories \ && apk upgrade && apk add --no-cache --virtual .build-deps \ - ca-certificates gcc g++ curl + ca-certificates gcc g++ curl upx ADD . . RUN release_url=$(curl -s https://api.github.com/repos/eryajf/go-ldap-admin-ui/releases/latest | grep "browser_download_url" | grep -v 'dist.zip.md5' | cut -d '"' -f 4); wget $release_url && unzip dist.zip && rm dist.zip && mv dist public/static RUN sed -i 's@localhost:389@openldap:389@g' /app/config.yml \ - && sed -i 's@host: localhost@host: mysql@g' /app/config.yml && go build -o go-ldap-admin . + && sed -i 's@host: localhost@host: mysql@g' /app/config.yml && go build -o go-ldap-admin . && upx -9 go-ldap-admin ### build final image FROM registry.cn-hangzhou.aliyuncs.com/ali_eryajf/alpine:3.19 diff --git a/config/config.go b/config/config.go index 7b0be81..66b22cc 100644 --- a/config/config.go +++ b/config/config.go @@ -4,6 +4,7 @@ import ( _ "embed" "fmt" "os" + "strconv" "github.com/fsnotify/fsnotify" "github.com/spf13/viper" @@ -72,6 +73,65 @@ func InitConfig() { Conf.System.RSAPublicBytes = pub Conf.System.RSAPrivateBytes = priv + // 部分配合通过环境变量加载 + dbDriver := os.Getenv("DB_DRIVER") + if dbDriver != "" { + Conf.Database.Driver = dbDriver + } + mysqlHost := os.Getenv("MYSQL_HOST") + if mysqlHost != "" { + Conf.Mysql.Host = mysqlHost + } + mysqlUsername := os.Getenv("MYSQL_USERNAME") + if mysqlUsername != "" { + Conf.Mysql.Username = mysqlUsername + } + mysqlPassword := os.Getenv("MYSQL_PASSWORD") + if mysqlPassword != "" { + Conf.Mysql.Password = mysqlPassword + } + mysqlDatabase := os.Getenv("MYSQL_DATABASE") + if mysqlDatabase != "" { + Conf.Mysql.Database = mysqlDatabase + } + mysqlPort := os.Getenv("MYSQL_PORT") + if mysqlPort != "" { + Conf.Mysql.Port, _ = strconv.Atoi(mysqlPort) + } + + ldapUrl := os.Getenv("LDAP_URL") + if ldapUrl != "" { + Conf.Ldap.Url = ldapUrl + } + ldapBaseDN := os.Getenv("LDAP_BASE_DN") + if ldapBaseDN != "" { + Conf.Ldap.BaseDN = ldapBaseDN + } + ldapAdminDN := os.Getenv("LDAP_ADMIN_DN") + if ldapAdminDN != "" { + Conf.Ldap.AdminDN = ldapAdminDN + } + ldapAdminPass := os.Getenv("LDAP_ADMIN_PASS") + if ldapAdminPass != "" { + Conf.Ldap.AdminPass = ldapAdminPass + } + ldapUserDN := os.Getenv("LDAP_USER_DN") + if ldapUserDN != "" { + Conf.Ldap.UserDN = ldapUserDN + } + ldapUserInitPassword := os.Getenv("LDAP_USER_INIT_PASSWORD") + if ldapUserInitPassword != "" { + + Conf.Ldap.UserInitPassword = ldapUserInitPassword + } + ldapDefaultEmailSuffix := os.Getenv("LDAP_DEFAULT_EMAIL_SUFFIX") + if ldapDefaultEmailSuffix != "" { + Conf.Ldap.DefaultEmailSuffix = ldapDefaultEmailSuffix + } + ldapUserPasswordEncryptionType := os.Getenv("LDAP_USER_PASSWORD_ENCRYPTION_TYPE") + if ldapUserPasswordEncryptionType != "" { + Conf.Ldap.UserPasswordEncryptionType = ldapUserPasswordEncryptionType + } } type SystemConfig struct {