github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/testutils/manifestbuilder/assemble.go (about)

     1  package manifestbuilder
     2  
     3  import (
     4  	"github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1"
     5  	"github.com/tilt-dev/tilt/pkg/model"
     6  )
     7  
     8  // Assemble these targets into a manifest, that deploys to k8s,
     9  // wiring up all the dependency ids so that the K8sTarget depends on all
    10  // the deployed image targets
    11  func assembleK8s(m model.Manifest, k model.K8sTarget, iTargets ...model.ImageTarget) model.Manifest {
    12  	// images on which another image depends -- we assume they are base
    13  	// images, i.e. not deployed directly, and so the deploy target
    14  	// should not depend on them.
    15  	baseImages := make(map[string]bool)
    16  	for _, iTarget := range iTargets {
    17  		for _, id := range iTarget.ImageMapDeps() {
    18  			baseImages[id] = true
    19  		}
    20  	}
    21  
    22  	imageMapNames := make([]string, 0, len(iTargets))
    23  	for _, iTarget := range iTargets {
    24  		if baseImages[iTarget.ImageMapName()] {
    25  			continue
    26  		}
    27  		imageMapNames = append(imageMapNames, iTarget.ImageMapName())
    28  	}
    29  	k = k.WithImageDependencies(model.FilterLiveUpdateOnly(imageMapNames, iTargets))
    30  	return m.
    31  		WithImageTargets(iTargets).
    32  		WithDeployTarget(k)
    33  }
    34  
    35  // Assemble these targets into a manifest, that deploys to docker compose,
    36  // wiring up all the dependency ids so that the DockerComposeTarget depends on all
    37  // the deployed image targets
    38  func assembleDC(m model.Manifest, dcTarg model.DockerComposeTarget, iTargets ...model.ImageTarget) model.Manifest {
    39  	// images on which another image depends -- we assume they are base
    40  	// images, i.e. not deployed directly, and so the deploy target
    41  	// should not depend on them.
    42  	baseImages := make(map[string]bool)
    43  	for _, iTarget := range iTargets {
    44  		for _, id := range iTarget.ImageMapDeps() {
    45  			baseImages[id] = true
    46  		}
    47  	}
    48  
    49  	imageMapNames := make([]string, 0, len(iTargets))
    50  	for _, iTarget := range iTargets {
    51  		if baseImages[iTarget.ImageMapName()] {
    52  			continue
    53  		}
    54  		imageMapNames = append(imageMapNames, iTarget.ImageMapName())
    55  	}
    56  
    57  	if len(imageMapNames) == 0 {
    58  		iTarget := model.ImageTarget{
    59  			ImageMapSpec: v1alpha1.ImageMapSpec{
    60  				Selector: dcTarg.Spec.Service,
    61  			},
    62  			BuildDetails: model.DockerComposeBuild{
    63  				Service: dcTarg.Spec.Service,
    64  			},
    65  		}
    66  		imageMapNames = append(imageMapNames, iTarget.ImageMapName())
    67  		iTargets = append(iTargets, iTarget)
    68  	}
    69  
    70  	dc := dcTarg.WithImageMapDeps(model.FilterLiveUpdateOnly(imageMapNames, iTargets))
    71  	return m.
    72  		WithImageTargets(iTargets).
    73  		WithDeployTarget(dc)
    74  }