in pkg/builder/spectrum.go [46:142]
func (t *spectrumTask) Do(ctx context.Context) v1.BuildStatus {
status := initializeStatusFrom(t.build.Status, t.task.BaseImage)
contextDir := t.task.ContextDir
if contextDir == "" {
// Use the working directory.
// This is useful when the task is executed in-container,
// so that its WorkingDir can be used to share state and
// coordinate with other tasks.
pwd, err := os.Getwd()
if err != nil {
return status.Failed(err)
}
contextDir = filepath.Join(pwd, ContextDir)
}
log.Infof("Running spectrum task in context directory: %s", contextDir)
exists, err := util.DirectoryExists(contextDir)
if err != nil {
return status.Failed(err)
}
empty, err := util.DirectoryEmpty(contextDir)
if err != nil {
return status.Failed(err)
}
if !exists || empty {
// this can only indicate that there are no more resources to add to the base image,
// because transitive resolution is the same even if spec differs.
status.Image = status.BaseImage
log.Infof("No new image to build, reusing existing image %s", status.Image)
return *status
}
pullInsecure := t.task.Registry.Insecure // incremental build case
log.Debugf("Registry address: %s", t.task.Registry.Address)
log.Debugf("Base image: %s", status.BaseImage)
if !strings.HasPrefix(status.BaseImage, t.task.Registry.Address) {
if pullInsecure {
log.Info("Assuming secure pull because the registry for the base image and the main registry are different")
pullInsecure = false
}
}
registryConfigDir := ""
if t.task.Registry.Secret != "" {
registryConfigDir, err = registry.MountSecretRegistryConfig(ctx, t.c, t.build.Namespace, "spectrum-secret-", t.task.Registry.Secret)
if err != nil {
return status.Failed(err)
}
}
newStdR, newStdW, pipeErr := os.Pipe()
defer util.CloseQuietly(newStdW)
if pipeErr != nil {
// In the unlikely case of an error, use stdout instead of aborting
log.Errorf(pipeErr, "Unable to remap I/O. Spectrum messages will be displayed on the stdout")
newStdW = os.Stdout
}
options := spectrum.Options{
PullInsecure: pullInsecure,
PushInsecure: t.task.Registry.Insecure,
PullConfigDir: registryConfigDir,
PushConfigDir: registryConfigDir,
Base: status.BaseImage,
Target: t.task.Image,
Stdout: newStdW,
Stderr: newStdW,
Recursive: true,
}
if jobs := runtime.GOMAXPROCS(0); jobs > 1 {
options.Jobs = jobs
}
go readSpectrumLogs(newStdR)
digest, err := spectrum.Build(options, contextDir+":"+filepath.Join(DeploymentDir)) //nolint
if err != nil {
_ = os.RemoveAll(registryConfigDir)
return status.Failed(err)
}
status.Image = t.task.Image
status.Digest = digest
if registryConfigDir != "" {
if err := os.RemoveAll(registryConfigDir); err != nil {
return status.Failed(err)
}
}
return *status
}