这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/turborepo-lib/src/config/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ mod test {
env.insert("turbo_remote_cache_read_only".into(), "1".into());
env.insert("turbo_run_summary".into(), "true".into());
env.insert("turbo_allow_no_turbo_json".into(), "true".into());
env.insert("turbo_remote_cache_upload_timeout".into(), "200".into());

let config = EnvVars::new(&env)
.unwrap()
Expand All @@ -331,6 +332,7 @@ mod test {
assert!(config.remote_cache_read_only());
assert!(config.run_summary());
assert!(config.allow_no_turbo_json());
assert_eq!(config.upload_timeout(), 200);
assert_eq!(turbo_api, config.api_url.unwrap());
assert_eq!(turbo_login, config.login_url.unwrap());
assert_eq!(turbo_team, config.team_slug.unwrap());
Expand Down
77 changes: 61 additions & 16 deletions crates/turborepo-lib/src/config/turbo_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,10 @@ impl<'a> TurboJsonReader<'a> {
pub fn new(repo_root: &'a AbsoluteSystemPath) -> Self {
Self { repo_root }
}
}

impl<'a> ResolvedConfigurationOptions for TurboJsonReader<'a> {
fn get_configuration_options(
&self,
existing_config: &ConfigurationOptions,
fn turbo_json_to_config_options(
turbo_json: RawTurboJson,
) -> Result<ConfigurationOptions, Error> {
let turbo_json_path = existing_config.root_turbo_json_path(self.repo_root);
let turbo_json = RawTurboJson::read(self.repo_root, &turbo_json_path).or_else(|e| {
if let Error::Io(e) = &e {
if matches!(e.kind(), std::io::ErrorKind::NotFound) {
return Ok(Default::default());
}
}

Err(e)
})?;
let mut opts = if let Some(remote_cache_options) = &turbo_json.remote_cache {
remote_cache_options.into()
} else {
Expand Down Expand Up @@ -64,8 +51,28 @@ impl<'a> ResolvedConfigurationOptions for TurboJsonReader<'a> {
}
}

impl<'a> ResolvedConfigurationOptions for TurboJsonReader<'a> {
fn get_configuration_options(
&self,
existing_config: &ConfigurationOptions,
) -> Result<ConfigurationOptions, Error> {
let turbo_json_path = existing_config.root_turbo_json_path(self.repo_root);
let turbo_json = RawTurboJson::read(self.repo_root, &turbo_json_path).or_else(|e| {
if let Error::Io(e) = &e {
if matches!(e.kind(), std::io::ErrorKind::NotFound) {
return Ok(Default::default());
}
}

Err(e)
})?;
Self::turbo_json_to_config_options(turbo_json)
}
}

#[cfg(test)]
mod test {
use serde_json::json;
use tempfile::tempdir;

use super::*;
Expand Down Expand Up @@ -111,7 +118,7 @@ mod test {
};
root_turbo_json_path
.create_with_contents(
serde_json::to_string_pretty(&serde_json::json!({
serde_json::to_string_pretty(&json!({
"daemon": false
}))
.unwrap(),
Expand All @@ -123,4 +130,42 @@ mod test {
// Make sure we read the correct turbo.json
assert_eq!(config.daemon(), Some(false));
}

#[test]
fn test_remote_cache_options() {
let timeout = 100;
let upload_timeout = 200;
let api_url = "localhost:3000";
let login_url = "localhost:3001";
let team_slug = "acme-packers";
let team_id = "id-123";
let turbo_json = RawTurboJson::parse(
&serde_json::to_string_pretty(&json!({
"remoteCache": {
"enabled": true,
"timeout": timeout,
"uploadTimeout": upload_timeout,
"apiUrl": api_url,
"loginUrl": login_url,
"teamSlug": team_slug,
"teamId": team_id,
"signature": true,
"preflight": true
}
}))
.unwrap(),
"junk",
)
.unwrap();
let config = TurboJsonReader::turbo_json_to_config_options(turbo_json).unwrap();
assert!(config.enabled());
assert_eq!(config.timeout(), timeout);
assert_eq!(config.upload_timeout(), upload_timeout);
assert_eq!(config.api_url(), api_url);
assert_eq!(config.login_url(), login_url);
assert_eq!(config.team_slug(), Some(team_slug));
assert_eq!(config.team_id(), Some(team_id));
assert!(config.signature());
assert!(config.preflight());
}
}
3 changes: 3 additions & 0 deletions crates/turborepo-lib/src/turbo_json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ pub(crate) struct RawRemoteCacheOptions {
timeout: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
enabled: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
upload_timeout: Option<u64>,
}

impl From<&RawRemoteCacheOptions> for ConfigurationOptions {
Expand All @@ -90,6 +92,7 @@ impl From<&RawRemoteCacheOptions> for ConfigurationOptions {
signature: remote_cache_opts.signature,
preflight: remote_cache_opts.preflight,
timeout: remote_cache_opts.timeout,
upload_timeout: remote_cache_opts.upload_timeout,
enabled: remote_cache_opts.enabled,
..Self::default()
}
Expand Down
12 changes: 12 additions & 0 deletions docs/repo-docs/reference/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ description: Learn how to configure Turborepo through `turbo.json`.
---

import { Callout } from '#/components/callout';
import { InVersion } from '#/components/in-version';
import Link from 'next/link';

Configure the behavior of `turbo` by adding a `turbo.json` file in your Workspace's root directory.
Expand Down Expand Up @@ -533,6 +534,17 @@ Sets a timeout for remote cache operations.
Value is given in seconds and only whole values are accepted.
If `0` is passed, then there is no timeout for any cache operations.

<InVersion version="2.3.2">
### `uploadTimeout`

Default: `60`

Sets a timeout for remote cache uploads.
Value is given in seconds and only whole values are accepted.
If `0` is passed, then there is no timeout for any remote cache uploads.

</InVersion>

### `apiUrl`

Default: `"https://vercel.com"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ System environment variables are always overridden by flag values provided direc
| `TURBO_REMOTE_CACHE_READ_ONLY` | Prevent writing to the [Remote Cache](/repo/docs/core-concepts/remote-caching) - but still allow reading. |
| `TURBO_REMOTE_CACHE_SIGNATURE_KEY` | Sign artifacts with a secret key. For more information, visit [the Artifact Integrity section](/repo/docs/core-concepts/remote-caching#artifact-integrity-and-authenticity-verification). |
| `TURBO_REMOTE_CACHE_TIMEOUT` | Set a timeout in seconds for `turbo` to get artifacts from [Remote Cache](/repo/docs/core-concepts/remote-caching). |
| `TURBO_REMOTE_CACHE_UPLOAD_TIMEOUT` | Set a timeout in seconds for `turbo` to upload artifacts to [Remote Cache](/repo/docs/core-concepts/remote-caching). |
| `TURBO_REMOTE_ONLY` | Always ignore the local filesystem cache for all tasks. |
| `TURBO_RUN_SUMMARY` | Generate a [Run Summary](/repo/docs/reference/run#--summarize) when you run tasks. |
| `TURBO_SCM_BASE` | Base used by `--affected` when calculating what has changed from `base...head` |
Expand Down
5 changes: 5 additions & 0 deletions packages/turbo-types/schemas/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@
"type": "number",
"description": "Sets a timeout for remote cache operations. Value is given in seconds and only whole values are accepted. If `0` is passed, then there is no timeout for any cache operations.",
"default": 30
},
"uploadTimeout": {
"type": "number",
"description": "Sets a timeout for remote cache uploads. Value is given in seconds and only whole values are accepted. If `0` is passed, then there is no timeout for any remote cache uploads.",
"default": 60
}
},
"additionalProperties": false
Expand Down
5 changes: 5 additions & 0 deletions packages/turbo-types/schemas/schema.v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@
"type": "number",
"description": "Sets a timeout for remote cache operations. Value is given in seconds and only whole values are accepted. If `0` is passed, then there is no timeout for any cache operations.",
"default": 30
},
"uploadTimeout": {
"type": "number",
"description": "Sets a timeout for remote cache uploads. Value is given in seconds and only whole values are accepted. If `0` is passed, then there is no timeout for any remote cache uploads.",
"default": 60
}
},
"additionalProperties": false
Expand Down
8 changes: 8 additions & 0 deletions packages/turbo-types/src/types/config-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,14 @@ export interface RemoteCache {
* @defaultValue `30`
*/
timeout?: number;
/**
* Sets a timeout for remote cache uploads. Value is given in seconds and
* only whole values are accepted. If `0` is passed, then there is no timeout
* for any remote cache uploads.
*
* @defaultValue `60`
*/
uploadTimeout?: number;
}

export const isRootSchemaV2 = (schema: Schema): schema is RootSchema =>
Expand Down
Loading