From f8e8c203e87c338f17a645f3014dbe16117484a4 Mon Sep 17 00:00:00 2001 From: Gaspar Garcia Date: Tue, 29 Mar 2022 14:48:54 -0700 Subject: [PATCH 1/4] Add docs for remote-only --- .../docs/reference/command-line-reference.mdx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/pages/docs/reference/command-line-reference.mdx b/docs/pages/docs/reference/command-line-reference.mdx index 02454511d4349..2862f043d7388 100644 --- a/docs/pages/docs/reference/command-line-reference.mdx +++ b/docs/pages/docs/reference/command-line-reference.mdx @@ -83,7 +83,7 @@ turbo run build --no-deps Let's say you have packages A, B, C, and D where A depends on B and C depends on D. You run `turbo run build` for the first time and everything is built and cached. Then, you change a line of code in B. With the `--deps` flag on, running `turbo run build` will execute `build` in B and then A, but not in C and D because they are not impacted by the change. If you were to run `turbo run build --no-deps` instead, turbo will only run `build` in B. -#### --dry / --dry-run +#### `--dry / --dry-run` Instead of executing tasks, display details about the affected packages and tasks that would be run. Specify `--dry=json` to get the output in JSON format. @@ -179,7 +179,7 @@ This is useful when using `--scope` in CI as it guarantees that every dependency #### `--no-cache` -Default false. Do not cache results of the task. This is useful for watch commands like `next dev` or `react-scripts start`. +Default `false`. Do not cache results of the task. This is useful for watch commands like `next dev` or `react-scripts start`. ```shell turbo run build --no-cache @@ -199,7 +199,7 @@ turbo run build --output-logs=new-only #### `--only` -Default false. Restricts execution to only include specified tasks. This is very similar to how how `lerna` or `pnpm` run tasks by default. +Default `false`. Restricts execution to only include specified tasks. This is very similar to how how `lerna` or `pnpm` run tasks by default. Given this pipeline in `turbo.json`: @@ -236,6 +236,14 @@ turbo run lint --parallel --no-cache turbo run dev --parallel --no-cache ``` +#### `--remote-only` + +Default `false`. Ignore the local filesystem cache for all tasks. Only allow reading and caching artifacts using the remote cache. + +```shell +turbo run build --remote-only +``` + #### `--scope` `type: string[]` From 66aff6a7174cdf3a179b23a0c758b4bda9f20b53 Mon Sep 17 00:00:00 2001 From: Gaspar Garcia Date: Tue, 29 Mar 2022 15:09:56 -0700 Subject: [PATCH 2/4] Implement command --- cli/internal/cache/cache.go | 4 ++-- cli/internal/run/run.go | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cli/internal/cache/cache.go b/cli/internal/cache/cache.go index e1ecb93685994..941e9743900f6 100644 --- a/cli/internal/cache/cache.go +++ b/cli/internal/cache/cache.go @@ -33,8 +33,8 @@ type CacheEvent struct { } // New creates a new cache -func New(config *config.Config, recorder analytics.Recorder) Cache { - c := newSyncCache(config, false, recorder) +func New(config *config.Config, remoteOnly bool, recorder analytics.Recorder) Cache { + c := newSyncCache(config, remoteOnly, recorder) if config.Cache.Workers > 0 { return newAsyncCache(c, config) } diff --git a/cli/internal/run/run.go b/cli/internal/run/run.go index 199797c643f67..1e76b5acb3a35 100644 --- a/cli/internal/run/run.go +++ b/cli/internal/run/run.go @@ -154,6 +154,8 @@ Options: --dry/--dry-run[=json] List the packages in scope and the tasks that would be run, but don't actually run them. Passing --dry=json or --dry-run=json will render the output in JSON format. + --remote-only Ignore the local filesystem cache for all tasks. Only + allow reading and caching artifacts using the remote cache. `) return strings.TrimSpace(helpText) } @@ -448,6 +450,8 @@ type RunOptions struct { cacheMissLogsMode LogsMode dryRun bool dryRunJson bool + // Only use the Remote Cache and ignore the local cache + remoteOnly bool } func (ro *RunOptions) scopeOpts() *scope.Opts { @@ -478,6 +482,7 @@ func getDefaultRunOptions() *RunOptions { only: false, cacheHitLogsMode: FullLogs, cacheMissLogsMode: FullLogs, + remoteOnly: false, } } @@ -594,6 +599,8 @@ func parseRunArgs(args []string, cwd string, output cli.Ui) (*RunOptions, error) if strings.HasPrefix(arg, "--dry=json") { runOptions.dryRunJson = true } + case strings.HasPrefix(arg, "--remote-only"): + runOptions.remoteOnly = true case strings.HasPrefix(arg, "--team"): case strings.HasPrefix(arg, "--token"): case strings.HasPrefix(arg, "--api"): @@ -657,7 +664,7 @@ func (c *RunCommand) executeTasks(g *completeGraph, rs *runSpec, engine *core.Sc } analyticsClient := analytics.NewClient(goctx, analyticsSink, c.Config.Logger.Named("analytics")) defer analyticsClient.CloseWithTimeout(50 * time.Millisecond) - turboCache := cache.New(c.Config, analyticsClient) + turboCache := cache.New(c.Config, rs.Opts.remoteOnly, analyticsClient) defer turboCache.Shutdown() runState := NewRunState(rs.Opts, startAt) runState.Listen(c.Ui, time.Now()) From cc34398d7b5e41865448718350ac3c7f940b1c98 Mon Sep 17 00:00:00 2001 From: Gaspar Garcia Date: Tue, 29 Mar 2022 15:28:08 -0700 Subject: [PATCH 3/4] Revert "Implement command" This reverts commit 66aff6a7174cdf3a179b23a0c758b4bda9f20b53. --- cli/internal/cache/cache.go | 4 ++-- cli/internal/run/run.go | 9 +-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/cli/internal/cache/cache.go b/cli/internal/cache/cache.go index 941e9743900f6..e1ecb93685994 100644 --- a/cli/internal/cache/cache.go +++ b/cli/internal/cache/cache.go @@ -33,8 +33,8 @@ type CacheEvent struct { } // New creates a new cache -func New(config *config.Config, remoteOnly bool, recorder analytics.Recorder) Cache { - c := newSyncCache(config, remoteOnly, recorder) +func New(config *config.Config, recorder analytics.Recorder) Cache { + c := newSyncCache(config, false, recorder) if config.Cache.Workers > 0 { return newAsyncCache(c, config) } diff --git a/cli/internal/run/run.go b/cli/internal/run/run.go index 1e76b5acb3a35..199797c643f67 100644 --- a/cli/internal/run/run.go +++ b/cli/internal/run/run.go @@ -154,8 +154,6 @@ Options: --dry/--dry-run[=json] List the packages in scope and the tasks that would be run, but don't actually run them. Passing --dry=json or --dry-run=json will render the output in JSON format. - --remote-only Ignore the local filesystem cache for all tasks. Only - allow reading and caching artifacts using the remote cache. `) return strings.TrimSpace(helpText) } @@ -450,8 +448,6 @@ type RunOptions struct { cacheMissLogsMode LogsMode dryRun bool dryRunJson bool - // Only use the Remote Cache and ignore the local cache - remoteOnly bool } func (ro *RunOptions) scopeOpts() *scope.Opts { @@ -482,7 +478,6 @@ func getDefaultRunOptions() *RunOptions { only: false, cacheHitLogsMode: FullLogs, cacheMissLogsMode: FullLogs, - remoteOnly: false, } } @@ -599,8 +594,6 @@ func parseRunArgs(args []string, cwd string, output cli.Ui) (*RunOptions, error) if strings.HasPrefix(arg, "--dry=json") { runOptions.dryRunJson = true } - case strings.HasPrefix(arg, "--remote-only"): - runOptions.remoteOnly = true case strings.HasPrefix(arg, "--team"): case strings.HasPrefix(arg, "--token"): case strings.HasPrefix(arg, "--api"): @@ -664,7 +657,7 @@ func (c *RunCommand) executeTasks(g *completeGraph, rs *runSpec, engine *core.Sc } analyticsClient := analytics.NewClient(goctx, analyticsSink, c.Config.Logger.Named("analytics")) defer analyticsClient.CloseWithTimeout(50 * time.Millisecond) - turboCache := cache.New(c.Config, rs.Opts.remoteOnly, analyticsClient) + turboCache := cache.New(c.Config, analyticsClient) defer turboCache.Shutdown() runState := NewRunState(rs.Opts, startAt) runState.Listen(c.Ui, time.Now()) From cfd79841e9217783e06bec60a4783d641989f140 Mon Sep 17 00:00:00 2001 From: Gaspar Garcia Date: Tue, 29 Mar 2022 15:47:08 -0700 Subject: [PATCH 4/4] Add docs TURBO_REMOTE_ONLY --- docs/pages/docs/reference/command-line-reference.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/pages/docs/reference/command-line-reference.mdx b/docs/pages/docs/reference/command-line-reference.mdx index 2862f043d7388..c6aeba96d5ace 100644 --- a/docs/pages/docs/reference/command-line-reference.mdx +++ b/docs/pages/docs/reference/command-line-reference.mdx @@ -244,6 +244,8 @@ Default `false`. Ignore the local filesystem cache for all tasks. Only allow rea turbo run build --remote-only ``` +The same behavior can also be set via the `TURBO_REMOTE_ONLY=true` environment variable. + #### `--scope` `type: string[]`