From ecc074971aad5edf643146e864ef8ed64233905a Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Sat, 4 Nov 2023 14:55:21 +0400 Subject: [PATCH 1/3] prepare stage: introduce --no-auto-prune command-line flag --- README.md | 13 +++++++------ internal/commands/prepare/prepare.go | 10 ++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5597445..9ff1bc3 100644 --- a/README.md +++ b/README.md @@ -150,12 +150,13 @@ that required paid sponsorship upon exceeding a free limit. ### `prepare` stage -| Argument | Default | Description | -|-----------------|-------------|--------------------------------------------------------------------------------------| -| `--concurrency` | 1 | Maximum number of concurrently running Tart VMs to calculate the `auto` resources | -| `--cpu` | no override | Override default image CPU configuration (number of CPUs or `auto`1) | -| `--memory` | no override | Override default image memory configuration (size in megabytes or `auto`1) | -| `--dir` | | `--dir` arguments to pass to `tart run`, can be specified multiple times | +| Argument | Default | Description | +|-------------------|-------------|----------------------------------------------------------------------------------------------------------------------| +| `--concurrency` | 1 | Maximum number of concurrently running Tart VMs to calculate the `auto` resources | +| `--cpu` | no override | Override default image CPU configuration (number of CPUs or `auto`1) | +| `--memory` | no override | Override default image memory configuration (size in megabytes or `auto`1) | +| `--dir` | | `--dir` arguments to pass to `tart run`, can be specified multiple times | +| `--no-auto-prune` | false | set `TART_NO_AUTO_PRUNE=true` environment variable for Tart invocations to disable the Tart's auto-pruning mechanism | 1: automatically distributes all host resources according to the concurrency level (for example, VM gets all of the host CPU and RAM assigned when `--concurrency` is 1, and half of that when `--concurrency` is 2) diff --git a/internal/commands/prepare/prepare.go b/internal/commands/prepare/prepare.go index 537cec6..b472e4e 100644 --- a/internal/commands/prepare/prepare.go +++ b/internal/commands/prepare/prepare.go @@ -24,6 +24,7 @@ var concurrency uint64 var cpuOverrideRaw string var memoryOverrideRaw string var customDirectoryMounts []string +var noAutoPrune bool func NewCommand() *cobra.Command { command := &cobra.Command{ @@ -40,6 +41,9 @@ func NewCommand() *cobra.Command { "Override default image memory configuration (size in megabytes or \"auto\")") command.PersistentFlags().StringArrayVar(&customDirectoryMounts, "dir", []string{}, "\"--dir\" arguments to pass to \"tart run\", can be specified multiple times") + command.PersistentFlags().BoolVar(&noAutoPrune, "no-auto-prune", false, + "set \"TART_NO_AUTO_PRUNE=true\" environment variable for Tart invocations"+ + "to disable the Tart's auto-pruning mechanism") return command } @@ -55,6 +59,12 @@ func runPrepareVM(cmd *cobra.Command, args []string) error { return err } + if noAutoPrune { + if err := os.Setenv("TART_NO_AUTO_PRUNE", "true"); err != nil { + return err + } + } + gitLabEnv, err := gitlab.InitEnv() if err != nil { return err From bebf869f7a9e41ea61bc094a425207977a5890af Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Mon, 6 Nov 2023 20:39:52 +0400 Subject: [PATCH 2/3] =?UTF-8?q?--no-auto-prune=20=E2=86=92=20--auto-prune?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/commands/prepare/prepare.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/commands/prepare/prepare.go b/internal/commands/prepare/prepare.go index b472e4e..5769266 100644 --- a/internal/commands/prepare/prepare.go +++ b/internal/commands/prepare/prepare.go @@ -24,7 +24,7 @@ var concurrency uint64 var cpuOverrideRaw string var memoryOverrideRaw string var customDirectoryMounts []string -var noAutoPrune bool +var autoPrune bool func NewCommand() *cobra.Command { command := &cobra.Command{ @@ -41,9 +41,9 @@ func NewCommand() *cobra.Command { "Override default image memory configuration (size in megabytes or \"auto\")") command.PersistentFlags().StringArrayVar(&customDirectoryMounts, "dir", []string{}, "\"--dir\" arguments to pass to \"tart run\", can be specified multiple times") - command.PersistentFlags().BoolVar(&noAutoPrune, "no-auto-prune", false, - "set \"TART_NO_AUTO_PRUNE=true\" environment variable for Tart invocations"+ - "to disable the Tart's auto-pruning mechanism") + command.PersistentFlags().BoolVar(&autoPrune, "auto-prune", true, + "Whether to enable or disable the Tart's auto-pruning mechanism (sets the "+ + "TART_NO_AUTO_PRUNE environment variable for Tart command invocations under the hood)") return command } @@ -59,7 +59,9 @@ func runPrepareVM(cmd *cobra.Command, args []string) error { return err } - if noAutoPrune { + // Auto-prune is enabled by default in Tart, + // so we only need to act when it's set to "false" + if !autoPrune { if err := os.Setenv("TART_NO_AUTO_PRUNE", "true"); err != nil { return err } From b47bb5aca5739e94c134ff43cf523b5e5bab3c06 Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Mon, 6 Nov 2023 20:41:31 +0400 Subject: [PATCH 3/3] Fix documentation --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9ff1bc3..fe2f249 100644 --- a/README.md +++ b/README.md @@ -150,13 +150,13 @@ that required paid sponsorship upon exceeding a free limit. ### `prepare` stage -| Argument | Default | Description | -|-------------------|-------------|----------------------------------------------------------------------------------------------------------------------| -| `--concurrency` | 1 | Maximum number of concurrently running Tart VMs to calculate the `auto` resources | -| `--cpu` | no override | Override default image CPU configuration (number of CPUs or `auto`1) | -| `--memory` | no override | Override default image memory configuration (size in megabytes or `auto`1) | -| `--dir` | | `--dir` arguments to pass to `tart run`, can be specified multiple times | -| `--no-auto-prune` | false | set `TART_NO_AUTO_PRUNE=true` environment variable for Tart invocations to disable the Tart's auto-pruning mechanism | +| Argument | Default | Description | +|------------------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `--concurrency` | 1 | Maximum number of concurrently running Tart VMs to calculate the `auto` resources | +| `--cpu` | no override | Override default image CPU configuration (number of CPUs or `auto`1) | +| `--memory` | no override | Override default image memory configuration (size in megabytes or `auto`1) | +| `--dir` | | `--dir` arguments to pass to `tart run`, can be specified multiple times | +| `--auto-prune` | true | Whether to enable or disable the Tart's auto-pruning mechanism (sets the `TART_NO_AUTO_PRUNE` environment variable for Tart command invocations under the hood) | 1: automatically distributes all host resources according to the concurrency level (for example, VM gets all of the host CPU and RAM assigned when `--concurrency` is 1, and half of that when `--concurrency` is 2)