Skip to content

Commit 2d1e749

Browse files
drahnrsylvestre
authored andcommitted
docs: document all config options, includes a unit test for verification
1 parent 75a0483 commit 2d1e749

File tree

2 files changed

+189
-2
lines changed

2 files changed

+189
-2
lines changed

docs/Configuration.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Available Configuration Options
2+
3+
## file
4+
5+
```toml
6+
[dist]
7+
# where to find the scheduler
8+
scheduler_url = "http://1.2.3.4:10600"
9+
# a set of prepackaged toolchains
10+
toolchains = []
11+
# the maximum size of the toolchain cache in bytes
12+
toolchain_cache_size = 5368709120
13+
cache_dir = "/home/user/.cache/sccache-dist-client"
14+
15+
[dist.auth]
16+
type = "token"
17+
token = "secrettoken"
18+
19+
20+
#[cache.azure]
21+
# does not work as it appears
22+
23+
[cache.disk]
24+
dir = "/tmp/.cache/sccache"
25+
size = 7516192768 # 7 GiBytes
26+
27+
[cache.gcs]
28+
# optional url
29+
url = "..."
30+
rw_mode = "READ_ONLY"
31+
# rw_mode = "READ_WRITE"
32+
cred_path = "/psst/secret/cred"
33+
bucket = "bucket"
34+
35+
[cache.memcached]
36+
url = "..."
37+
38+
[cache.redis]
39+
url = "redis://user:[email protected]:6379/1"
40+
41+
[cache.s3]
42+
bucket = "name"
43+
endpoint = "s3-us-east-1.amazonaws.com"
44+
use_ssl = true
45+
```
46+
47+
## env
48+
49+
Whatever is set by a file based configuration, it is overruled by the env
50+
configuration variables
51+
52+
### misc
53+
54+
* `SCCACHE_ALLOW_CORE_DUMPS` to enable core dumps by the server
55+
* `SCCACHE_CONF` configuration file path
56+
* `SCCACHE_CACHED_CONF`
57+
* `SCCACHE_IDLE_TIMEOUT` how long the local daemon process waits for more client requests before exiting
58+
* `SCCACHE_STARTUP_NOTIFY` specify a path to a socket which will be used for server completion notification
59+
* `SCCACHE_MAX_FRAME_LENGTH` how much data can be transfered between client and server
60+
* `SCCACHE_NO_DAEMON` set to `1` to disable putting the server to the background
61+
62+
### cache configs
63+
64+
#### disk
65+
66+
* `SCCACHE_DIR` local on disk artifact cache directory
67+
* `SCCACHE_CACHE_SIZE` maximum size of the local on disk cache i.e. `10G`
68+
69+
#### s3 compatible
70+
71+
* `SCCACHE_BUCKET` s3 bucket to be used
72+
* `SCCACHE_ENDPOINT` s3 endpoint
73+
* `SCCACHE_REGION` s3 region
74+
* `SCCACHE_S3_USE_SSL` s3 endpoint requires TLS, set this to `true`
75+
76+
The endpoint used then becomes `${SCCACHE_BUCKET}.s3-{SCCACHE_REGION}.amazonaws.com`.
77+
If `SCCACHE_REGION` is undefined, it will default to `us-east-1`.
78+
79+
#### redis
80+
81+
* `SCCACHE_REDIS` full redis url, including auth and access token/passwd
82+
83+
The full url appears then as `redis://user:[email protected]:6379/1`.
84+
85+
#### memcached
86+
87+
* `SCCACHE_MEMCACHED` memcached url
88+
89+
#### gcs
90+
91+
* `SCCACHE_GCS_BUCKET`
92+
* `SCCACHE_GCS_CREDENTIALS_URL`
93+
* `SCCACHE_GCS_KEY_PATH`
94+
* `SCCACHE_GCS_RW_MODE`
95+
96+
#### azure
97+
98+
* `SCCACHE_AZURE_CONNECTION_STRING`

src/config.rs

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ pub enum CacheType {
215215
S3(S3CacheConfig),
216216
}
217217

218-
#[derive(Debug, Default, Serialize, Deserialize)]
218+
#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
219219
#[serde(deny_unknown_fields)]
220220
pub struct CacheConfigs {
221221
pub azure: Option<AzureCacheConfig>,
@@ -404,7 +404,7 @@ impl Default for DistConfig {
404404
}
405405

406406
// TODO: fields only pub for tests
407-
#[derive(Debug, Default, Serialize, Deserialize)]
407+
#[derive(Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
408408
#[serde(default)]
409409
#[serde(deny_unknown_fields)]
410410
pub struct FileConfig {
@@ -938,3 +938,92 @@ fn test_gcs_oauth_url() {
938938
None => unreachable!(),
939939
};
940940
}
941+
942+
943+
944+
#[test]
945+
fn full_toml_parse() {
946+
const CONFIG_STR: &str = r#"
947+
[dist]
948+
# where to find the scheduler
949+
scheduler_url = "http://1.2.3.4:10600"
950+
# a set of prepackaged toolchains
951+
toolchains = []
952+
# the maximum size of the toolchain cache in bytes
953+
toolchain_cache_size = 5368709120
954+
cache_dir = "/home/user/.cache/sccache-dist-client"
955+
956+
[dist.auth]
957+
type = "token"
958+
token = "secrettoken"
959+
960+
961+
#[cache.azure]
962+
# does not work as it appears
963+
964+
[cache.disk]
965+
dir = "/tmp/.cache/sccache"
966+
size = 7516192768 # 7 GiBytes
967+
968+
[cache.gcs]
969+
# optional url
970+
url = "..."
971+
rw_mode = "READ_ONLY"
972+
# rw_mode = "READ_WRITE"
973+
cred_path = "/psst/secret/cred"
974+
bucket = "bucket"
975+
976+
[cache.memcached]
977+
url = "..."
978+
979+
[cache.redis]
980+
url = "redis://user:[email protected]:6379/1"
981+
982+
[cache.s3]
983+
bucket = "name"
984+
endpoint = "s3-us-east-1.amazonaws.com"
985+
use_ssl = true
986+
"#;
987+
988+
let file_config: FileConfig = toml::from_str(CONFIG_STR).expect("Is valid toml.");
989+
assert_eq!(file_config,
990+
FileConfig {
991+
cache: CacheConfigs {
992+
azure: None, // TODO not sure how to represent a unit struct in TOML Some(AzureCacheConfig),
993+
disk: Some(DiskCacheConfig {
994+
dir: PathBuf::from("/tmp/.cache/sccache"),
995+
size: 7 * 1024 * 1024 * 1024,
996+
}),
997+
gcs: Some(GCSCacheConfig {
998+
url: Some("...".to_owned()),
999+
bucket: "bucket".to_owned(),
1000+
cred_path: Some(PathBuf::from("/psst/secret/cred")),
1001+
rw_mode: GCSCacheRWMode::ReadOnly,
1002+
1003+
}),
1004+
redis: Some(RedisCacheConfig {
1005+
url: "redis://user:[email protected]:6379/1".to_owned(),
1006+
}),
1007+
memcached: Some(MemcachedCacheConfig {
1008+
url: "...".to_owned(),
1009+
}),
1010+
s3: Some(S3CacheConfig {
1011+
bucket: "name".to_owned(),
1012+
endpoint: "s3-us-east-1.amazonaws.com".to_owned(),
1013+
use_ssl: true,
1014+
}),
1015+
},
1016+
dist: DistConfig {
1017+
auth: DistAuth::Token { token: "secrettoken".to_owned() } ,
1018+
#[cfg(any(feature = "dist-client", feature = "dist-server"))]
1019+
scheduler_url: Some(parse_http_url("http://1.2.3.4:10600").map(|url| { HTTPUrl::from_url(url)}).expect("Scheduler url must be valid url str")),
1020+
#[cfg(not(any(feature = "dist-client", feature = "dist-server")))]
1021+
scheduler_url: Some("http://1.2.3.4:10600".to_owned()),
1022+
cache_dir: PathBuf::from("/home/user/.cache/sccache-dist-client"),
1023+
toolchains: vec![],
1024+
toolchain_cache_size: 5368709120,
1025+
rewrite_includes_only: false,
1026+
},
1027+
}
1028+
)
1029+
}

0 commit comments

Comments
 (0)