[GitHub] [camel-k] doru1004 opened a new pull request #1827: Add command line options for creating, building and running containerized integrations locally

classic Classic list List threaded Threaded
26 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 opened a new pull request #1827: Add command line options for creating, building and running containerized integrations locally

GitBox

doru1004 opened a new pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827


   <!-- Description -->
   
   This patch adds command line options for creating, building and running local images.
   
   A new local command, `local create` has been added to construct a base image to be used as a starter for all integration images. Example of building a base image:
   
   ```
   kamel local create --base-image --docker-registry <registry-name>
   ```
   
   The image can then be used as a base for creating and building integration images. Example of building an integration image:
   
   ```
   kamel local create --docker-registry <registry-name> --image-name my-image -d <dep> -p <prop> --property-file <file> route1.java route2.yaml
   ```
   
   The resoling image can then be run locally using the following invocation:
   
   ```
   kamel local run --docker-registry <registry-name> --image-name my-image
   ```
   
   Local run has been enhanced with containerization capabilities i.e. it can now create, build and run container images locally. The following command containerizes and runs the integration:
   
   ```
   kamel local run --containerize --docker-registry <registry-name> --image-name my-image -d <dep> -p <prop> --property-file <file> route1.java route2.yaml
   ```
   
   
   <!--
   Enter your extended release note in the below block. If the PR requires
   additional action from users switching to the new release, include the string
   "action required". If no release note is required, write "NONE".
   
   You can (optionally) mark this PR with labels "kind/bug" or "kind/feature" to make sure
   the text is added to the right section of the release notes.
   -->
   
   **Release Note**
   ```release-note
   "kind/feature"
   ```
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] nicolaferraro commented on a change in pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox

nicolaferraro commented on a change in pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#discussion_r531539386



##########
File path: pkg/cmd/local_run.go
##########
@@ -55,31 +55,60 @@ func newCmdLocalRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *localRunCm
  },
  }
 
+ cmd.Flags().Bool("containerize", false, "Run integration in a local container.")
+ cmd.Flags().String("image-name", "", "Integration image name.")
+ cmd.Flags().String("docker-registry", "", "Docker registry to store intermediate images.")

Review comment:
       Same comment as before.. in all places

##########
File path: pkg/util/docker/docker.go
##########
@@ -0,0 +1,141 @@
+/*
+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 docker
+
+import (
+ "os/exec"
+ "path"
+ "strings"
+
+ "github.com/apache/camel-k/pkg/util"
+)
+
+// CreateBaseImageDockerFile --
+func CreateBaseImageDockerFile() error {
+ dockerFile := []string{}
+
+ // Base image is a java-only image since the integration command is just a java command.
+ dockerFile = append(dockerFile, FROM("adoptopenjdk/openjdk11:alpine"))

Review comment:
       You should use the base image from `defaults.go`

##########
File path: pkg/util/util.go
##########
@@ -35,6 +36,23 @@ import (
  yaml2 "gopkg.in/yaml.v2"
 )
 
+/// Directories and file names:
+
+// MavenWorkingDirectory --  Directory used by Maven for an invocation of the kamel local command. By default a temporary folder will be used.
+var MavenWorkingDirectory string = ""
+
+// DefaultDependenciesDirectoryName --
+const DefaultDependenciesDirectoryName = "dependencies"
+
+// DefaultPropertiesDirectoryName --
+const DefaultPropertiesDirectoryName = "properties"
+
+// DefaultRoutesDirectoryName --
+const DefaultRoutesDirectoryName = "routes"
+
+// DefaultWorkingDirectoryName --
+const DefaultWorkingDirectoryName = "workspace"

Review comment:
       Can we use the same structure found in the kubernetes image? There's a small structure under `/deployments` there, plus many of other things are present in `/etc/camel`.
   
   The reason why this is important is that many users would like to use this command to freeze a container image that is then used in test and production, so it would be nice if a base image built here can be used as base image in kube as well

##########
File path: pkg/cmd/local_create.go
##########
@@ -0,0 +1,168 @@
+/*
+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 cmd
+
+import (
+ "fmt"
+
+ "github.com/pkg/errors"
+ "github.com/spf13/cobra"
+)
+
+func newCmdLocalCreate(rootCmdOptions *RootCmdOptions) (*cobra.Command, *localCreateCmdOptions) {
+ options := localCreateCmdOptions{
+ RootCmdOptions: rootCmdOptions,
+ }
+
+ cmd := cobra.Command{
+ Use:     "create [options]",
+ Short:   "Create integration images locally.",
+ Long:    `Create integration images locally for containerized integrations.`,
+ PreRunE: decode(&options),
+ RunE: func(_ *cobra.Command, args []string) error {
+ if err := options.validate(args); err != nil {
+ return err
+ }
+ if err := options.init(args); err != nil {
+ return err
+ }
+ if err := options.run(args); err != nil {
+ fmt.Println(err.Error())
+ }
+ if err := options.deinit(args); err != nil {
+ return err
+ }
+
+ return nil
+ },
+ Annotations: map[string]string{
+ offlineCommandLabel: "true",
+ },
+ }
+
+ cmd.Flags().Bool("base-image", false, "Create base image used as a starting point for any integration.")

Review comment:
       I like the idea of building a base-image for an integration (without embedding the sources) or an image with source embedded.
   
   However, I've tested this with an integration (base-image=false) and sources are not included. If this is the idea, I think there's something still not working correctly.

##########
File path: pkg/cmd/local_create.go
##########
@@ -0,0 +1,168 @@
+/*
+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 cmd
+
+import (
+ "fmt"
+
+ "github.com/pkg/errors"
+ "github.com/spf13/cobra"
+)
+
+func newCmdLocalCreate(rootCmdOptions *RootCmdOptions) (*cobra.Command, *localCreateCmdOptions) {
+ options := localCreateCmdOptions{
+ RootCmdOptions: rootCmdOptions,
+ }
+
+ cmd := cobra.Command{
+ Use:     "create [options]",
+ Short:   "Create integration images locally.",
+ Long:    `Create integration images locally for containerized integrations.`,
+ PreRunE: decode(&options),
+ RunE: func(_ *cobra.Command, args []string) error {
+ if err := options.validate(args); err != nil {
+ return err
+ }
+ if err := options.init(args); err != nil {
+ return err
+ }
+ if err := options.run(args); err != nil {
+ fmt.Println(err.Error())
+ }
+ if err := options.deinit(args); err != nil {
+ return err
+ }
+
+ return nil
+ },
+ Annotations: map[string]string{
+ offlineCommandLabel: "true",
+ },
+ }
+
+ cmd.Flags().Bool("base-image", false, "Create base image used as a starting point for any integration.")
+ cmd.Flags().String("image-name", "", "Integration image name.")
+ cmd.Flags().String("docker-registry", "", "Docker registry to store intermediate images.")

Review comment:
       I'd prefer using the word "container" instead of Docker here.
   
   Also, I wonder if it would be better to have a single parameter for the image name and registry. Simplifying the command as: `kamel local create it.yaml --image docker.io/myrepo/myimage`, i.e. treat is as a tag.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] nicolaferraro commented on a change in pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox
In reply to this post by GitBox

nicolaferraro commented on a change in pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#discussion_r531545871



##########
File path: pkg/cmd/local_create.go
##########
@@ -0,0 +1,168 @@
+/*
+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 cmd
+
+import (
+ "fmt"
+
+ "github.com/pkg/errors"
+ "github.com/spf13/cobra"
+)
+
+func newCmdLocalCreate(rootCmdOptions *RootCmdOptions) (*cobra.Command, *localCreateCmdOptions) {
+ options := localCreateCmdOptions{
+ RootCmdOptions: rootCmdOptions,
+ }
+
+ cmd := cobra.Command{
+ Use:     "create [options]",
+ Short:   "Create integration images locally.",
+ Long:    `Create integration images locally for containerized integrations.`,
+ PreRunE: decode(&options),
+ RunE: func(_ *cobra.Command, args []string) error {
+ if err := options.validate(args); err != nil {
+ return err
+ }
+ if err := options.init(args); err != nil {
+ return err
+ }
+ if err := options.run(args); err != nil {
+ fmt.Println(err.Error())
+ }
+ if err := options.deinit(args); err != nil {
+ return err
+ }
+
+ return nil
+ },
+ Annotations: map[string]string{
+ offlineCommandLabel: "true",
+ },
+ }
+
+ cmd.Flags().Bool("base-image", false, "Create base image used as a starting point for any integration.")

Review comment:
       I re-read the description and I think I didn't get it correctly...




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] nicolaferraro commented on pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox
In reply to this post by GitBox

nicolaferraro commented on pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#issuecomment-734795165


   Another issue is that `kamel local create --base-image` creates a maven structure in the current directory (pom.xml, src and target dirs).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on a change in pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox
In reply to this post by GitBox

doru1004 commented on a change in pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#discussion_r532827623



##########
File path: pkg/cmd/local_create.go
##########
@@ -0,0 +1,168 @@
+/*
+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 cmd
+
+import (
+ "fmt"
+
+ "github.com/pkg/errors"
+ "github.com/spf13/cobra"
+)
+
+func newCmdLocalCreate(rootCmdOptions *RootCmdOptions) (*cobra.Command, *localCreateCmdOptions) {
+ options := localCreateCmdOptions{
+ RootCmdOptions: rootCmdOptions,
+ }
+
+ cmd := cobra.Command{
+ Use:     "create [options]",
+ Short:   "Create integration images locally.",
+ Long:    `Create integration images locally for containerized integrations.`,
+ PreRunE: decode(&options),
+ RunE: func(_ *cobra.Command, args []string) error {
+ if err := options.validate(args); err != nil {
+ return err
+ }
+ if err := options.init(args); err != nil {
+ return err
+ }
+ if err := options.run(args); err != nil {
+ fmt.Println(err.Error())
+ }
+ if err := options.deinit(args); err != nil {
+ return err
+ }
+
+ return nil
+ },
+ Annotations: map[string]string{
+ offlineCommandLabel: "true",
+ },
+ }
+
+ cmd.Flags().Bool("base-image", false, "Create base image used as a starting point for any integration.")
+ cmd.Flags().String("image-name", "", "Integration image name.")
+ cmd.Flags().String("docker-registry", "", "Docker registry to store intermediate images.")

Review comment:
       The reason why I have separated the two flags is because the base image doesn't need a name (name is always the same), it only needs a registry. So I'd have to keep the flag around for that reason and rename it to `container-registry` and then for integration images I can just support the `--image` flag like you suggested and make it illegal to use the registry flag when an integration is being built. What do you think?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on a change in pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox
In reply to this post by GitBox

doru1004 commented on a change in pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#discussion_r532884477



##########
File path: pkg/cmd/local_run.go
##########
@@ -55,31 +55,60 @@ func newCmdLocalRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *localRunCm
  },
  }
 
+ cmd.Flags().Bool("containerize", false, "Run integration in a local container.")
+ cmd.Flags().String("image-name", "", "Integration image name.")
+ cmd.Flags().String("docker-registry", "", "Docker registry to store intermediate images.")

Review comment:
       Done.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox
In reply to this post by GitBox

doru1004 commented on pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#issuecomment-736114145


   > Another issue is that `kamel local create --base-image` creates a maven structure in the current directory (pom.xml, src and target dirs).
   
   I fixed this. There were several other files and folders emitted and now no intermediate files/folders are emitted in the current directory.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on a change in pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox
In reply to this post by GitBox

doru1004 commented on a change in pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#discussion_r532968744



##########
File path: pkg/cmd/local_create.go
##########
@@ -0,0 +1,168 @@
+/*
+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 cmd
+
+import (
+ "fmt"
+
+ "github.com/pkg/errors"
+ "github.com/spf13/cobra"
+)
+
+func newCmdLocalCreate(rootCmdOptions *RootCmdOptions) (*cobra.Command, *localCreateCmdOptions) {
+ options := localCreateCmdOptions{
+ RootCmdOptions: rootCmdOptions,
+ }
+
+ cmd := cobra.Command{
+ Use:     "create [options]",
+ Short:   "Create integration images locally.",
+ Long:    `Create integration images locally for containerized integrations.`,
+ PreRunE: decode(&options),
+ RunE: func(_ *cobra.Command, args []string) error {
+ if err := options.validate(args); err != nil {
+ return err
+ }
+ if err := options.init(args); err != nil {
+ return err
+ }
+ if err := options.run(args); err != nil {
+ fmt.Println(err.Error())
+ }
+ if err := options.deinit(args); err != nil {
+ return err
+ }
+
+ return nil
+ },
+ Annotations: map[string]string{
+ offlineCommandLabel: "true",
+ },
+ }
+
+ cmd.Flags().Bool("base-image", false, "Create base image used as a starting point for any integration.")

Review comment:
       If there are any further questions about this please let me know :)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on a change in pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox
In reply to this post by GitBox

doru1004 commented on a change in pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#discussion_r532968839



##########
File path: pkg/util/docker/docker.go
##########
@@ -0,0 +1,141 @@
+/*
+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 docker
+
+import (
+ "os/exec"
+ "path"
+ "strings"
+
+ "github.com/apache/camel-k/pkg/util"
+)
+
+// CreateBaseImageDockerFile --
+func CreateBaseImageDockerFile() error {
+ dockerFile := []string{}
+
+ // Base image is a java-only image since the integration command is just a java command.
+ dockerFile = append(dockerFile, FROM("adoptopenjdk/openjdk11:alpine"))

Review comment:
       Done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] nicolaferraro commented on a change in pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox
In reply to this post by GitBox

nicolaferraro commented on a change in pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#discussion_r533491662



##########
File path: pkg/cmd/local_create.go
##########
@@ -0,0 +1,168 @@
+/*
+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 cmd
+
+import (
+ "fmt"
+
+ "github.com/pkg/errors"
+ "github.com/spf13/cobra"
+)
+
+func newCmdLocalCreate(rootCmdOptions *RootCmdOptions) (*cobra.Command, *localCreateCmdOptions) {
+ options := localCreateCmdOptions{
+ RootCmdOptions: rootCmdOptions,
+ }
+
+ cmd := cobra.Command{
+ Use:     "create [options]",
+ Short:   "Create integration images locally.",
+ Long:    `Create integration images locally for containerized integrations.`,
+ PreRunE: decode(&options),
+ RunE: func(_ *cobra.Command, args []string) error {
+ if err := options.validate(args); err != nil {
+ return err
+ }
+ if err := options.init(args); err != nil {
+ return err
+ }
+ if err := options.run(args); err != nil {
+ fmt.Println(err.Error())
+ }
+ if err := options.deinit(args); err != nil {
+ return err
+ }
+
+ return nil
+ },
+ Annotations: map[string]string{
+ offlineCommandLabel: "true",
+ },
+ }
+
+ cmd.Flags().Bool("base-image", false, "Create base image used as a starting point for any integration.")
+ cmd.Flags().String("image-name", "", "Integration image name.")
+ cmd.Flags().String("docker-registry", "", "Docker registry to store intermediate images.")

Review comment:
       Sounds good




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] nicolaferraro commented on pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox
In reply to this post by GitBox

nicolaferraro commented on pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#issuecomment-736618536


   Seems there is some other issue, I can't get `kamel local run examples/routes.groovy` to work (it does not print the periodic log message).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox
In reply to this post by GitBox

doru1004 commented on pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#issuecomment-736634410


   > Seems there is some other issue, I can't get `kamel local run examples/routes.groovy` to work (it does not print the periodic log message).
   
   It looks like this has nothing to do with the latest changes, it probably has to do with redirecting the output of the command.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox
In reply to this post by GitBox

doru1004 commented on pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#issuecomment-736658531


   > Seems there is some other issue, I can't get `kamel local run examples/routes.groovy` to work (it does not print the periodic log message).
   
   The ` -d camel-k:runtime-quarkus` dependency needs to be added to the CLI then it all works. Perhaps we can add that dependency automatically every time.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on a change in pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox
In reply to this post by GitBox

doru1004 commented on a change in pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#discussion_r533579118



##########
File path: pkg/cmd/local_create.go
##########
@@ -0,0 +1,168 @@
+/*
+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 cmd
+
+import (
+ "fmt"
+
+ "github.com/pkg/errors"
+ "github.com/spf13/cobra"
+)
+
+func newCmdLocalCreate(rootCmdOptions *RootCmdOptions) (*cobra.Command, *localCreateCmdOptions) {
+ options := localCreateCmdOptions{
+ RootCmdOptions: rootCmdOptions,
+ }
+
+ cmd := cobra.Command{
+ Use:     "create [options]",
+ Short:   "Create integration images locally.",
+ Long:    `Create integration images locally for containerized integrations.`,
+ PreRunE: decode(&options),
+ RunE: func(_ *cobra.Command, args []string) error {
+ if err := options.validate(args); err != nil {
+ return err
+ }
+ if err := options.init(args); err != nil {
+ return err
+ }
+ if err := options.run(args); err != nil {
+ fmt.Println(err.Error())
+ }
+ if err := options.deinit(args); err != nil {
+ return err
+ }
+
+ return nil
+ },
+ Annotations: map[string]string{
+ offlineCommandLabel: "true",
+ },
+ }
+
+ cmd.Flags().Bool("base-image", false, "Create base image used as a starting point for any integration.")
+ cmd.Flags().String("image-name", "", "Integration image name.")
+ cmd.Flags().String("docker-registry", "", "Docker registry to store intermediate images.")

Review comment:
       Cool, I implemented that strategy.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on a change in pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox
In reply to this post by GitBox

doru1004 commented on a change in pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#discussion_r533821835



##########
File path: pkg/util/util.go
##########
@@ -35,6 +36,23 @@ import (
  yaml2 "gopkg.in/yaml.v2"
 )
 
+/// Directories and file names:
+
+// MavenWorkingDirectory --  Directory used by Maven for an invocation of the kamel local command. By default a temporary folder will be used.
+var MavenWorkingDirectory string = ""
+
+// DefaultDependenciesDirectoryName --
+const DefaultDependenciesDirectoryName = "dependencies"
+
+// DefaultPropertiesDirectoryName --
+const DefaultPropertiesDirectoryName = "properties"
+
+// DefaultRoutesDirectoryName --
+const DefaultRoutesDirectoryName = "routes"
+
+// DefaultWorkingDirectoryName --
+const DefaultWorkingDirectoryName = "workspace"

Review comment:
       Done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox
In reply to this post by GitBox

doru1004 commented on pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#issuecomment-736916096


   I have updated the patch to fix the reported problems. I have also changed the directories used inside the image to be the same ones used by Kubernetes! :)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 edited a comment on pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox
In reply to this post by GitBox

doru1004 edited a comment on pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#issuecomment-736916096


   I have updated the patch to fix the reported problems. I have also changed the directories used inside the image to be the same ones used in the Kubernetes case! :)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox
In reply to this post by GitBox

doru1004 commented on pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#issuecomment-737414607


   @nicolaferraro not sure why the knative test failed, it looks like there is a similar failure in master.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox
In reply to this post by GitBox

doru1004 commented on pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#issuecomment-737417015


   Rebased on latest master.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] nicolaferraro commented on a change in pull request #1827: Add command line support for creating, building and running containerized integrations locally

GitBox
In reply to this post by GitBox

nicolaferraro commented on a change in pull request #1827:
URL: https://github.com/apache/camel-k/pull/1827#discussion_r534998049



##########
File path: pkg/cmd/util_containerization.go
##########
@@ -0,0 +1,178 @@
+/*
+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 cmd
+
+import (
+ "fmt"
+ "io/ioutil"
+ "os"
+ "os/exec"
+ "strings"
+
+ "github.com/apache/camel-k/pkg/util/docker"
+ "github.com/pkg/errors"
+)
+
+/// Local Docker file system management functions.
+
+func createDockerBaseWorkingDirectory() error {
+ // Create local docker base directory.
+ temporaryDirectory, err := ioutil.TempDir(os.TempDir(), "docker-base-")
+ if err != nil {
+ return err
+ }
+
+ // Set the Docker base directory to the default value.
+ docker.BaseWorkingDirectory = temporaryDirectory
+
+ return nil
+}
+
+func deleteDockerBaseWorkingDirectory() error {
+ // Remove directory used for computing the dependencies.
+ defer os.RemoveAll(docker.BaseWorkingDirectory)
+
+ return nil
+}
+
+func createDockerWorkingDirectory() error {
+ // Create local docker base directory.
+ temporaryDirectory, err := ioutil.TempDir(os.TempDir(), "docker-")
+ if err != nil {
+ return err
+ }
+
+ // Set the Docker base directory to the default value.
+ docker.IntegrationWorkingDirectory = temporaryDirectory
+
+ return nil
+}
+
+func deleteDockerWorkingDirectory() error {
+ // Remove directory used for computing the dependencies.
+ defer os.RemoveAll(docker.IntegrationWorkingDirectory)
+
+ return nil
+}
+
+func createAndBuildBaseImage(containerRegistry string) error {
+ // Create the base image Docker file.
+ err := docker.CreateBaseImageDockerFile()
+ if err != nil {
+ return err
+ }
+
+ // Get the Docker command arguments for building the base image and create the command.
+ args := docker.BuildBaseImageArgs()
+ cmd := exec.CommandContext(ctx, "docker", args...)
+
+ // Output executed command.
+ fmt.Printf("Executing: " + strings.Join(cmd.Args, " ") + "\n")
+
+ // Run the command.
+ if err := cmd.Run(); err != nil {
+ return errors.Errorf("base image containerization did not run successfully: %v", err)
+ }
+
+ return nil
+}
+
+func createAndBuildIntegrationImage(containerRegistry string, justBaseImage bool, image string,
+ propertyFiles []string, dependencies []string, routes []string) error {
+ // This ensures the Dockerfile for the base image will not end up in an undesired location.
+ if docker.BaseWorkingDirectory == "" {
+ return errors.New("base directory that holds the base image Dockerfile has not been set correctly")
+ }
+
+ docker.RegistryName = containerRegistry
+ if !justBaseImage {
+ registryName, err := docker.ExtractRegistryName(image)
+ if err != nil {
+ return err
+ }
+
+ docker.RegistryName = registryName
+ }
+
+ // Create the Dockerfile and build the base image.
+ err := createAndBuildBaseImage(containerRegistry)
+ if err != nil {
+ return err
+ }
+
+ if justBaseImage {
+ return nil
+ }
+
+ if docker.IntegrationWorkingDirectory == "" {
+ return errors.New("integration directory that holds the image Dockerfile has not been set correctly")
+ }
+
+ // Create integration image if integration files were provided.
+ // Copy dependencies to a dependencies folder under a local directory.
+ err = updateIntegrationDependencies(dependencies)
+ if err != nil {
+ return err
+ }
+
+ // Copy routes to a routes folder under a local directory.
+ err = updateIntegrationRoutes(routes)
+ if err != nil {
+ return err
+ }
+
+ // Get integration run command to be run inside the container. This means the command
+ // has to be created with the paths which will be valid inside the container.
+ containerCmd := GetContainerIntegrationRunCommand(propertyFiles, dependencies, routes)
+
+ // Create the integration image Docker file.
+ err = docker.CreateIntegrationImageDockerFile(containerCmd)
+ if err != nil {
+ return err
+ }
+
+ // Get the Docker command arguments for building the base image and create the command.
+ args := docker.BuildIntegrationImageArgs(image)
+ cmd := exec.CommandContext(ctx, "docker", args...)
+
+ // Output executed command.
+ fmt.Printf("Executing: " + strings.Join(cmd.Args, " ") + "\n")
+
+ // Run the command.
+ if err := cmd.Run(); err != nil {
+ return errors.Errorf("integration image containerization did not run successfully: %v", err)
+ }
+
+ return nil
+}
+
+func runIntegrationImage(image string) error {
+ // Get the docker command line argument for running an image.
+ args := docker.RunIntegrationImageArgs(image)
+ cmd := exec.CommandContext(ctx, "docker", args...)
+
+ // Output executed command.
+ fmt.Printf("Executing: " + strings.Join(cmd.Args, " ") + "\n")
+
+ // Run the command.
+ if err := cmd.Run(); err != nil {

Review comment:
       Should you set the stdout and stderr here? It works but I see no logs




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


12