diff --git a/Dockerfile b/Dockerfile index 6dee961..b6f9741 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,15 +14,19 @@ COPY . . # 构建可执行文件 RUN CGO_ENABLED=0 GOOS=linux go build -v -o app . + # 使用一个更小的基础镜像来减小最终镜像的大小 FROM alpine:latest - +# 时区设置成当前时区 +RUN apk add --no-cache tzdata +ENV TZ="Asia/Shanghai" # 设置工作目录 WORKDIR /root/ - # 从构建阶段复制可执行文件 COPY --from=builder /app/app . - +# 在容器目录 /root/ 创建一个目录 为config +RUN mkdir conf . +COPY --from=builder /app/conf/ ./conf/ # 暴露端口 EXPOSE 8080 diff --git a/conf/config.go b/conf/config.go index 4a26251..1b85507 100644 --- a/conf/config.go +++ b/conf/config.go @@ -85,6 +85,7 @@ func SetUp1() { mysqlHost := viper.GetString("mysql.Host") jwtSecretKey := viper.GetString("jwt.SecretKey") serverPort := viper.GetInt("server.Port") + DataBase = viper.Get("database") templateGlob := viper.GetString("project.TemplateGlob") // 打印获取到的配置值 diff --git a/conf/config.yml b/conf/config.yml index e4a4acc..d4fcf41 100644 --- a/conf/config.yml +++ b/conf/config.yml @@ -1,4 +1,4 @@ -mysql: +database: Type: mysql Host: 127.0.0.1 Port: 3306 diff --git a/main.go b/main.go index f33ce57..b0cad68 100644 --- a/main.go +++ b/main.go @@ -36,7 +36,6 @@ func init() { flag.Parse() conf.SetUp() - conf.SetUp1() models.SetUp(isOrmDebug) }