-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yiling
authored and
yiling
committed
Nov 15, 2024
1 parent
2900741
commit cc4efc1
Showing
9 changed files
with
411 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
CSGHub server supports two configuration methods: using environment variables or configuration files. You can also combine them, for example, by placing non-sensitive configurations in a config file and overriding sensitive configurations with environment variables. | ||
|
||
### Using a Config File | ||
|
||
CSGHub supports TOML format for config files. When starting any service from the command line, you can specify the config file with the `--config` option: | ||
|
||
``` | ||
go run cmd/csghub-server/main.go start server --config local.toml | ||
go run cmd/csghub-server/main.go deploy runner --config local.toml | ||
``` | ||
|
||
We provide an [example config file](common/config/config.toml.example), you can rename it, modify as needed and use. All available configurations are defined in [this Go file](common/config/config.go). The TOML configuration uses snake_case naming convention, and names automatically map to corresponding struct field names. | ||
|
||
If a config value is missing in the config file, the `default` tag value specified in the Go struct file will be used. | ||
|
||
### Using Environment Variables | ||
|
||
CSGHub also supports configuration through environment variables. The relevant environment variable names are defined in [this Go file](common/config/config.go) under the `env` tag. If an environment variable is absent, the value in the `default` tag will be used. | ||
|
||
### Combining Config File with Environment Variables | ||
|
||
You can use config file together with environment variables. When both are used, environment variables take **higher priority** than the config file. For example, if you have a `Port` setting, and you specify it in the TOML file as `port=1234` and in an environment variable as `export PORT=5678`, the environment variable value (5678) will be used for the port configuration. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
[saas] | ||
enabled = false | ||
|
||
[instance] | ||
id = "" | ||
|
||
[swagger] | ||
enabled = false | ||
|
||
[api] | ||
token = "0c11e6e4f2054444374ba3f0b70de4145935a7312289d404814cd5907c6aa93cc65cd35dbf94e04c13a3dedbf51f1694de84240c8acb7238b54a2c3ac8e87c59" | ||
|
||
[https] | ||
enabled = false | ||
|
||
[api_server] | ||
port = 8080 | ||
public_domain = "http://localhost:8080" | ||
ssh_domain = "git@localhost:2222" | ||
|
||
[mirror] | ||
url = "http://localhost:8085" | ||
token = "" | ||
port = 8085 | ||
session_secret_key = "mirror" | ||
worker_number = 5 | ||
|
||
[docs_host] | ||
url = "http://localhost:6636" | ||
|
||
[database] | ||
driver = "pg" | ||
dsn = "postgresql://postgres:postgres@localhost:5432/starhub_server?sslmode=disable" | ||
timezone = "Asia/Shanghai" | ||
|
||
[redis] | ||
endpoint = "localhost:6379" | ||
max_retries = 3 | ||
min_idle_connections = 0 | ||
user = "" | ||
password = "" | ||
sentinel_mode = false | ||
sentinel_master = "" | ||
sentinel_endpoint = "" | ||
|
||
[git_server] | ||
url = "http://localhost:3000" | ||
type = "gitea" | ||
host = "http://localhost:3000" | ||
secret_key = "619c849c49e03754454ccd4cda79a209ce0b30b3" | ||
username = "root" | ||
password = "password123" | ||
timeout_sec = 5 | ||
|
||
[gitaly_server] | ||
address = "tcp://localhost:9999" | ||
storage = "default" | ||
token = "abc123secret" | ||
jwt_secret = "signing-key" | ||
|
||
[mirror_server] | ||
enabled = true | ||
url = "http://localhost:3001" | ||
type = "gitea" | ||
host = "http://localhost:3001" | ||
secret_key = "619c849c49e03754454ccd4cda79a209ce0b30b3" | ||
username = "root" | ||
password = "password123" | ||
|
||
[frontend] | ||
url = "https://opencsg.com" | ||
|
||
[s3] | ||
ssl = false | ||
access_key_id = "" | ||
access_key_secret = "" | ||
region = "" | ||
endpoint = "localhost:9000" | ||
internal_endpoint = "" | ||
bucket = "opencsg-test" | ||
enable_ssl = false | ||
|
||
[sensitive_check] | ||
enabled = false | ||
access_key_id = "" | ||
access_key_secret = "" | ||
region = "" | ||
endpoint = "oss-cn-beijing.aliyuncs.com" | ||
enable_ssl = true | ||
|
||
[jwt] | ||
signing_key = "signing-key" | ||
valid_hour = 24 | ||
|
||
[inference] | ||
server_addr = "http://localhost:8000" | ||
|
||
[space] | ||
builder_endpoint = "http://localhost:8081" | ||
runner_endpoint = "http://localhost:8082" | ||
runner_server_port = 8082 | ||
internal_root_domain = "internal.example.com" | ||
public_root_domain = "public.example.com" | ||
docker_reg_base = "registry.cn-beijing.aliyuncs.com/opencsg_public/" | ||
image_pull_secret = "opencsg-pull-secret" | ||
rproxy_server_port = 8083 | ||
session_secret_key = "secret" | ||
deploy_timeout_in_min = 30 | ||
gpu_model_label = "aliyun.accelerator/nvidia_name" | ||
readiness_delay_seconds = 120 | ||
readiness_period_seconds = 10 | ||
readiness_failure_threshold = 3 | ||
|
||
[model] | ||
deploy_timeout_in_min = 60 | ||
download_endpoint = "https://hub.opencsg.com" | ||
docker_reg_base = "opencsg-registry.cn-beijing.cr.aliyuncs.com/public/" | ||
nim_docker_secret_name = "ngc-secret" | ||
nim_ngc_secret_name = "nvidia-nim-secrets" | ||
|
||
[event] | ||
sync_interval = 1 | ||
|
||
[casdoor] | ||
client_id = "client_id" | ||
client_secret = "client_secret" | ||
endpoint = "http://localhost:80" | ||
certificate = "/etc/casdoor/certificate.pem" | ||
organization_name = "opencsg" | ||
application_name = "opencsg" | ||
|
||
[nats] | ||
url = "nats://account:g98dc5FA8v4J7ck90w@natsmaster:4222" | ||
msg_fetch_timeout_in_sec = 5 | ||
meter_request_subject = "accounting.metering.>" | ||
meter_duration_send_subject = "accounting.metering.duration" | ||
meter_token_send_subject = "accounting.metering.token" | ||
meter_quota_send_subject = "accounting.metering.quota" | ||
|
||
[accounting] | ||
host = "http://localhost" | ||
port = 8086 | ||
|
||
[user] | ||
host = "http://localhost" | ||
port = 8088 | ||
signin_success_redirect_url = "http://localhost:3000/server/callback" | ||
|
||
[multi_sync] | ||
saas_api_domain = "https://hub.opencsg.com" | ||
saas_sync_domain = "https://sync.opencsg.com" | ||
enabled = true | ||
|
||
[telemetry] | ||
enabled = true | ||
report_url = "http://hub.opencsg.com/api/v1/telemetry" | ||
|
||
[auto_clean] | ||
instance = false | ||
|
||
[dataset] | ||
prompt_max_jsonl_file_size = 1048576 | ||
|
||
[dataflow] | ||
host = "http://127.0.0.1" | ||
port = 8000 | ||
|
||
[moderation] | ||
host = "http://localhost" | ||
port = 8089 | ||
encoded_sensitive_words = "5Lmg6L+R5bmzLHhpamlucGluZw==" | ||
|
||
[workflow] | ||
endpoint = "localhost:7233" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestConfig_LoadConfig(t *testing.T) { | ||
t.Run("config env", func(t *testing.T) { | ||
t.Setenv("STARHUB_SERVER_INSTANCE_ID", "foo") | ||
t.Setenv("STARHUB_SERVER_SERVER_PORT", "6789") | ||
cfg, err := LoadConfig() | ||
require.Nil(t, err) | ||
|
||
require.Equal(t, "foo", cfg.InstanceID) | ||
require.Equal(t, 6789, cfg.APIServer.Port) | ||
require.Equal(t, "git@localhost:2222", cfg.APIServer.SSHDomain) | ||
}) | ||
|
||
t.Run("config file", func(t *testing.T) { | ||
SetConfigFile("test.toml") | ||
cfg, err := LoadConfig() | ||
require.Nil(t, err) | ||
|
||
require.Equal(t, "bar", cfg.InstanceID) | ||
require.Equal(t, 4321, cfg.APIServer.Port) | ||
require.Equal(t, "git@localhost:2222", cfg.APIServer.SSHDomain) | ||
}) | ||
|
||
t.Run("file and env", func(t *testing.T) { | ||
SetConfigFile("test.toml") | ||
t.Setenv("STARHUB_SERVER_INSTANCE_ID", "foobar") | ||
cfg, err := LoadConfig() | ||
require.Nil(t, err) | ||
|
||
require.Equal(t, "foobar", cfg.InstanceID) | ||
require.Equal(t, 4321, cfg.APIServer.Port) | ||
require.Equal(t, "git@localhost:2222", cfg.APIServer.SSHDomain) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
instance_id = "bar" | ||
|
||
[api_server] | ||
port = 4321 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters