MCPcopy Create free account
hub / github.com/coder/envbuilder / RunCacheProbe

Function RunCacheProbe

envbuilder.go:979–1348  ·  view source on GitHub ↗

RunCacheProbe performs a 'dry-run' build of the image and checks that all of the resulting layers are present in options.CacheRepo.

(ctx context.Context, opts options.Options)

Source from the content-addressed store, hash-verified

977// RunCacheProbe performs a 'dry-run' build of the image and checks that
978// all of the resulting layers are present in options.CacheRepo.
979func RunCacheProbe(ctx context.Context, opts options.Options) (v1.Image, error) {
980 defer options.UnsetEnv()
981 if !opts.GetCachedImage {
982 return nil, fmt.Errorf("developer error: RunCacheProbe must be run with --get-cached-image")
983 }
984 if opts.CacheRepo == "" {
985 return nil, fmt.Errorf("--cache-repo must be set when using --get-cached-image")
986 }
987
988 workingDir := workingdir.At(opts.WorkingDirBase)
989
990 stageNumber := 0
991 startStage := func(format string, args ...any) func(format string, args ...any) {
992 now := time.Now()
993 stageNumber++
994 stageNum := stageNumber
995 opts.Logger(log.LevelInfo, "#%d: %s", stageNum, fmt.Sprintf(format, args...))
996
997 return func(format string, args ...any) {
998 opts.Logger(log.LevelInfo, "#%d: %s [%s]", stageNum, fmt.Sprintf(format, args...), time.Since(now))
999 }
1000 }
1001
1002 opts.Logger(log.LevelInfo, "%s %s - Build development environments from repositories in a container", newColor(color.Bold).Sprintf("envbuilder"), buildinfo.Version())
1003
1004 cleanupDockerConfigOverride, err := initDockerConfigOverride(opts.Filesystem, opts.Logger, workingDir, opts.DockerConfigBase64)
1005 if err != nil {
1006 return nil, err
1007 }
1008 defer func() {
1009 if err := cleanupDockerConfigOverride(); err != nil {
1010 opts.Logger(log.LevelError, "failed to cleanup docker config override: %w", err)
1011 }
1012 }() // best effort
1013
1014 buildTimeWorkspaceFolder := opts.WorkspaceFolder
1015 var fallbackErr error
1016 var cloned bool
1017 if opts.GitURL != "" {
1018 endStage := startStage("📦 Cloning %s to %s...",
1019 newColor(color.FgCyan).Sprint(opts.GitURL),
1020 newColor(color.FgCyan).Sprint(opts.WorkspaceFolder),
1021 )
1022 stageNum := stageNumber
1023 logStage := func(format string, args ...any) {
1024 opts.Logger(log.LevelInfo, "#%d: %s", stageNum, fmt.Sprintf(format, args...))
1025 }
1026
1027 // In cache probe mode we should only attempt to clone the full
1028 // repository if remote repo build mode isn't enabled.
1029 if !opts.RemoteRepoBuildMode {
1030 cloneOpts, err := git.CloneOptionsFromOptions(logStage, opts)
1031 if err != nil {
1032 return nil, fmt.Errorf("git clone options: %w", err)
1033 }
1034
1035 w := git.ProgressWriter(logStage)
1036 defer w.Close()

Callers 1

envbuilderCmdFunction · 0.92

Calls 15

UnsetEnvFunction · 0.92
AtFunction · 0.92
VersionFunction · 0.92
CloneOptionsFromOptionsFunction · 0.92
ProgressWriterFunction · 0.92
CloneRepoFunction · 0.92
ShallowCloneRepoFunction · 0.92
ParseFunction · 0.92
HijackLogrusFunction · 0.92
FromLogrusFunction · 0.92
WriterFunction · 0.92
newColorFunction · 0.85

Tested by

no test coverage detected