Skip to content

Commit

Permalink
load config form env
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorPolyakov committed Jul 20, 2024
1 parent 26bc1d9 commit 5664b3e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN apk --no-cache add ca-certificates
WORKDIR /ctf01d.ru

COPY --from=builder /ctf01d.ru/server .
COPY --from=builder /ctf01d.ru/config/config.production.yml ./config/config.production.yml
COPY --from=builder /ctf01d.ru/config/ ./config/

EXPOSE 4202

Expand Down
10 changes: 8 additions & 2 deletions cmd/ctf01d/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import (
)

func main() {
cfg, err := config.NewConfig("./config/config.development.yml")
path := "./config/config.development.yml"
if envPath, exists := os.LookupEnv("CONFIG_PATH"); exists {
path = envPath
}

cfg, err := config.NewConfig(path)
if err != nil {
slog.Error("Config error: " + err.Error())
os.Exit(1)
Expand All @@ -26,14 +31,15 @@ func main() {
),
}))
slog.SetDefault(logger)
slog.Info("Config path is - " + path)
db, err := database.InitDatabase(cfg)
if err != nil {
slog.Error("Error opening database connection: " + err.Error())
return
}
slog.Info("Database connection established successfully")
defer db.Close()
router := chi.NewRouter() // TODO .StrictSlash(true)
router := chi.NewRouter()
hndlrs := &handlers.Handlers{
DB: db,
}
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ version: "2"
services:
ctf01d_backend:
image: ghcr.io/sea-kg/ctf01d-training-platform:latest
environment:
CONFIG_PATH: "/config/config.production.yml"

0 comments on commit 5664b3e

Please sign in to comment.