Skip to content

Commit

Permalink
builder: wake up event loop when the container image buils is done to…
Browse files Browse the repository at this point in the history
… seep up deployment time
  • Loading branch information
lburgazzoli authored and nicolaferraro committed Dec 7, 2018
1 parent 12adcf0 commit 8fed404
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
42 changes: 37 additions & 5 deletions pkg/builder/builder_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ func FindBestImage(images []PublishedImage, dependencies []string, artifacts []v
return bestImage, bestImageCommonLibs
}

// Notify --
func Notify(ctx *Context) error {
c := v1alpha1.IntegrationContext{
// NotifyIntegrationContext --
func NotifyIntegrationContext(ctx *Context) error {
target := v1alpha1.IntegrationContext{
TypeMeta: metav1.TypeMeta{
Kind: v1alpha1.IntegrationContextKind,
APIVersion: v1alpha1.SchemeGroupVersion.String(),
Expand All @@ -377,11 +377,43 @@ func Notify(ctx *Context) error {
},
}

if err := sdk.Get(&c); err != nil {
if err := sdk.Get(&target); err != nil {
return err
}

t := c.DeepCopy()
t := target.DeepCopy()
if t.Annotations == nil {
t.Annotations = make(map[string]string)
}

// Add a random ID to trigger update
t.Annotations["camel.apache.org/build.id"] = xid.New().String()

if err := sdk.Update(t); err != nil {
return err
}

return nil
}

// NotifyIntegration --
func NotifyIntegration(ctx *Context) error {
target := v1alpha1.Integration{
TypeMeta: metav1.TypeMeta{
Kind: v1alpha1.IntegrationKind,
APIVersion: v1alpha1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: ctx.Namespace,
Name: ctx.Request.Meta.Name,
},
}

if err := sdk.Get(&target); err != nil {
return err
}

t := target.DeepCopy()
if t.Annotations == nil {
t.Annotations = make(map[string]string)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/builder/kaniko/kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var DefaultSteps = []builder.Step{
builder.NewStep("build/compute-dependencies", builder.ProjectBuildPhase, builder.ComputeDependencies),
builder.NewStep("packager", builder.ApplicationPackagePhase, builder.StandardPackager),
builder.NewStep("publisher/kaniko", builder.ApplicationPublishPhase, Publisher),
builder.NewStep("notify", builder.NotifyPhase, builder.Notify),
builder.NewStep("notify/context", builder.NotifyPhase, builder.NotifyIntegrationContext),
}

// BuildDir is the directory where to build artifacts (shared with the Kaniko pod)
Expand Down
2 changes: 1 addition & 1 deletion pkg/builder/s2i/s2i.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ var DefaultSteps = []builder.Step{
builder.NewStep("build/compute-dependencies", builder.ProjectBuildPhase, builder.ComputeDependencies),
builder.NewStep("packager/incremental", builder.ApplicationPackagePhase, builder.IncrementalPackager),
builder.NewStep("publisher/s2i", builder.ApplicationPublishPhase, Publisher),
builder.NewStep("notify", builder.NotifyPhase, builder.Notify),
builder.NewStep("notify/context", builder.NotifyPhase, builder.NotifyIntegrationContext),
}
2 changes: 1 addition & 1 deletion pkg/stub/action/context/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (action *buildAction) Handle(context *v1alpha1.IntegrationContext) error {
target := context.DeepCopy()
target.Status.Phase = v1alpha1.IntegrationContextPhaseError

logrus.Info("Context ", target.Name, " transitioning to state ", target.Status.Phase)
logrus.Infof("Context %s transitioning to state %s, reason: %s", target.Name, target.Status.Phase, res.Error.Error())

// remove the build from cache
defer b.Purge(r)
Expand Down
2 changes: 1 addition & 1 deletion pkg/stub/action/integration/build_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (action *buildImageAction) Handle(integration *v1alpha1.Integration) error
target := integration.DeepCopy()
target.Status.Phase = v1alpha1.IntegrationPhaseError

logrus.Info("Integration ", target.Name, " transitioning to state ", target.Status.Phase)
logrus.Infof("Integration %s transitioning to state %s, reason: %s", target.Name, target.Status.Phase, res.Error.Error())

// remove the build from cache
defer b.Purge(r)
Expand Down
2 changes: 2 additions & 0 deletions pkg/trait/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ func (*builderTrait) apply(e *Environment) error {
e.Steps = []builder.Step{
builder.NewStep("packager", builder.ApplicationPackagePhase, builder.StandardPackager),
builder.NewStep("publisher/s2i", builder.ApplicationPublishPhase, s2i.Publisher),
builder.NewStep("notify/integration", builder.NotifyPhase, builder.NotifyIntegration),
}
} else if platform.SupportsKanikoPublishStrategy(e.Platform) {
e.Steps = []builder.Step{
builder.NewStep("packager", builder.ApplicationPackagePhase, builder.StandardPackager),
builder.NewStep("publisher/kaniko", builder.ApplicationPublishPhase, kaniko.Publisher),
builder.NewStep("notify/integration", builder.NotifyPhase, builder.NotifyIntegration),
}
}
}
Expand Down

0 comments on commit 8fed404

Please sign in to comment.