Skip to content

Commit 21da243

Browse files
committed
use INI config instead of env file
1 parent a9a2936 commit 21da243

File tree

6 files changed

+57
-18
lines changed

6 files changed

+57
-18
lines changed

.air.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ exclude_dir = []
88
exclude_file = []
99
exclude_regex = ["_test\\.go$", "\\.md$"]
1010
exclude_unchanged = false
11-
include_dir = ["pkg", "cmd"]
12-
include_ext = ["go"]
11+
include_dir = ["pkg", "cmd", "config"]
12+
include_ext = ["go", "ini"]
1313
include_file = []
1414
kill_delay = "0s"
1515
log = "/dev/stderr"
@@ -21,4 +21,3 @@ rerun = false
2121
rerun_delay = 500
2222
send_interrupt = false
2323
stop_on_error = false
24-

Makefile

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ repository_root := $(shell git rev-parse --show-toplevel)
22
repository_root := $(or $(repository_root), $(CURDIR))
33
include $(repository_root)/variables.mk
44

5-
GENENV_FILES ?= $(wildcard ./config/*)
6-
GENENV_FILE ?= ./config/genenv.local.sh
5+
CONFIG_FILES ?= $(wildcard ./config/*.ini)
6+
CONFIG_FILE ?= ./config/local.ini
77

88
COMPOSE_PROJECT_NAME ?= $(notdir $(CURDIR))
99

@@ -20,8 +20,7 @@ start: tmp/.env
2020

2121
.PHONY: start/prisme
2222
start/prisme: start tmp/prisme
23-
source ./tmp/.env \
24-
&& air --build.cmd '$(MAKE) tmp/prisme' --build.bin './tmp/prisme' \
23+
PRISME_CONFIG=$(CONFIG_FILE) air --build.cmd '$(MAKE) tmp/prisme' --build.bin './tmp/prisme' \
2524
|& bunyan
2625

2726
.PHONY: start/addevents
@@ -76,14 +75,11 @@ codegen: ./pkg/embedded/static/wa.js ./pkg/embedded/static/openapi.json ./pkg/em
7675
./pkg/embedded/static/wa.js: ./tracker/web_analytics.js
7776
minify --js-version 2019 $^ > $@
7877

79-
$(GENENV_FILE):
80-
@echo "$(GENENV_FILE) doesn't exist, generating one..."
81-
@printf '#!/usr/bin/env bash\n\nDIR="$$(dirname $$0)"\nsource "$$DIR/genenv.sh"\n\n# setenv PRISME_XXX_OPTION "value"' > $@
82-
@chmod +x $(GENENV_FILE)
83-
@echo "$(GENENV_FILE) generated, you can edit it!"
84-
85-
tmp/.env: tmp/ $(GENENV_FILES) $(GENENV_FILE)
86-
bash $(GENENV_FILE) > tmp/.env; \
78+
$(CONFIG_FILE): ./config/example.ini
79+
@echo "$(CONFIG_FILE) doesn't exist, generating one..."
80+
@cp ./config/example.ini $@
81+
@chmod +x $(CONFIG_FILE)
82+
@echo "$(CONFIG_FILE) generated, you can edit it!"
8783

8884
tmp/prisme: go/build/prisme
8985

@@ -95,7 +91,7 @@ test/unit: codegen
9591
go test -v -tags assert,test -short -race -bench=./... -benchmem ./...
9692

9793
.PHONY: test/integ
98-
test/integ: start ./tmp/.env
94+
test/integ: start $(CONFIG_FILE)
9995
source ./tmp/.env && go test -tags chdb,test -v -race -p 1 -run TestInteg ./...
10096
source ./tmp/.env && go test -tags chdb,test -v -p 1 -run TestIntegNoRaceDetector ./...
10197
$(MAKE) clean

cmd/prisme/config.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,18 @@ func (c *Config) Validate() error {
6969
}
7070

7171
func defaultConfig() {
72-
ini := configue.NewINI(configue.File("./", "config.ini"))
72+
ini := configue.NewINI(configFilePath())
7373
figue := configue.New("default-config", configue.ContinueOnError, ini)
7474
var cfg Config
7575
cfg.RegisterOptions(figue)
7676

7777
ini.SetOutput(os.Stdout)
7878
ini.PropSet.PrintDefaults()
7979
}
80+
81+
func configFilePath() string {
82+
if fpath := os.Getenv("PRISME_CONFIG"); fpath != "" {
83+
return fpath
84+
}
85+
return configue.File("./", "config.ini")
86+
}

cmd/prisme/serve.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434

3535
func serve() {
3636
// Setup configuration loader.
37-
ini := configue.NewINI(configue.File("./", "config.ini"))
37+
ini := configue.NewINI(configFilePath())
3838
figue := configue.New(
3939
"",
4040
configue.ContinueOnError,

config/example.ini

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[server]
2+
.access.log = "/dev/stdout"
3+
.debug = true
4+
.port = 8000
5+
.api.stats.allow.origins = "*"
6+
7+
[proxy]
8+
.trust = true
9+
10+
[clickhouse]
11+
.tls = false
12+
.hostport = "clickhouse.localhost:9000" # Native port
13+
.db = "prisme"
14+
.user = "clickhouse"
15+
.password = "password"
16+

config/local.ini

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
origins = "localhost,mywebsite.localhost,foo.mywebsite.localhost"
2+
3+
[server]
4+
access.log = "/dev/stdout"
5+
debug = true
6+
port = 8000
7+
api.stats.allow.origins = "*"
8+
9+
[proxy]
10+
trust = true
11+
12+
[clickhouse]
13+
tls = false
14+
hostport = "clickhouse.localhost:9000" # Native port
15+
database = "prisme"
16+
user = "clickhouse"
17+
password = "password"
18+
19+
[eventstore]
20+
max.batch.size = 1
21+

0 commit comments

Comments
 (0)