Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: configurable cache cleanup via env (CODER_PROVISIONER_CACHE_*)#20051

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
angrycub wants to merge2 commits intomain
base:main
Choose a base branch
Loading
fromblink/configurable-terraform-cache-cleanup
Draft
Show file tree
Hide file tree
Changes fromall 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
17 changes: 11 additions & 6 deletionsdocs/tutorials/best-practices/speed-up-templates.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -159,10 +159,15 @@ provider versions.

### Cache directory

Coder will instruct Terraform to cache its downloaded providers in the
configured [`CODER_CACHE_DIRECTORY`](../../reference/cli/server.md#--cache-dir)
directory.
Coder will instruct Terraform to cache its downloaded providers in the configured [`CODER_CACHE_DIRECTORY`](../../reference/cli/server.md#--cache-dir) directory.

Ensure that this directory is set to a location on disk which will persist
across restarts of Coder or
[external provisioners](../../admin/provisioners/index.md), if you're using them.
Ensure that this directory is set to a location on disk which will persist across restarts of Coder or [external provisioners](../../admin/provisioners/index.md), if you're using them.

#### Cache cleanup configuration

Provisioner cache cleanup can be controlled at runtime via environment variables (on both built-in and external provisioners):

- `CODER_PROVISIONER_CACHE_CLEANUP` (default `true`): enable or disable cleanup.
- `CODER_PROVISIONER_CACHE_RETENTION` (default `720h`): age threshold for considering a cached provider stale, parsed with Go's `time.ParseDuration` (example: `720h` ~30 days).

If unset, cleanup runs with a default 30-day retention.
15 changes: 11 additions & 4 deletionsprovisioner/terraform/provision.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,11 @@ import (
"github.com/coder/coder/v2/provisionersdk/proto"
)

const staleTerraformPluginRetention = 30 * 24 * time.Hour
var staleTerraformPluginRetention = 30 * 24 * time.Hour

// terraformPluginCleanupEnabled controls whether plugin cache cleanup runs.
// Defaults to true.
var terraformPluginCleanupEnabled = true

func (s *server) setupContexts(parent context.Context, canceledOrComplete <-chan struct{}) (
ctx context.Context, cancel func(), killCtx context.Context, kill func(),
Expand DownExpand Up@@ -100,9 +104,11 @@ func (s *server) Plan(
}
}

err := CleanStaleTerraformPlugins(sess.Context(), s.cachePath, afero.NewOsFs(), time.Now(), s.logger)
if err != nil {
return provisionersdk.PlanErrorf("unable to clean stale Terraform plugins: %s", err)
if terraformPluginCleanupEnabled {
err := CleanStaleTerraformPlugins(sess.Context(), s.cachePath, afero.NewOsFs(), time.Now(), s.logger)
if err != nil {
return provisionersdk.PlanErrorf("unable to clean stale Terraform plugins: %s", err)
}
}

s.logger.Debug(ctx, "running initialization")
Expand All@@ -112,6 +118,7 @@ func (s *server) Plan(
initTimings := newTimingAggregator(database.ProvisionerJobTimingStageInit)
initTimings.ingest(createInitTimingsEvent(timingInitStart))

var err error
err = e.init(ctx, killCtx, sess)
if err != nil {
initTimings.ingest(createInitTimingsEvent(timingInitErrored))
Expand Down
14 changes: 14 additions & 0 deletionsprovisioner/terraform/serve.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,10 @@ package terraform
import (
"context"
"errors"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
"time"

Expand DownExpand Up@@ -86,6 +89,17 @@ func systemBinary(ctx context.Context) (*systemBinaryDetails, error) {

// Serve starts a dRPC server on the provided transport speaking Terraform provisioner.
func Serve(ctx context.Context, options *ServeOptions) error {
// Optional environment overrides for plugin cache cleanup behavior.
if v, ok := os.LookupEnv("CODER_PROVISIONER_CACHE_CLEANUP"); ok {
if b, err := strconv.ParseBool(strings.TrimSpace(v)); err == nil {
terraformPluginCleanupEnabled = b
}
}
if v, ok := os.LookupEnv("CODER_PROVISIONER_CACHE_RETENTION"); ok {
if d, err := time.ParseDuration(strings.TrimSpace(v)); err == nil {
staleTerraformPluginRetention = d
}
}
if options.BinaryPath == "" {
binaryDetails, err := systemBinary(ctx)
if err != nil {
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp