optimize docker deploy file

This commit is contained in:
douxu 2025-12-12 11:01:18 +08:00
parent 5021e7fda1
commit 716f56babb
3 changed files with 18 additions and 2 deletions

View File

@ -0,0 +1,15 @@
FROM golang:1.24-alpine AS builder
WORKDIR /app
COPY go.mod .
COPY go.sum .
RUN GOPROXY="https://goproxy.cn,direct" go mod download
COPY . .
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o modelrt main.go
FROM alpine:latest
WORKDIR /app
COPY --from=builder /app/modelrt ./modelrt
COPY configs/config.example.yaml ./configs/config.example.yaml
RUN chmod +x /app/modelrt
CMD ["/app/modelrt"]

View File

@ -77,7 +77,6 @@ func InitLoggerInstance(lCfg config.LoggerConfig) {
once.Do(func() { once.Do(func() {
_globalLogger = initLogger(lCfg) _globalLogger = initLogger(lCfg)
}) })
defer _globalLogger.Sync()
} }
// GetLoggerInstance define func of returns the global logger instance It's safe for concurrent use. // GetLoggerInstance define func of returns the global logger instance It's safe for concurrent use.

View File

@ -6,6 +6,7 @@ import (
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"log"
"net/http" "net/http"
"os" "os"
"os/signal" "os/signal"
@ -76,7 +77,7 @@ func main() {
configPath := filepath.Join(*modelRTConfigDir, *modelRTConfigName+"."+*modelRTConfigType) configPath := filepath.Join(*modelRTConfigDir, *modelRTConfigName+"."+*modelRTConfigType)
if _, err := os.Stat(configPath); os.IsNotExist(err) { if _, err := os.Stat(configPath); os.IsNotExist(err) {
logger.Info(ctx, "configuration file not found,checking for example file") log.Println("configuration file not found,checking for example file")
exampleConfigPath := filepath.Join(*modelRTConfigDir, *modelRTConfigName+".example."+*modelRTConfigType) exampleConfigPath := filepath.Join(*modelRTConfigDir, *modelRTConfigName+".example."+*modelRTConfigType)
if _, err := os.Stat(exampleConfigPath); err == nil { if _, err := os.Stat(exampleConfigPath); err == nil {
@ -94,6 +95,7 @@ func main() {
// init logger // init logger
logger.InitLoggerInstance(modelRTConfig.LoggerConfig) logger.InitLoggerInstance(modelRTConfig.LoggerConfig)
defer logger.GetLoggerInstance().Sync()
hostName, err := os.Hostname() hostName, err := os.Hostname()
if err != nil { if err != nil {