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 {