feat: 增加几个重要配置支持通过环境变量加载的方式 (#326)
This commit is contained in:
parent
103d765735
commit
7589182931
|
@ -4,14 +4,14 @@ WORKDIR /app
|
||||||
|
|
||||||
RUN sed -i "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g" /etc/apk/repositories \
|
RUN sed -i "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g" /etc/apk/repositories \
|
||||||
&& apk upgrade && apk add --no-cache --virtual .build-deps \
|
&& apk upgrade && apk add --no-cache --virtual .build-deps \
|
||||||
ca-certificates gcc g++ curl
|
ca-certificates gcc g++ curl upx
|
||||||
|
|
||||||
ADD . .
|
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 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 \
|
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
|
### build final image
|
||||||
FROM registry.cn-hangzhou.aliyuncs.com/ali_eryajf/alpine:3.19
|
FROM registry.cn-hangzhou.aliyuncs.com/ali_eryajf/alpine:3.19
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/fsnotify/fsnotify"
|
"github.com/fsnotify/fsnotify"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
@ -72,6 +73,65 @@ func InitConfig() {
|
||||||
Conf.System.RSAPublicBytes = pub
|
Conf.System.RSAPublicBytes = pub
|
||||||
Conf.System.RSAPrivateBytes = priv
|
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 {
|
type SystemConfig struct {
|
||||||
|
|
Loading…
Reference in New Issue