Skip to content

Commit

Permalink
Enable the new scheduler by default
Browse files Browse the repository at this point in the history
  • Loading branch information
pixxon committed Feb 3, 2024
1 parent 2e970c2 commit 8fd4cb2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ RUN apk add --no-cache ca-certificates
COPY --from=builder /app/cmd/backup/backup /usr/bin/backup
COPY --chmod=755 ./entrypoint.sh /root/

ENTRYPOINT ["/root/entrypoint.sh"]
ENTRYPOINT ["/usr/bin/backup", "--foreground"]
27 changes: 18 additions & 9 deletions cmd/backup/configProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ package main

import (
"fmt"
"log"
"log/slog"
"os"
"path/filepath"

"github.com/joho/godotenv"
"github.com/offen/envconfig"
Expand All @@ -25,12 +26,12 @@ func loadConfig(lookup envProxy) (*Config, error) {
case !okValue && okFile: // only file
contents, err := os.ReadFile(location)
if err != nil {
log.Panicf("newScript: failed to read %s! Error: %s", location, err)
slog.Error(fmt.Sprintf("failed to read %s", location), "error", err)
return "", false
}
return string(contents), true
case okValue && okFile: // both
log.Panicf("newScript: both %s and %s are set!", key, key+"_FILE")
slog.Error(fmt.Sprintf("both %s and %s are set!", key, key+"_FILE"))
return "", false
default: // neither, ignore
return "", false
Expand All @@ -39,38 +40,46 @@ func loadConfig(lookup envProxy) (*Config, error) {

var c = &Config{}
if err := envconfig.Process("", c); err != nil {
return nil, fmt.Errorf("newScript: failed to process configuration values: %w", err)
slog.Error("failed to process configuration values", "error", err)
return nil, err
}

return c, nil
}

func loadEnvVars() (*Config, error) {
slog.Info("loading config from environment variables")
return loadConfig(os.LookupEnv)
}

func loadEnvFiles(folder string) ([]*Config, error) {
slog.Info(fmt.Sprintf("loading config from environment files from directory %s", folder))

items, err := os.ReadDir(folder)
if err != nil {
return nil, fmt.Errorf("Failed to read files from env folder: %w", err)
slog.Error("failed to read files from env folder", "error", err)
return nil, err
}

var cs = make([]*Config, 0)
for _, item := range items {
if item.IsDir() {
log.Println("Skipping directory")
slog.Info("skipping subdirectory")
} else {
envFile, err := godotenv.Read(".env")
p := filepath.Join(folder, item.Name())
envFile, err := godotenv.Read(p)
if err != nil {
log.Println("Error reading file: %w", err)
slog.Error(fmt.Sprintf("skipping subdirectory %s", p), "error", err)
return nil, err
}
lookup := func(key string) (string, bool) {
val, ok := envFile[key]
return val, ok
}
c, err := loadConfig(lookup)
if err != nil {
log.Println("Error loading config from file: %w", err)
slog.Error(fmt.Sprintf("error loading config from file %s", p), "error", err)
return nil, err
}
cs = append(cs, c)
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/backup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,15 @@ func main() {

cs, err := loadEnvFiles(*envFolder)
if err != nil {
logger.Warn("could not load config from environment files")
if !os.IsNotExist(err) {
logger.Error("could not load config from environment files")
os.Exit(1)
}

c, err := loadEnvVars()
if err != nil {
logger.Error("could not load config from environment variables")
os.Exit(1)
} else {
addJob(c)
}
Expand Down

0 comments on commit 8fd4cb2

Please sign in to comment.