Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for spring boot #239

Merged
merged 3 commits into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions deploy/platform-integration-context-spring-boot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: camel.apache.org/v1alpha1
kind: IntegrationContext
metadata:
name: spring-boot
labels:
app: "camel-k"
camel.apache.org/context.created.by.kind: Operator
camel.apache.org/context.created.by.name: jvm
camel.apache.org/context.type: platform
spec:
dependencies:
- runtime:jvm
- runtime:spring-boot
- camel:core
traits:
springboot:
configuration:
enabled: "true"
22 changes: 22 additions & 0 deletions deploy/resources.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/apis/camel/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,5 @@ const (
type Artifact struct {
ID string `json:"id" yaml:"id"`
Location string `json:"location,omitempty" yaml:"location,omitempty"`
Target string `json:"target,omitempty" yaml:"target,omitempty"`
}
11 changes: 7 additions & 4 deletions pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,20 @@ func (b *defaultBuilder) submit(request Request) {
b.request.Store(request.Meta.Name, r)

c := Context{
C: b.ctx,
Path: builderPath,
Namespace: b.namespace,
Request: request,
C: b.ctx,
Path: builderPath,
Namespace: b.namespace,
Request: request,
ComputeClasspath: true,
Image: "fabric8/s2i-java:2.3", // TODO: externalize
}

// Sort steps by phase
sort.SliceStable(request.Steps, func(i, j int) bool {
return request.Steps[i].Phase() < request.Steps[j].Phase()
})

b.log.Infof("steps: %v", request.Steps)
for _, step := range request.Steps {
if c.Error != nil {
break
Expand Down
46 changes: 26 additions & 20 deletions pkg/builder/builder_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func ComputeDependencies(ctx *Context) error {
ctx.Artifacts = append(ctx.Artifacts, v1alpha1.Artifact{
ID: e.ID,
Location: e.Location,
Target: "dependencies",
})
}

Expand All @@ -166,7 +167,7 @@ type ArtifactsSelector func([]v1alpha1.Artifact) (string, []v1alpha1.Artifact, e
// StandardPackager --
func StandardPackager(ctx *Context) error {
return packager(ctx, func(libraries []v1alpha1.Artifact) (string, []v1alpha1.Artifact, error) {
return "fabric8/s2i-java:2.3", libraries, nil
return ctx.Image, libraries, nil
})
}

Expand All @@ -191,15 +192,19 @@ func IncrementalPackager(ctx *Context) error {
}

// return default selection
return "fabric8/s2i-java:2.3", libraries, nil
return ctx.Image, libraries, nil
})
}

// ClassPathPackager --
func packager(ctx *Context, selector ArtifactsSelector) error {
imageName, selectedArtifacts, err := selector(ctx.Artifacts)
if err != nil {
return err
}
if imageName == "" {
imageName = ctx.Image
}

tarFileName := path.Join(ctx.Path, "package", "occi.tar")
tarFileDir := path.Dir(tarFileName)
Expand All @@ -215,38 +220,38 @@ func packager(ctx *Context, selector ArtifactsSelector) error {
}
defer tarAppender.Close()

tarDir := "dependencies/"
for _, entry := range selectedArtifacts {
gav, err := maven.ParseGAV(entry.ID)
if err != nil {
return err
}

tarPath := path.Join(tarDir, gav.GroupID)
_, err = tarAppender.AddFile(entry.Location, tarPath)
_, fileName := path.Split(entry.Location)

_, err = tarAppender.AddFileWithName(gav.GroupID+"."+fileName, entry.Location, entry.Target)
if err != nil {
return err
}
}

cp := ""
for _, entry := range ctx.Artifacts {
gav, err := maven.ParseGAV(entry.ID)
if err != nil {
return nil
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"
}
tarPath := path.Join(tarDir, gav.GroupID)
_, fileName := path.Split(entry.Location)
fileName = path.Join(tarPath, fileName)
cp += fileName + "\n"
}

err = tarAppender.AppendData([]byte(cp), "classpath")
if err != nil {
return err
err = tarAppender.AppendData([]byte(cp), "classpath")
lburgazzoli marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
}

ctx.Image = imageName //"fabric8/s2i-java:2.3"
ctx.Image = imageName
ctx.Archive = tarFileName

return nil
Expand Down Expand Up @@ -299,7 +304,8 @@ func FindBestImage(images []PublishedImage, entries []v1alpha1.Artifact) (*Publi
}
numCommonLibs := len(common)
surplus := len(image.Classpath) - numCommonLibs
if surplus >= numCommonLibs/3 {

if numCommonLibs != len(image.Classpath) && surplus >= numCommonLibs/3 {
// Heuristic approach: if there are too many unrelated libraries, just use the base image
continue
}
Expand Down
29 changes: 18 additions & 11 deletions pkg/builder/builder_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
)

const (
// IntiPhase --
IntiPhase int32 = 0
// ProjectGenerationPhase --
ProjectGenerationPhase int32 = 10
// ProjectBuildPhase --
Expand Down Expand Up @@ -59,7 +61,7 @@ type Step interface {
type stepWrapper struct {
id string
phase int32
task func(*Context) error
task StepTask
}

func (s *stepWrapper) String() string {
Expand All @@ -78,8 +80,11 @@ func (s *stepWrapper) Execute(ctx *Context) error {
return s.task(ctx)
}

// StepTask ---
type StepTask func(*Context) error

// NewStep --
func NewStep(ID string, phase int32, task func(*Context) error) Step {
func NewStep(ID string, phase int32, task StepTask) Step {
s := stepWrapper{
id: ID,
phase: phase,
Expand Down Expand Up @@ -123,15 +128,17 @@ type Result struct {

// Context --
type Context struct {
C context.Context
Request Request
Image string
Error error
Namespace string
Project maven.Project
Path string
Artifacts []v1alpha1.Artifact
Archive string
C context.Context
Request Request
Image string
Error error
Namespace string
Project maven.Project
Path string
Artifacts []v1alpha1.Artifact
Archive string
ComputeClasspath bool
MainClass string
}

// PublishedImage --
Expand Down
37 changes: 37 additions & 0 deletions pkg/builder/springboot/dependencies.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package springboot

import (
"strings"

"github.com/apache/camel-k/pkg/builder"
)

// ComputeDependencies --
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:") {
// Don't set a target so the jar will be copied to the
// deployment root
ctx.Artifacts[i].Target = ""
}
}

return nil
}
Loading