diff --git a/Dockerfile b/Dockerfile index 5233dfd..41a1747 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,8 @@ RUN apk add --no-cache ca-certificates tzdata WORKDIR /app COPY --from=backend /out/statuspage /app/statuspage COPY --from=frontend /ui/dist /app/dist +ENV CONFIG=/app/config.local.yaml VOLUME /app/data.volume EXPOSE 5000 ENTRYPOINT ["/app/statuspage"] -CMD ["-c", "/app/config.local.yaml", "--addr", ":5000"] +CMD ["--addr", ":5000"] diff --git a/docker-compose.yml b/docker-compose.yml index 57ffa49..5153e4b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,9 @@ services: volumes: - ./data.volume:/app/data.volume - ./config.local.yaml:/app/config.local.yaml:ro + environment: + - CONFIG=/app/config.local.yaml + - ADDR=:5000 cap_add: - NET_RAW restart: unless-stopped diff --git a/go.mod b/go.mod index 6d51973..7b1acde 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,12 @@ module statuspage go 1.26.4 require ( + github.com/joho/godotenv v1.5.1 + github.com/mattn/go-sqlite3 v1.14.49 + github.com/spf13/pflag v1.0.10 golang.org/x/crypto v0.54.0 golang.org/x/net v0.57.0 gopkg.in/yaml.v3 v3.0.1 ) -require ( - github.com/mattn/go-sqlite3 v1.14.49 // indirect - github.com/spf13/pflag v1.0.10 // indirect - golang.org/x/sys v0.47.0 // indirect -) +require golang.org/x/sys v0.47.0 // indirect diff --git a/go.sum b/go.sum index 3485160..c535593 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/mattn/go-sqlite3 v1.14.49 h1:B8jBHC3xhxZgxztrgruTuLucebnULQnx4W7cF7SAE9w= github.com/mattn/go-sqlite3 v1.14.49/go.mod h1:6JTjA44L93a0QCyJef5YvlPoKXntQPjzWv5gtm9sB6w= github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= diff --git a/server/main.go b/server/main.go index 311ce42..f1023d6 100644 --- a/server/main.go +++ b/server/main.go @@ -9,9 +9,17 @@ import ( "path/filepath" "strings" + "github.com/joho/godotenv" "github.com/spf13/pflag" ) +func envOr(key, def string) string { + if v := os.Getenv(key); v != "" { + return v + } + return def +} + func buildFrontend() error { cmd := "npm" if _, err := exec.LookPath("npm"); err != nil { @@ -43,11 +51,13 @@ func spaHandler() http.HandlerFunc { } func main() { + _ = godotenv.Load() + dev := pflag.Bool("dev", false, "run `npm run build` before serving dist/") devServer := pflag.Bool("dev-server", false, "frontend served by the vite dev server, do not serve dist/") - addr := pflag.String("addr", ":5000", "listen address") - configPath := pflag.StringP("config", "c", "config.local.yaml", "yaml config file") - dbPath := pflag.String("db", "data.volume/history.db", "sqlite history database file") + addr := pflag.String("addr", envOr("ADDR", ":5000"), "listen address") + configPath := pflag.StringP("config", "c", envOr("CONFIG", "config.local.yaml"), "yaml config file") + dbPath := pflag.String("db", envOr("DB", "data.volume/history.db"), "sqlite history database file") pflag.Parse() if dir := filepath.Dir(*dbPath); dir != "." {