Skip to content

Commit

Permalink
Allow to configure the base image used to run integrations #340
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli authored and nicolaferraro committed Jan 18, 2019
1 parent cab8231 commit 92362f3
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 12 deletions.
1 change: 1 addition & 0 deletions deploy/platform-cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ metadata:
spec:
build:
camelVersion: "2.23.1"
baseImage: "fabric8/s2i-java:3.0-java8"
1 change: 1 addition & 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/integrationcontext_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type IntegrationContextSpec struct {
// IntegrationContextStatus defines the observed state of IntegrationContext
type IntegrationContextStatus struct {
Phase IntegrationContextPhase `json:"phase,omitempty"`
BaseImage string `json:"baseImage,omitempty"`
Image string `json:"image,omitempty"`
PublicImage string `json:"publicImage,omitempty"`
Digest string `json:"digest,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/camel/v1alpha1/integrationplatform_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type IntegrationPlatformBuildSpec struct {
Organization string `json:"organization,omitempty"`
PushSecret string `json:"pushSecret,omitempty"`
CamelVersion string `json:"camelVersion,omitempty"`
BaseImage string `json:"baseImage,omitempty"`
Properties map[string]string `json:"properties,omitempty"`
Repositories []string `json:"repositories,omitempty"`
}
Expand Down
38 changes: 28 additions & 10 deletions pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,38 @@ func (b *defaultBuilder) submit(request Request) {

defer os.RemoveAll(builderPath)

// update the cache
b.request.Store(request.Meta.Name, r)

c := Context{
C: b.ctx,
Client: b.client,
Path: builderPath,
Namespace: b.namespace,
Request: request,
Image: "fabric8/s2i-java:2.3", // TODO: externalize,
Image: request.Platform.Build.BaseImage,
}

if request.Image != "" {
c.Image = request.Image
}

// base image is mandatory
if c.Image == "" {
r.Status = StatusError
r.Image = ""
r.PublicImage = ""
r.Error = errors.New("no base image defined")
r.Task.CompletedAt = time.Now()

// update the cache
b.request.Store(request.Meta.Name, r)

return
}

c.BaseImage = c.Image

// update the cache
b.request.Store(request.Meta.Name, r)

// Sort steps by phase
sort.SliceStable(request.Steps, func(i, j int) bool {
return request.Steps[i].Phase() < request.Steps[j].Phase()
Expand Down Expand Up @@ -192,6 +208,7 @@ func (b *defaultBuilder) submit(request Request) {
}

r.Status = StatusCompleted
r.BaseImage = c.BaseImage
r.Image = c.Image
r.PublicImage = c.PublicImage
r.Error = c.Error
Expand All @@ -208,10 +225,11 @@ func (b *defaultBuilder) submit(request Request) {
b.request.Store(request.Meta.Name, r)

b.log.Infof("request to build context %s executed in %f seconds", request.Meta.Name, r.Task.Elapsed().Seconds())
b.log.Infof("dependencies : %s", request.Dependencies)
b.log.Infof("artifacts : %s", ArtifactIDs(c.Artifacts))
b.log.Infof("artifacts selected : %s", ArtifactIDs(c.SelectedArtifacts))
b.log.Infof("requested image : %s", request.Image)
b.log.Infof("resolved image : %s", c.Image)
b.log.Infof("resolved public image : %s", c.PublicImage)
b.log.Infof("dependencies: %s", request.Dependencies)
b.log.Infof("artifacts: %s", ArtifactIDs(c.Artifacts))
b.log.Infof("artifacts selected: %s", ArtifactIDs(c.SelectedArtifacts))
b.log.Infof("requested image: %s", request.Image)
b.log.Infof("base image: %s", c.BaseImage)
b.log.Infof("resolved image: %s", c.Image)
b.log.Infof("resolved public image: %s", c.PublicImage)
}
1 change: 1 addition & 0 deletions pkg/builder/builder_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func IncrementalPackager(ctx *Context) error {
}
}

ctx.BaseImage = bestImage.Image
ctx.Image = bestImage.Image
ctx.SelectedArtifacts = selectedArtifacts
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/builder/builder_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (t Task) Elapsed() time.Duration {
// Result represents the result of a build
type Result struct {
Request Request
BaseImage string
Image string
PublicImage string
Error error
Expand All @@ -138,6 +139,7 @@ type Context struct {
C context.Context
client.Client
Request Request
BaseImage string
Image string
PublicImage string
Error error
Expand Down
5 changes: 5 additions & 0 deletions pkg/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func newCmdInstall(rootCmdOptions *RootCmdOptions) *cobra.Command {
cmd.Flags().StringSliceVar(&impl.repositories, "repository", nil, "Add a maven repository")
cmd.Flags().StringSliceVarP(&impl.properties, "property", "p", nil, "Add a camel property")
cmd.Flags().StringVar(&impl.camelVersion, "camel-version", "", "Set the camel version")
cmd.Flags().StringVar(&impl.baseImage, "base-image", "", "Set the base image used to run integrations")
cmd.Flags().StringSliceVar(&impl.contexts, "context", nil, "Add a camel context to build at startup, by default all known contexts are built")

// completion support
Expand All @@ -79,6 +80,7 @@ type installCmdOptions struct {
organization string
pushSecret string
camelVersion string
baseImage string
repositories []string
properties []string
contexts []string
Expand Down Expand Up @@ -144,6 +146,9 @@ func (o *installCmdOptions) install(cmd *cobra.Command, args []string) error {
if o.camelVersion != "" {
platform.Spec.Build.CamelVersion = o.camelVersion
}
if o.baseImage != "" {
platform.Spec.Build.BaseImage = o.baseImage
}

platform.Spec.Resources.Contexts = o.contexts

Expand Down
1 change: 1 addition & 0 deletions pkg/controller/integrationcontext/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (action *buildAction) Handle(ctx context.Context, ictx *v1alpha1.Integratio
return action.client.Update(ctx, target)
case builder.StatusCompleted:
target := ictx.DeepCopy()
target.Status.BaseImage = res.BaseImage
target.Status.Image = res.Image
target.Status.PublicImage = res.PublicImage
target.Status.Phase = v1alpha1.IntegrationContextPhaseReady
Expand Down
6 changes: 4 additions & 2 deletions test/build_manager_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func TestBuildManagerBuild(t *testing.T) {
},
Platform: v1alpha1.IntegrationPlatformSpec{
Build: v1alpha1.IntegrationPlatformBuildSpec{
CamelVersion: "2.23.0",
CamelVersion: "2.23.1",
BaseImage: "docker.io/fabric8/s2i-java:3.0-java8",
},
},
Dependencies: []string{
Expand Down Expand Up @@ -84,7 +85,8 @@ func TestBuildManagerFailedBuild(t *testing.T) {
},
Platform: v1alpha1.IntegrationPlatformSpec{
Build: v1alpha1.IntegrationPlatformBuildSpec{
CamelVersion: "2.23.0",
CamelVersion: "2.23.1",
BaseImage: "fabric8/s2i-java:3.0-java8",
},
},
Dependencies: []string{
Expand Down

0 comments on commit 92362f3

Please sign in to comment.