-
Notifications
You must be signed in to change notification settings - Fork 625
feat: support for Tencent Cloud Object Storage #2563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # COS | ||
|
|
||
| If you want to use _Tencent Cloud Object Storage_ (aka COS) for the sccache cache, you need to set the `SCCACHE_COS_BUCKET` environment variable to the name of the COS bucket to use. | ||
|
|
||
| You **must** specify the endpoint URL using the `SCCACHE_COS_ENDPOINT` environment variable. More details are at [COS endpoints](https://www.tencentcloud.com/document/product/436/6224). | ||
|
|
||
| You can also define a prefix that will be prepended to the keys of all cache objects created and read within the COS bucket, effectively creating a scope. To do that use the `SCCACHE_COS_KEY_PREFIX` environment variable. This can be useful when sharing a bucket with another application. | ||
|
|
||
| ## Credentials | ||
|
|
||
| Sccache is able to load credentials from environment variables: `TENCENTCLOUD_SECRET_ID` and `TENCENTCLOUD_SECRET_KEY`. More details about the access of COS bucket can be found at the [introduction page](https://www.tencentcloud.com/document/product/436/7751). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,6 +112,11 @@ bucket = "name" | |
| endpoint = "oss-us-east-1.aliyuncs.com" | ||
| key_prefix = "ossprefix" | ||
| no_credentials = true | ||
|
|
||
| [cache.cos] | ||
| bucket = "name" | ||
| endpoint = "cos.na-siliconvalley.myqcloud.com" | ||
| key_prefix = "cosprefix" | ||
| ``` | ||
|
|
||
| sccache looks for its configuration file at the path indicated by env variable `SCCACHE_CONF`. | ||
|
|
@@ -234,3 +239,11 @@ The full url appears then as `redis://user:[email protected]:6379/?db=1`. | |
| * `ALIBABA_CLOUD_ACCESS_KEY_ID` | ||
| * `ALIBABA_CLOUD_ACCESS_KEY_SECRET` | ||
| * `SCCACHE_OSS_NO_CREDENTIALS` | ||
|
|
||
| #### Tencent Cloud Object Storage (COS) | ||
|
|
||
| * `SCCACHE_COS_BUCKET` | ||
| * `SCCACHE_COS_ENDPOINT` | ||
| * `SCCACHE_COS_KEY_PREFIX` | ||
| * `TENCENTCLOUD_SECRET_ID` | ||
| * `TENCENTCLOUD_SECRET_KEY` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| use opendal::Operator; | ||
| use opendal::layers::{HttpClientLayer, LoggingLayer}; | ||
| use opendal::services::Cos; | ||
|
|
||
| use crate::errors::*; | ||
|
|
||
| use super::http_client::set_user_agent; | ||
|
|
||
| pub struct COSCache; | ||
|
|
||
| // Implement for Tencent Cloud Object Storage | ||
| impl COSCache { | ||
| pub fn build(bucket: &str, key_prefix: &str, endpoint: Option<&str>) -> Result<Operator> { | ||
| let mut builder = Cos::default().bucket(bucket).root(key_prefix); | ||
|
|
||
| if let Some(endpoint) = endpoint { | ||
| builder = builder.endpoint(endpoint); | ||
| } | ||
|
|
||
| let op = Operator::new(builder)? | ||
| .layer(HttpClientLayer::new(set_user_agent())) | ||
| .layer(LoggingLayer::default()) | ||
| .finish(); | ||
| Ok(op) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -361,6 +361,15 @@ pub struct OSSCacheConfig { | |||||||||||
| pub no_credentials: bool, | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] | ||||||||||||
| #[serde(deny_unknown_fields)] | ||||||||||||
| pub struct COSCacheConfig { | ||||||||||||
| pub bucket: String, | ||||||||||||
| #[serde(default)] | ||||||||||||
| pub key_prefix: String, | ||||||||||||
| pub endpoint: Option<String>, | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| #[derive(Debug, PartialEq, Eq)] | ||||||||||||
| pub enum CacheType { | ||||||||||||
| Azure(AzureCacheConfig), | ||||||||||||
|
|
@@ -371,6 +380,7 @@ pub enum CacheType { | |||||||||||
| S3(S3CacheConfig), | ||||||||||||
| Webdav(WebdavCacheConfig), | ||||||||||||
| OSS(OSSCacheConfig), | ||||||||||||
| COS(COSCacheConfig), | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| #[derive(Debug, Default, Serialize, Deserialize, PartialEq, Eq)] | ||||||||||||
|
|
@@ -385,6 +395,7 @@ pub struct CacheConfigs { | |||||||||||
| pub s3: Option<S3CacheConfig>, | ||||||||||||
| pub webdav: Option<WebdavCacheConfig>, | ||||||||||||
| pub oss: Option<OSSCacheConfig>, | ||||||||||||
| pub cos: Option<COSCacheConfig>, | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| impl CacheConfigs { | ||||||||||||
|
|
@@ -401,6 +412,7 @@ impl CacheConfigs { | |||||||||||
| s3, | ||||||||||||
| webdav, | ||||||||||||
| oss, | ||||||||||||
| cos, | ||||||||||||
| } = self; | ||||||||||||
|
|
||||||||||||
| let cache_type = s3 | ||||||||||||
|
|
@@ -411,7 +423,8 @@ impl CacheConfigs { | |||||||||||
| .or_else(|| gha.map(CacheType::GHA)) | ||||||||||||
| .or_else(|| azure.map(CacheType::Azure)) | ||||||||||||
| .or_else(|| webdav.map(CacheType::Webdav)) | ||||||||||||
| .or_else(|| oss.map(CacheType::OSS)); | ||||||||||||
| .or_else(|| oss.map(CacheType::OSS)) | ||||||||||||
| .or_else(|| cos.map(CacheType::COS)); | ||||||||||||
|
|
||||||||||||
| let fallback = disk.unwrap_or_default(); | ||||||||||||
|
|
||||||||||||
|
|
@@ -430,6 +443,7 @@ impl CacheConfigs { | |||||||||||
| s3, | ||||||||||||
| webdav, | ||||||||||||
| oss, | ||||||||||||
| cos, | ||||||||||||
| } = other; | ||||||||||||
|
|
||||||||||||
| if azure.is_some() { | ||||||||||||
|
|
@@ -456,10 +470,12 @@ impl CacheConfigs { | |||||||||||
| if webdav.is_some() { | ||||||||||||
| self.webdav = webdav; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please keep the empty line to be consistent
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is inconsistent with others. |
||||||||||||
| if oss.is_some() { | ||||||||||||
| self.oss = oss; | ||||||||||||
| } | ||||||||||||
| if cos.is_some() { | ||||||||||||
|
Comment on lines
475
to
+476
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| self.cos = cos; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
|
@@ -892,6 +908,20 @@ fn config_from_env() -> Result<EnvConfig> { | |||||||||||
| bail!("If setting OSS credentials, SCCACHE_OSS_NO_CREDENTIALS must not be set."); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // ======= COS ======= | ||||||||||||
| let cos = if let Ok(bucket) = env::var("SCCACHE_COS_BUCKET") { | ||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing validation: SCCACHE_COS_ENDPOINT should be required when SCCACHE_COS_BUCKET is set. Add validation like: if
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I followed the codes of other object stores (like OSS). They don't validate the |
||||||||||||
| let endpoint = env::var("SCCACHE_COS_ENDPOINT").ok(); | ||||||||||||
| let key_prefix = key_prefix_from_env_var("SCCACHE_COS_KEY_PREFIX"); | ||||||||||||
|
|
||||||||||||
| Some(COSCacheConfig { | ||||||||||||
| bucket, | ||||||||||||
| endpoint, | ||||||||||||
| key_prefix, | ||||||||||||
| }) | ||||||||||||
| } else { | ||||||||||||
| None | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| // ======= Local ======= | ||||||||||||
| let disk_dir = env::var_os("SCCACHE_DIR").map(PathBuf::from); | ||||||||||||
| let disk_sz = env::var("SCCACHE_CACHE_SIZE") | ||||||||||||
|
|
@@ -944,6 +974,7 @@ fn config_from_env() -> Result<EnvConfig> { | |||||||||||
| s3, | ||||||||||||
| webdav, | ||||||||||||
| oss, | ||||||||||||
| cos, | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| Ok(EnvConfig { cache }) | ||||||||||||
|
|
@@ -1559,6 +1590,11 @@ bucket = "name" | |||||||||||
| endpoint = "oss-us-east-1.aliyuncs.com" | ||||||||||||
| key_prefix = "ossprefix" | ||||||||||||
| no_credentials = true | ||||||||||||
|
|
||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add a test to cover the parsing of this block
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test is already added here: [cache.cos]
bucket = "name"
endpoint = "cos.na-siliconvalley.myqcloud.com"
key_prefix = "cosprefix" |
||||||||||||
| [cache.cos] | ||||||||||||
| bucket = "name" | ||||||||||||
| endpoint = "cos.na-siliconvalley.myqcloud.com" | ||||||||||||
| key_prefix = "cosprefix" | ||||||||||||
| "#; | ||||||||||||
|
|
||||||||||||
| let file_config: FileConfig = toml::from_str(CONFIG_STR).expect("Is valid toml."); | ||||||||||||
|
|
@@ -1625,6 +1661,11 @@ no_credentials = true | |||||||||||
| key_prefix: "ossprefix".into(), | ||||||||||||
| no_credentials: true, | ||||||||||||
| }), | ||||||||||||
| cos: Some(COSCacheConfig { | ||||||||||||
| bucket: "name".to_owned(), | ||||||||||||
| endpoint: Some("cos.na-siliconvalley.myqcloud.com".to_owned()), | ||||||||||||
| key_prefix: "cosprefix".into(), | ||||||||||||
| }), | ||||||||||||
| }, | ||||||||||||
| dist: DistConfig { | ||||||||||||
| auth: DistAuth::Token { | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the doc, you say that it is mandatory, so, maybe don't use Option here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other object store services like S3, OSS use
Optiontoo.https://github.com/mozilla/sccache/blob/main/docs/OSS.md?plain=1#L5