Skip to content
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

improve provider lock speed by using cache #34632

Merged
merged 6 commits into from
Feb 9, 2024
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
77 changes: 45 additions & 32 deletions internal/command/providers_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ func (c *ProvidersLockCommand) Run(args []string) int {
var optPlatforms FlagStringSlice
var fsMirrorDir string
var netMirrorURL string

cmdFlags.Var(&optPlatforms, "platform", "target platform")
cmdFlags.StringVar(&fsMirrorDir, "fs-mirror", "", "filesystem mirror directory")
cmdFlags.StringVar(&netMirrorURL, "net-mirror", "", "network mirror base URL")
pluginCache := cmdFlags.Bool("enable-plugin-cache", false, "")
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
if err := cmdFlags.Parse(args); err != nil {
c.Ui.Error(fmt.Sprintf("Error parsing command-line flags: %s\n", err.Error()))
Expand Down Expand Up @@ -246,6 +248,13 @@ func (c *ProvidersLockCommand) Run(args []string) int {
dir := providercache.NewDirWithPlatform(tempDir, platform)
installer := providercache.NewInstaller(dir, source)

// Use global plugin cache for extra speed if present and flag is set
globalCacheDir := c.providerGlobalCacheDir()
DanielMSchmidt marked this conversation as resolved.
Show resolved Hide resolved
if *pluginCache && globalCacheDir != nil {
installer.SetGlobalCacheDir(globalCacheDir.WithPlatform(platform))
installer.SetGlobalCacheDirMayBreakDependencyLockFile(c.PluginCacheMayBreakDependencyLockFile)
}

newLocks, err := installer.EnsureProviderVersions(ctx, oldLocks, reqs, providercache.InstallNewProvidersForce)
if err != nil {
diags = diags.Append(tfdiags.Sourceless(
Expand Down Expand Up @@ -370,38 +379,42 @@ Usage: terraform [global options] providers lock [options] [providers...]

Options:

-fs-mirror=dir Consult the given filesystem mirror directory instead
of the origin registry for each of the given providers.

This would be necessary to generate lock file entries for
a provider that is available only via a mirror, and not
published in an upstream registry. In this case, the set
of valid checksums will be limited only to what Terraform
can learn from the data in the mirror directory.

-net-mirror=url Consult the given network mirror (given as a base URL)
instead of the origin registry for each of the given
providers.

This would be necessary to generate lock file entries for
a provider that is available only via a mirror, and not
published in an upstream registry. In this case, the set
of valid checksums will be limited only to what Terraform
can learn from the data in the mirror indices.

-platform=os_arch Choose a target platform to request package checksums
for.

By default Terraform will request package checksums
suitable only for the platform where you run this
command. Use this option multiple times to include
checksums for multiple target systems.

Target names consist of an operating system and a CPU
architecture. For example, "linux_amd64" selects the
Linux operating system running on an AMD64 or x86_64
CPU. Each provider is available only for a limited
set of target platforms.
-fs-mirror=dir Consult the given filesystem mirror directory instead
of the origin registry for each of the given providers.

This would be necessary to generate lock file entries for
a provider that is available only via a mirror, and not
published in an upstream registry. In this case, the set
of valid checksums will be limited only to what Terraform
can learn from the data in the mirror directory.

-net-mirror=url Consult the given network mirror (given as a base URL)
instead of the origin registry for each of the given
providers.

This would be necessary to generate lock file entries for
a provider that is available only via a mirror, and not
published in an upstream registry. In this case, the set
of valid checksums will be limited only to what Terraform
can learn from the data in the mirror indices.

-platform=os_arch Choose a target platform to request package checksums
for.

By default Terraform will request package checksums
suitable only for the platform where you run this
command. Use this option multiple times to include
checksums for multiple target systems.

Target names consist of an operating system and a CPU
architecture. For example, "linux_amd64" selects the
Linux operating system running on an AMD64 or x86_64
CPU. Each provider is available only for a limited
set of target platforms.

-enable-plugin-cache Enable the usage of the globally configured plugin cache.
This will speed up the locking process, but the providers
wont be loaded from an authoritative source.
`
}

Expand Down
6 changes: 6 additions & 0 deletions internal/providercache/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ func (d *Dir) BasePath() string {
return filepath.Clean(d.baseDir)
}

// WithPlatform creates a new dir with the provided platform based
// on this dir
func (d *Dir) WithPlatform(platform getproviders.Platform) *Dir {
return NewDirWithPlatform(d.baseDir, platform)
}

// AllAvailablePackages returns a description of all of the packages already
// present in the directory. The cache entries are grouped by the provider
// they relate to and then sorted by version precedence, with highest
Expand Down
Loading