This is an automated email from the ASF dual-hosted git repository.

nferraro 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 7bd061d  feature(kaniko): support for incremental build
7bd061d is described below

commit 7bd061dec315bd98f017eeb794787bbe05933dc6
Author: lburgazzoli <[email protected]>
AuthorDate: Wed Mar 6 13:23:03 2019 +0100

    feature(kaniko): support for incremental build
---
 .../camel/v1alpha1/integrationplatform_types.go    | 12 +++++++++---
 pkg/builder/kaniko/kaniko.go                       |  2 +-
 pkg/builder/kaniko/publisher.go                    | 19 ++++++++++++-------
 pkg/cmd/install.go                                 | 14 +++++++-------
 pkg/controller/integrationplatform/initialize.go   |  2 +-
 pkg/install/operator.go                            | 22 ++++++++++++----------
 pkg/platform/platform.go                           |  2 +-
 pkg/trait/builder_test.go                          |  2 +-
 pkg/trait/knative_service_env_test.go              |  4 ++--
 pkg/trait/knative_service_vol_test.go              |  4 ++--
 10 files changed, 48 insertions(+), 35 deletions(-)

diff --git a/pkg/apis/camel/v1alpha1/integrationplatform_types.go 
b/pkg/apis/camel/v1alpha1/integrationplatform_types.go
index 5e334bf..41e2daf 100644
--- a/pkg/apis/camel/v1alpha1/integrationplatform_types.go
+++ b/pkg/apis/camel/v1alpha1/integrationplatform_types.go
@@ -72,15 +72,21 @@ var allTraitProfiles = 
[]TraitProfile{TraitProfileOpenShift, TraitProfileKuberne
 // IntegrationPlatformBuildSpec contains platform related build information
 type IntegrationPlatformBuildSpec struct {
        PublishStrategy IntegrationPlatformBuildPublishStrategy 
`json:"publishStrategy,omitempty"`
-       Registry        string                                  
`json:"registry,omitempty"`
-       Organization    string                                  
`json:"organization,omitempty"`
-       PushSecret      string                                  
`json:"pushSecret,omitempty"`
        CamelVersion    string                                  
`json:"camelVersion,omitempty"`
        RuntimeVersion  string                                  
`json:"runtimeVersion,omitempty"`
        BaseImage       string                                  
`json:"baseImage,omitempty"`
        Properties      map[string]string                       
`json:"properties,omitempty"`
        LocalRepository string                                  
`json:"localRepository,omitempty"`
        Repositories    []string                                
`json:"repositories,omitempty"`
+       Registry        IntegrationPlatformRegistrySpec         
`json:"registry,omitempty"`
+}
+
+// IntegrationPlatformRegistrySpec --
+type IntegrationPlatformRegistrySpec struct {
+       Insecure     bool   `json:"insecure,omitempty"`
+       Address      string `json:"address,omitempty"`
+       Secret       string `json:"secret,omitempty"`
+       Organization string `json:"organization,omitempty"`
 }
 
 // IntegrationPlatformBuildPublishStrategy enumerates all implemented build 
strategies
diff --git a/pkg/builder/kaniko/kaniko.go b/pkg/builder/kaniko/kaniko.go
index 0c81d0a..187ced0 100644
--- a/pkg/builder/kaniko/kaniko.go
+++ b/pkg/builder/kaniko/kaniko.go
@@ -27,7 +27,7 @@ var DefaultSteps = []builder.Step{
        builder.NewStep("project/inject-dependencies", 
builder.ProjectGenerationPhase+1, builder.InjectDependencies),
        builder.NewStep("project/sanitize-dependencies", 
builder.ProjectGenerationPhase+2, builder.SanitizeDependencies),
        builder.NewStep("build/compute-dependencies", 
builder.ProjectBuildPhase, builder.ComputeDependencies),
-       builder.NewStep("packager", builder.ApplicationPackagePhase, 
builder.StandardPackager),
+       builder.NewStep("packager/incremental", 
builder.ApplicationPackagePhase, builder.IncrementalPackager),
        builder.NewStep("publisher/kaniko", builder.ApplicationPublishPhase, 
Publisher),
 }
 
diff --git a/pkg/builder/kaniko/publisher.go b/pkg/builder/kaniko/publisher.go
index b897b74..a326078 100644
--- a/pkg/builder/kaniko/publisher.go
+++ b/pkg/builder/kaniko/publisher.go
@@ -36,11 +36,11 @@ import (
 
 // Publisher --
 func Publisher(ctx *builder.Context) error {
-       organization := ctx.Request.Platform.Build.Organization
+       organization := ctx.Request.Platform.Build.Registry.Organization
        if organization == "" {
                organization = ctx.Namespace
        }
-       image := ctx.Request.Platform.Build.Registry + "/" + organization + 
"/camel-k-" + ctx.Request.Meta.Name + ":" + ctx.Request.Meta.ResourceVersion
+       image := ctx.Request.Platform.Build.Registry.Address + "/" + 
organization + "/camel-k-" + ctx.Request.Meta.Name + ":" + 
ctx.Request.Meta.ResourceVersion
        baseDir, _ := path.Split(ctx.Archive)
        contextDir := path.Join(baseDir, "context")
        if err := tar.Extract(ctx.Archive, contextDir); err != nil {
@@ -74,7 +74,7 @@ func Publisher(ctx *builder.Context) error {
                        MountPath: "/workspace",
                },
        }
-       envs := []corev1.EnvVar{}
+       envs := make([]corev1.EnvVar, 0)
        baseArgs := []string{
                "--dockerfile=Dockerfile",
                "--context=" + contextDir,
@@ -83,15 +83,20 @@ func Publisher(ctx *builder.Context) error {
                "--cache-dir=/workspace/cache",
        }
 
-       args := append(baseArgs, "--insecure")
-       args = append(args, "--insecure-pull")
+       args := make([]string, 0, len(baseArgs))
+       args = append(args, baseArgs...)
 
-       if ctx.Request.Platform.Build.PushSecret != "" {
+       if ctx.Request.Platform.Build.Registry.Insecure {
+               args = append(args, "--insecure")
+               args = append(args, "--insecure-pull")
+       }
+
+       if ctx.Request.Platform.Build.Registry.Secret != "" {
                volumes = append(volumes, corev1.Volume{
                        Name: "kaniko-secret",
                        VolumeSource: corev1.VolumeSource{
                                Secret: &corev1.SecretVolumeSource{
-                                       SecretName: 
ctx.Request.Platform.Build.PushSecret,
+                                       SecretName: 
ctx.Request.Platform.Build.Registry.Secret,
                                },
                        },
                })
diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go
index a381088..b4a2722 100644
--- a/pkg/cmd/install.go
+++ b/pkg/cmd/install.go
@@ -54,10 +54,12 @@ func newCmdInstall(rootCmdOptions *RootCmdOptions) 
*cobra.Command {
        cmd.Flags().BoolVar(&impl.clusterSetupOnly, "cluster-setup", false, 
"Execute cluster-wide operations only (may require admin rights)")
        cmd.Flags().BoolVar(&impl.skipClusterSetup, "skip-cluster-setup", 
false, "Skip the cluster-setup phase")
        cmd.Flags().BoolVar(&impl.exampleSetup, "example", false, "Install 
example integration")
-       cmd.Flags().StringVar(&impl.registry, "registry", "", "A Docker 
registry that can be used to publish images")
+
        cmd.Flags().StringVarP(&impl.outputFormat, "output", "o", "", "Output 
format. One of: json|yaml")
-       cmd.Flags().StringVar(&impl.organization, "organization", "", "A 
organization on the Docker registry that can be used to publish images")
-       cmd.Flags().StringVar(&impl.pushSecret, "push-secret", "", "A secret 
used to push images to the Docker registry")
+       cmd.Flags().StringVar(&impl.registry.Organization, "organization", "", 
"A organization on the Docker registry that can be used to publish images")
+       cmd.Flags().StringVar(&impl.registry.Address, "registry", "", "A Docker 
registry that can be used to publish images")
+       cmd.Flags().StringVar(&impl.registry.Secret, "registry-secret", "", "A 
secret used to push/pull images to the Docker registry")
+       cmd.Flags().BoolVar(&impl.registry.Insecure, "registry-insecure", 
false, "Configure to configure registry access in insecure mode or not")
        cmd.Flags().StringSliceVar(&impl.repositories, "repository", nil, "Add 
a maven repository")
        cmd.Flags().BoolVar(&impl.snapshotRepositories, 
"snapshot-repositories", false, "Automatically include known snapshot 
repositories")
        cmd.Flags().StringVar(&impl.localRepository, "local-repository", "", 
"Location of the local maven repository")
@@ -86,10 +88,7 @@ type installCmdOptions struct {
        skipClusterSetup     bool
        exampleSetup         bool
        snapshotRepositories bool
-       registry             string
        outputFormat         string
-       organization         string
-       pushSecret           string
        camelVersion         string
        runtimeVersion       string
        baseImage            string
@@ -97,6 +96,7 @@ type installCmdOptions struct {
        repositories         []string
        properties           []string
        contexts             []string
+       registry             v1alpha1.IntegrationPlatformRegistrySpec
 }
 
 func (o *installCmdOptions) install(_ *cobra.Command, _ []string) error {
@@ -137,7 +137,7 @@ func (o *installCmdOptions) install(_ *cobra.Command, _ 
[]string) error {
                        return err
                }
 
-               platform, err := install.PlatformOrCollect(o.Context, c, 
namespace, o.registry, o.organization, o.pushSecret, collection)
+               platform, err := install.PlatformOrCollect(o.Context, c, 
namespace, o.registry, collection)
                if err != nil {
                        return err
                }
diff --git a/pkg/controller/integrationplatform/initialize.go 
b/pkg/controller/integrationplatform/initialize.go
index a901739..7182575 100644
--- a/pkg/controller/integrationplatform/initialize.go
+++ b/pkg/controller/integrationplatform/initialize.go
@@ -85,7 +85,7 @@ func (action *initializeAction) Handle(ctx context.Context, 
ip *v1alpha1.Integra
                }
        }
 
-       if target.Spec.Build.PublishStrategy == 
v1alpha1.IntegrationPlatformBuildPublishStrategyKaniko && 
target.Spec.Build.Registry == "" {
+       if target.Spec.Build.PublishStrategy == 
v1alpha1.IntegrationPlatformBuildPublishStrategyKaniko && 
target.Spec.Build.Registry.Address == "" {
                action.L.Info("No registry specified for publishing images")
        }
 
diff --git a/pkg/install/operator.go b/pkg/install/operator.go
index 365592f..1305347 100644
--- a/pkg/install/operator.go
+++ b/pkg/install/operator.go
@@ -90,13 +90,13 @@ func installKnative(ctx context.Context, c client.Client, 
namespace string, coll
 }
 
 // Platform installs the platform custom resource
-func Platform(ctx context.Context, c client.Client, namespace string, registry 
string, organization string, pushSecret string) (*v1alpha1.IntegrationPlatform, 
error) {
-       return PlatformOrCollect(ctx, c, namespace, registry, organization, 
pushSecret, nil)
+func Platform(ctx context.Context, c client.Client, namespace string, registry 
v1alpha1.IntegrationPlatformRegistrySpec) (*v1alpha1.IntegrationPlatform, 
error) {
+       return PlatformOrCollect(ctx, c, namespace, registry, nil)
 }
 
 // PlatformOrCollect --
 // nolint: lll
-func PlatformOrCollect(ctx context.Context, c client.Client, namespace string, 
registry string, organization string, pushSecret string, collection 
*kubernetes.Collection) (*v1alpha1.IntegrationPlatform, error) {
+func PlatformOrCollect(ctx context.Context, c client.Client, namespace string, 
registry v1alpha1.IntegrationPlatformRegistrySpec, collection 
*kubernetes.Collection) (*v1alpha1.IntegrationPlatform, error) {
        isOpenshift, err := openshift.IsOpenShift(c)
        if err != nil {
                return nil, err
@@ -108,22 +108,24 @@ func PlatformOrCollect(ctx context.Context, c 
client.Client, namespace string, r
        pl := platformObject.(*v1alpha1.IntegrationPlatform)
 
        if !isOpenshift {
+
+               pl.Spec.Build.Registry = registry
+
                // Kubernetes only (Minikube)
-               if registry == "" {
+               if registry.Address == "" {
                        // This operation should be done here in the installer
                        // because the operator is not allowed to look into the 
"kube-system" namespace
-                       minishiftRegistry, err := minishift.FindRegistry(ctx, c)
+                       minikubeRegistry, err := minishift.FindRegistry(ctx, c)
                        if err != nil {
                                return nil, err
                        }
-                       if minishiftRegistry == nil {
+                       if minikubeRegistry == nil {
                                return nil, errors.New("cannot find 
automatically a registry where to push images")
                        }
-                       registry = *minishiftRegistry
+
+                       pl.Spec.Build.Registry.Address = *minikubeRegistry
+                       pl.Spec.Build.Registry.Insecure = true
                }
-               pl.Spec.Build.Registry = registry
-               pl.Spec.Build.Organization = organization
-               pl.Spec.Build.PushSecret = pushSecret
        }
 
        var knativeInstalled bool
diff --git a/pkg/platform/platform.go b/pkg/platform/platform.go
index 30741ff..ddf1285 100644
--- a/pkg/platform/platform.go
+++ b/pkg/platform/platform.go
@@ -93,5 +93,5 @@ func SupportsS2iPublishStrategy(p 
*v1alpha1.IntegrationPlatform) bool {
 
 // SupportsKanikoPublishStrategy --
 func SupportsKanikoPublishStrategy(p *v1alpha1.IntegrationPlatform) bool {
-       return p.Spec.Build.PublishStrategy == 
v1alpha1.IntegrationPlatformBuildPublishStrategyKaniko && p.Spec.Build.Registry 
!= ""
+       return p.Spec.Build.PublishStrategy == 
v1alpha1.IntegrationPlatformBuildPublishStrategyKaniko && 
p.Spec.Build.Registry.Address != ""
 }
diff --git a/pkg/trait/builder_test.go b/pkg/trait/builder_test.go
index 558d83d..50ecac7 100644
--- a/pkg/trait/builder_test.go
+++ b/pkg/trait/builder_test.go
@@ -146,7 +146,7 @@ func createBuilderTestEnv(cluster 
v1alpha1.IntegrationPlatformCluster, strategy
                                Cluster: cluster,
                                Build: v1alpha1.IntegrationPlatformBuildSpec{
                                        PublishStrategy: strategy,
-                                       Registry:        "registry",
+                                       Registry:        
v1alpha1.IntegrationPlatformRegistrySpec{Address: "registry"},
                                        CamelVersion:    
defaults.CamelVersionConstraint,
                                },
                        },
diff --git a/pkg/trait/knative_service_env_test.go 
b/pkg/trait/knative_service_env_test.go
index 51af21c..0511739 100644
--- a/pkg/trait/knative_service_env_test.go
+++ b/pkg/trait/knative_service_env_test.go
@@ -90,7 +90,7 @@ func TestKnativeTraitWithCompressedSources(t *testing.T) {
                                Cluster: 
v1alpha1.IntegrationPlatformClusterOpenShift,
                                Build: v1alpha1.IntegrationPlatformBuildSpec{
                                        PublishStrategy: 
v1alpha1.IntegrationPlatformBuildPublishStrategyS2I,
-                                       Registry:        "registry",
+                                       Registry:        
v1alpha1.IntegrationPlatformRegistrySpec{Address: "registry"},
                                },
                        },
                },
@@ -179,7 +179,7 @@ func TestKnativeTraitWithConfigMapSources(t *testing.T) {
                                Cluster: 
v1alpha1.IntegrationPlatformClusterOpenShift,
                                Build: v1alpha1.IntegrationPlatformBuildSpec{
                                        PublishStrategy: 
v1alpha1.IntegrationPlatformBuildPublishStrategyS2I,
-                                       Registry:        "registry",
+                                       Registry:        
v1alpha1.IntegrationPlatformRegistrySpec{Address: "registry"},
                                },
                        },
                },
diff --git a/pkg/trait/knative_service_vol_test.go 
b/pkg/trait/knative_service_vol_test.go
index 01c8a7b..8bdfe6c 100644
--- a/pkg/trait/knative_service_vol_test.go
+++ b/pkg/trait/knative_service_vol_test.go
@@ -91,7 +91,7 @@ func TestKnativeWithVolumeBinding(t *testing.T) {
                                Cluster: 
v1alpha1.IntegrationPlatformClusterOpenShift,
                                Build: v1alpha1.IntegrationPlatformBuildSpec{
                                        PublishStrategy: 
v1alpha1.IntegrationPlatformBuildPublishStrategyS2I,
-                                       Registry:        "registry",
+                                       Registry:        
v1alpha1.IntegrationPlatformRegistrySpec{Address: "registry"},
                                },
                        },
                },
@@ -227,7 +227,7 @@ func TestKnativeWithVolumeBindingAndContainerImage(t 
*testing.T) {
                                Cluster: 
v1alpha1.IntegrationPlatformClusterOpenShift,
                                Build: v1alpha1.IntegrationPlatformBuildSpec{
                                        PublishStrategy: 
v1alpha1.IntegrationPlatformBuildPublishStrategyS2I,
-                                       Registry:        "registry",
+                                       Registry:        
v1alpha1.IntegrationPlatformRegistrySpec{Address: "registry"},
                                },
                        },
                },

Reply via email to