Skip to content

Commit

Permalink
Set default Docker directories
Browse files Browse the repository at this point in the history
  • Loading branch information
JackDallas committed Jun 4, 2022
1 parent f1b43bc commit 3769dcb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ RUN apt update && \
apt install ca-certificates \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir /data

ENV PREMIUMIZEARR_CONFIG_DIR_PATH=/data
ENV PREMIUMIZEARR_LOGGING_DIR_PATH=/data

Expand Down
13 changes: 13 additions & 0 deletions cmd/premiumizearrd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ func main() {

config, err := config.LoadOrCreateConfig(configFile)

// Override config data directories if running in docker
if utils.IsRunningInDockerContainer() {
if config.BlackholeDirectory == "" {
config.BlackholeDirectory = "/blackhole"
}
if config.DownloadsDirectory == "" {
config.DownloadsDirectory = "/downloads"
}
if config.UnzipDirectory == "" {
config.UnzipDirectory = "/unzip"
}
}

if err != nil {
panic(err)
}
Expand Down
13 changes: 13 additions & 0 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,16 @@ func EnvOrDefault(envName string, defaultValue string) string {
}
return envValue
}

func IsRunningInDockerContainer() bool {
// docker creates a .dockerenv file at the root
// of the directory tree inside the container.
// if this file exists then the viewer is running
// from inside a container so return true

if _, err := os.Stat("/.dockerenv"); err == nil {
return true
}

return false
}

0 comments on commit 3769dcb

Please sign in to comment.