diff --git a/Dockerfile b/Dockerfile index 9c321d3..00cd62f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,13 +23,12 @@ RUN \ esac && \ wget https://github.com/mvdkleijn/healthchecker/releases/download/v1.0.2/healthchecker-${DOWNLOAD_ARCH} && \ mv /build/healthchecker-${DOWNLOAD_ARCH} /build/healthchecker && \ - chmod 755 /build/healthchecker + chmod 755 /build/healthchecker && \ + mkdir /homedash && chmod 755 /homedash COPY . . RUN go mod download -RUN go vet -v -RUN go test -v RUN go build -ldflags="-w -s" -o app . ##################### @@ -39,6 +38,7 @@ FROM --platform=${TARGETPLATFORM:-linux/arm64} gcr.io/distroless/static-debian11 COPY --from=builder /build/app / COPY --from=builder /build/healthchecker /healthchecker +COPY --from=builder /homedash /homedash EXPOSE 8080 diff --git a/internal/config/config.go b/internal/config/config.go index 2381f7e..6d63cf7 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -12,6 +12,7 @@ package config import ( + "os" "strings" log "github.com/sirupsen/logrus" @@ -62,8 +63,14 @@ func initViper() { viper.SetDefault("server.port", "8080") viper.SetDefault("debug", false) viper.SetDefault("maxAge", "20") - viper.SetDefault("icons.TmpDir", "data/tmp") - viper.SetDefault("icons.CacheDir", "data/cache") + if isRunningInContainer() { + Logger.Debugln("detected that we're runnning in a container, using /homedash as default data directory") + viper.SetDefault("icons.TmpDir", "/homedash/tmp") + viper.SetDefault("icons.CacheDir", "/homedash/cache") + } else { + viper.SetDefault("icons.TmpDir", "./data/tmp") + viper.SetDefault("icons.CacheDir", "./data/cache") + } viper.SetDefault("checkInterval", "1") viper.SetDefault("cors.allowedOrigins", "*") viper.SetDefault("cors.allowCredentials", false) @@ -117,3 +124,10 @@ func init() { Logger.Info("initialization completed") Logger.Debugf("dumping active configuration: %v", Config) } + +func isRunningInContainer() bool { + if _, err := os.Stat("/homedash"); err != nil { + return false + } + return true +}