Skip to content

Commit

Permalink
use /homedash for data dir if running in container
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdkleijn committed Jun 9, 2023
1 parent 0ac2983 commit 9f29f16
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 .

#####################
Expand All @@ -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

Expand Down
18 changes: 16 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package config

import (
"os"
"strings"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

0 comments on commit 9f29f16

Please sign in to comment.