This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/master by this push:
new ce8c088 runtime(springboot): set the exact list of dependencies used
by spring boot instead of use everithing in the dependencies folder
ce8c088 is described below
commit ce8c088127dc001ad4e5cff20c7b5c0cbbb0fa27
Author: lburgazzoli <[email protected]>
AuthorDate: Mon Dec 3 14:02:15 2018 +0100
runtime(springboot): set the exact list of dependencies used by spring boot
instead of use everithing in the dependencies folder
---
pkg/apis/camel/v1alpha1/types.go | 2 +-
pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go | 6 ++--
pkg/builder/builder.go | 8 +++--
pkg/builder/builder_steps.go | 38 +++++++++++-------------
pkg/builder/builder_types.go | 4 +--
pkg/builder/springboot/dependencies.go | 12 +++++++-
pkg/stub/action/context/build.go | 11 ++++++-
pkg/trait/springboot.go | 26 ++++++++++++++++
pkg/util/tar/appender.go | 2 +-
9 files changed, 77 insertions(+), 32 deletions(-)
diff --git a/pkg/apis/camel/v1alpha1/types.go b/pkg/apis/camel/v1alpha1/types.go
index 901c001..5626fef 100644
--- a/pkg/apis/camel/v1alpha1/types.go
+++ b/pkg/apis/camel/v1alpha1/types.go
@@ -171,7 +171,7 @@ type IntegrationContextStatus struct {
Phase IntegrationContextPhase `json:"phase,omitempty"`
Image string `json:"image,omitempty"`
Digest string `json:"digest,omitempty"`
- Classpath []string `json:"classpath,omitempty"`
+ Artifacts []Artifact `json:"artifacts,omitempty"`
}
// IntegrationContextPhase --
diff --git a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
index 9ae3d88..3086ad8 100644
--- a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
@@ -187,9 +187,9 @@ func (in *IntegrationContextSpec) DeepCopy()
*IntegrationContextSpec {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver,
writing into out. in must be non-nil.
func (in *IntegrationContextStatus) DeepCopyInto(out
*IntegrationContextStatus) {
*out = *in
- if in.Classpath != nil {
- in, out := &in.Classpath, &out.Classpath
- *out = make([]string, len(*in))
+ if in.Artifacts != nil {
+ in, out := &in.Artifacts, &out.Artifacts
+ *out = make([]Artifact, len(*in))
copy(*out, *in)
}
return
diff --git a/pkg/builder/builder.go b/pkg/builder/builder.go
index a04f3d8..163df7f 100644
--- a/pkg/builder/builder.go
+++ b/pkg/builder/builder.go
@@ -27,6 +27,8 @@ import (
"sync/atomic"
"time"
+ "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+
"github.com/sirupsen/logrus"
)
@@ -192,9 +194,9 @@ func (b *defaultBuilder) submit(request Request) {
r.Status = StatusError
}
- r.Classpath = make([]string, 0, len(c.Artifacts))
- for _, l := range c.Artifacts {
- r.Classpath = append(r.Classpath, l.ID)
+ r.Artifacts = make([]v1alpha1.Artifact, 0, len(c.Artifacts))
+ for _, artifact := range c.Artifacts {
+ r.Artifacts = append(r.Artifacts, artifact)
}
// update the cache
diff --git a/pkg/builder/builder_steps.go b/pkg/builder/builder_steps.go
index 01af0dd..09530c0 100644
--- a/pkg/builder/builder_steps.go
+++ b/pkg/builder/builder_steps.go
@@ -152,10 +152,17 @@ func ComputeDependencies(ctx *Context) error {
}
for _, e := range cp["dependencies"] {
+ _, fileName := path.Split(e.Location)
+
+ gav, err := maven.ParseGAV(e.ID)
+ if err != nil {
+ return nil
+ }
+
ctx.Artifacts = append(ctx.Artifacts, v1alpha1.Artifact{
ID: e.ID,
Location: e.Location,
- Target: "dependencies",
+ Target: path.Join("dependencies",
gav.GroupID+"."+fileName),
})
}
@@ -222,14 +229,10 @@ func packager(ctx *Context, selector ArtifactsSelector)
error {
defer tarAppender.Close()
for _, entry := range selectedArtifacts {
- gav, err := maven.ParseGAV(entry.ID)
- if err != nil {
- return err
- }
+ _, tarFileName := path.Split(entry.Target)
+ tarFilePath := path.Dir(entry.Target)
- _, fileName := path.Split(entry.Location)
-
- _, err = tarAppender.AddFileWithName(gav.GroupID+"."+fileName,
entry.Location, entry.Target)
+ _, err = tarAppender.AddFileWithName(tarFileName,
entry.Location, tarFilePath)
if err != nil {
return err
}
@@ -238,12 +241,7 @@ func packager(ctx *Context, selector ArtifactsSelector)
error {
if ctx.ComputeClasspath {
cp := ""
for _, entry := range ctx.Artifacts {
- gav, err := maven.ParseGAV(entry.ID)
- if err != nil {
- return nil
- }
- _, fileName := path.Split(entry.Location)
- cp += path.Join(entry.Target, gav.GroupID+"."+fileName)
+ "\n"
+ cp += path.Join(entry.Target) + "\n"
}
err = tarAppender.AppendData([]byte(cp), "classpath")
@@ -277,7 +275,7 @@ func ListPublishedImages(namespace string)
([]PublishedImage, error) {
images = append(images, PublishedImage{
Image: ctx.Status.Image,
- Classpath: ctx.Status.Classpath,
+ Artifacts: ctx.Status.Artifacts,
})
}
return images, nil
@@ -298,15 +296,15 @@ func FindBestImage(images []PublishedImage, entries
[]v1alpha1.Artifact) (*Publi
bestImageSurplusLibs := 0
for _, image := range images {
common := make(map[string]bool)
- for _, id := range image.Classpath {
- if _, ok := requiredLibs[id]; ok {
- common[id] = true
+ for _, artifact := range image.Artifacts {
+ if _, ok := requiredLibs[artifact.ID]; ok {
+ common[artifact.ID] = true
}
}
numCommonLibs := len(common)
- surplus := len(image.Classpath) - numCommonLibs
+ surplus := len(image.Artifacts) - numCommonLibs
- if numCommonLibs != len(image.Classpath) && surplus >=
numCommonLibs/3 {
+ if numCommonLibs != len(image.Artifacts) && surplus >=
numCommonLibs/3 {
// Heuristic approach: if there are too many unrelated
libraries, just use the base image
continue
}
diff --git a/pkg/builder/builder_types.go b/pkg/builder/builder_types.go
index a81f879..1f970f0 100644
--- a/pkg/builder/builder_types.go
+++ b/pkg/builder/builder_types.go
@@ -122,7 +122,7 @@ type Result struct {
Image string
Error error
Status Status
- Classpath []string
+ Artifacts []v1alpha1.Artifact
Task Task
}
@@ -144,7 +144,7 @@ type Context struct {
// PublishedImage --
type PublishedImage struct {
Image string
- Classpath []string
+ Artifacts []v1alpha1.Artifact
}
// Status --
diff --git a/pkg/builder/springboot/dependencies.go
b/pkg/builder/springboot/dependencies.go
index 6c3aec1..e7f7e9e 100644
--- a/pkg/builder/springboot/dependencies.go
+++ b/pkg/builder/springboot/dependencies.go
@@ -18,8 +18,11 @@ limitations under the License.
package springboot
import (
+ "path"
"strings"
+ "github.com/apache/camel-k/pkg/util/maven"
+
"github.com/apache/camel-k/pkg/builder"
)
@@ -27,9 +30,16 @@ import (
func ComputeDependencies(ctx *builder.Context) error {
for i := 0; i < len(ctx.Artifacts); i++ {
if strings.HasPrefix(ctx.Artifacts[i].ID,
"org.apache.camel.k:camel-k-runtime-spring-boot:") {
+
+ _, fileName := path.Split(ctx.Artifacts[i].Location)
+ gav, err := maven.ParseGAV(ctx.Artifacts[i].ID)
+ if err != nil {
+ return nil
+ }
+
// Don't set a target so the jar will be copied to the
// deployment root
- ctx.Artifacts[i].Target = ""
+ ctx.Artifacts[i].Target = gav.GroupID + "." + fileName
}
}
diff --git a/pkg/stub/action/context/build.go b/pkg/stub/action/context/build.go
index 4734bbc..8f7a9bf 100644
--- a/pkg/stub/action/context/build.go
+++ b/pkg/stub/action/context/build.go
@@ -88,7 +88,16 @@ func (action *buildAction) Handle(context
*v1alpha1.IntegrationContext) error {
target := context.DeepCopy()
target.Status.Image = res.Image
target.Status.Phase = v1alpha1.IntegrationContextPhaseReady
- target.Status.Classpath = res.Classpath
+ target.Status.Artifacts = make([]v1alpha1.Artifact, 0,
len(res.Artifacts))
+
+ for _, a := range res.Artifacts {
+ // do not include artifact location
+ target.Status.Artifacts =
append(target.Status.Artifacts, v1alpha1.Artifact{
+ ID: a.ID,
+ Location: "",
+ Target: a.Target,
+ })
+ }
logrus.Info("Context ", target.Name, " transitioning to state
", v1alpha1.IntegrationContextPhaseReady)
diff --git a/pkg/trait/springboot.go b/pkg/trait/springboot.go
index 7069d67..1314bfb 100644
--- a/pkg/trait/springboot.go
+++ b/pkg/trait/springboot.go
@@ -19,6 +19,10 @@ package trait
import (
"sort"
+ "strings"
+
+ "github.com/operator-framework/operator-sdk/pkg/sdk"
+ "github.com/pkg/errors"
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/builder"
@@ -80,6 +84,28 @@ func (trait *springBootTrait) apply(e *Environment) error {
// Override env vars
e.EnvVars["JAVA_MAIN_CLASS"] =
"org.springframework.boot.loader.PropertiesLauncher"
e.EnvVars["LOADER_PATH"] = "/deployments/dependencies/"
+
+ if e.Integration.Spec.Context != "" {
+ name := e.Integration.Spec.Context
+ ctx :=
v1alpha1.NewIntegrationContext(e.Integration.Namespace, name)
+
+ if err := sdk.Get(&ctx); err != nil {
+ return errors.Wrapf(err, "unable to find
integration context %s, %s", ctx.Name, err)
+ }
+
+ deps := make([]string, 0, len(ctx.Status.Artifacts))
+ for _, artifact := range ctx.Status.Artifacts {
+ if strings.HasPrefix(artifact.ID,
"org.apache.camel.k:camel-k-runtime-spring-boot:") {
+ // do not include runner jar
+ continue
+ }
+
+ deps = append(deps, artifact.Target)
+ }
+
+ e.EnvVars["LOADER_HOME"] = "/deployments"
+ e.EnvVars["LOADER_PATH"] = strings.Join(deps, ",")
+ }
}
//
diff --git a/pkg/util/tar/appender.go b/pkg/util/tar/appender.go
index 7ffbfad..f4fbecb 100644
--- a/pkg/util/tar/appender.go
+++ b/pkg/util/tar/appender.go
@@ -92,7 +92,7 @@ func (t *Appender) AddFile(filePath string, tarDir string)
(string, error) {
return fileName, nil
}
-// AddFileWithName adds a file content to the tarDir, using the fiven file
name.
+// AddFileWithName adds a file content to the tarDir, using the given file
name.
// It returns the full path of the file inside the tar.
func (t *Appender) AddFileWithName(fileName string, filePath string, tarDir
string) (string, error) {
info, err := os.Stat(filePath)