optimize dockerfile and config generate of docker deploy
This commit is contained in:
parent
4f5d998659
commit
689d31c246
|
|
@ -9,7 +9,11 @@ RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o modelrt main.go
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
ARG USER_ID=1000
|
||||||
|
RUN adduser -D -u ${USER_ID} modelrt
|
||||||
COPY --from=builder /app/modelrt ./modelrt
|
COPY --from=builder /app/modelrt ./modelrt
|
||||||
COPY configs/config.example.yaml ./configs/config.example.yaml
|
COPY configs/config.example.yaml ./configs/config.example.yaml
|
||||||
|
RUN chown -R modelrt:modelrt /app
|
||||||
RUN chmod +x /app/modelrt
|
RUN chmod +x /app/modelrt
|
||||||
CMD ["/app/modelrt"]
|
USER modelrt
|
||||||
|
CMD ["/app/modelrt", "-modelRT_config_dir=/app/configs"]
|
||||||
10
main.go
10
main.go
|
|
@ -72,14 +72,16 @@ func main() {
|
||||||
log.Println("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)
|
||||||
|
configDir := filepath.Dir(configPath)
|
||||||
|
if err := os.MkdirAll(configDir, 0o755); err != nil {
|
||||||
|
panic(fmt.Errorf("failed to create config directory %s:%w", configDir, err))
|
||||||
|
}
|
||||||
if _, err := os.Stat(exampleConfigPath); err == nil {
|
if _, err := os.Stat(exampleConfigPath); err == nil {
|
||||||
if err := util.CopyFile(exampleConfigPath, configPath); err != nil {
|
if err := util.CopyFile(exampleConfigPath, configPath); err != nil {
|
||||||
panicErr := fmt.Errorf("failed to copy example config file:%w", err)
|
panic(fmt.Errorf("failed to copy example config file:%w", err))
|
||||||
panic(panicErr)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
panicErr := errors.New("no config file and no config example file found")
|
panic(errors.New("no config file and no config example file found"))
|
||||||
panic(panicErr)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue