This is an automated email from the ASF dual-hosted git repository. astefanutti pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit b456c988c42f1dbdac5724227719961a98413039 Author: Antonin Stefanutti <[email protected]> AuthorDate: Thu Aug 19 13:32:26 2021 +0200 feat(native): Support native build with Spectrum strategy --- pkg/builder/spectrum.go | 21 +++++++++++++-------- pkg/trait/quarkus.go | 12 ++++++++++-- pkg/util/util.go | 14 ++++++++++++++ 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/pkg/builder/spectrum.go b/pkg/builder/spectrum.go index cb2134a..b719222 100644 --- a/pkg/builder/spectrum.go +++ b/pkg/builder/spectrum.go @@ -32,6 +32,7 @@ import ( v1 "github.com/apache/camel-k/pkg/apis/camel/v1" "github.com/apache/camel-k/pkg/client" + "github.com/apache/camel-k/pkg/util" "github.com/apache/camel-k/pkg/util/log" ) @@ -65,16 +66,20 @@ func (t *spectrumTask) Do(ctx context.Context) v1.BuildStatus { contextDir = path.Join(pwd, ContextDir) } - libraryPath := path.Join(contextDir, DependenciesDir) - _, err := os.Stat(libraryPath) - if err != nil && os.IsNotExist(err) { - // this can only indicate that there are no more libraries to add to the base image, - // because transitive resolution is the same even if spec differs + 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. log.Infof("No new image to build, reusing existing image %s", baseImage) status.Image = baseImage return status - } else if err != nil { - return status.Failed(err) } pullInsecure := t.task.Registry.Insecure // incremental build case @@ -120,7 +125,7 @@ func (t *spectrumTask) Do(ctx context.Context) v1.BuildStatus { } go readSpectrumLogs(newStdR) - digest, err := spectrum.Build(options, libraryPath+":"+path.Join(DeploymentDir, DependenciesDir)) + digest, err := spectrum.Build(options, contextDir+":"+path.Join(DeploymentDir)) if err != nil { return status.Failed(err) diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go index d77b614..bb38039 100644 --- a/pkg/trait/quarkus.go +++ b/pkg/trait/quarkus.go @@ -96,10 +96,18 @@ func (t *quarkusTrait) Apply(e *Environment) error { if t.isNativePackageType() { build.Maven.Properties["quarkus.package.type"] = string(nativePackageType) - steps = append(steps, builder.Image.NativeImageContext, builder.Image.ExecutableDockerfile) + steps = append(steps, builder.Image.NativeImageContext) + // Spectrum does not rely on Dockerfile to assemble the image + if e.Platform.Status.Build.PublishStrategy != v1.IntegrationPlatformBuildPublishStrategySpectrum { + steps = append(steps, builder.Image.ExecutableDockerfile) + } } else { build.Maven.Properties["quarkus.package.type"] = string(fastJarPackageType) - steps = append(steps, builder.Quarkus.ComputeQuarkusDependencies, builder.Image.IncrementalImageContext, builder.Image.JvmDockerfile) + steps = append(steps, builder.Quarkus.ComputeQuarkusDependencies, builder.Image.IncrementalImageContext) + // Spectrum does not rely on Dockerfile to assemble the image + if e.Platform.Status.Build.PublishStrategy != v1.IntegrationPlatformBuildPublishStrategySpectrum { + steps = append(steps, builder.Image.JvmDockerfile) + } } // Sort steps by phase diff --git a/pkg/util/util.go b/pkg/util/util.go index 8e61e97..40e559f 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -289,6 +289,20 @@ func DirectoryExists(directory string) (bool, error) { return info.IsDir(), nil } +func DirectoryEmpty(directory string) (bool, error) { + f, err := os.Open(directory) + if err != nil { + return false, err + } + defer f.Close() + + _, err = f.Readdirnames(1) + if err == io.EOF { + return true, nil + } + return false, err +} + func CreateDirectory(directory string) error { if directory != "" { // If directory does not exist, create it
