You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by jp...@apache.org on 2022/06/01 13:56:09 UTC

[camel-k] branch main updated (61b5017f1 -> f5e39aaa4)

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

jpoth pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


    from 61b5017f1 Updated CHANGELOG.md
     new d545b70be feat(cli): Add option to specify registry url when uploading artifacts. Move options into file:// URI syntax
     new 5ef7236fa feat(cli): Add option to skip checksum files when uploading artifacts
     new f5e39aaa4 feat(cli): Add option to skip uploading POM from JAR  when uploading artifacts to the image registry

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 e2e/registry/registry_maven_wagon_test.go |  6 +--
 pkg/cmd/run.go                            | 88 ++++++++++++++++++++-----------
 pkg/cmd/run_test.go                       | 66 -----------------------
 3 files changed, 61 insertions(+), 99 deletions(-)


[camel-k] 02/03: feat(cli): Add option to skip checksum files when uploading artifacts

Posted by jp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jpoth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 5ef7236fa51bb93d30d07e597ed5854ef41e8d92
Author: John Poth <po...@gmail.com>
AuthorDate: Mon May 23 17:26:13 2022 +0200

    feat(cli): Add option to skip checksum files when uploading artifacts
---
 pkg/cmd/run.go | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 82b16a513..04f342665 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -96,7 +96,7 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *runCmdOptions)
 
 	cmd.Flags().String("name", "", "The integration name")
 	cmd.Flags().StringArrayP("connect", "c", nil, "A Service that the integration should bind to, specified as [[apigroup/]version:]kind:[namespace/]name")
-	cmd.Flags().StringArrayP("dependency", "d", nil, "A dependency that should be included, e.g., \"-d camel-mail\" for a Camel component, \"-d mvn:org.my:app:1.0\" for a Maven dependency or \"file://localPath[?targetPath=<path>&registry=<registry URL>]\" for local files (experimental)")
+	cmd.Flags().StringArrayP("dependency", "d", nil, "A dependency that should be included, e.g., \"-d camel-mail\" for a Camel component, \"-d mvn:org.my:app:1.0\" for a Maven dependency or \"file://localPath[?targetPath=<path>&registry=<registry URL>&skipChecksums=<true>]\" for local files (experimental)")
 	cmd.Flags().BoolP("wait", "w", false, "Wait for the integration to be running")
 	cmd.Flags().StringP("kit", "k", "", "The kit used to run the integration")
 	cmd.Flags().StringArrayP("property", "p", nil, "Add a runtime property or properties file (syntax: [my-key=my-value|file:/path/to/my-conf.properties])")
@@ -825,6 +825,10 @@ func (o *runCmdOptions) getRegistry(platform *v1.IntegrationPlatform) string {
 	return platform.Status.Build.Registry.Address
 }
 
+func (o *runCmdOptions) skipChecksums() bool {
+	return o.RegistryOptions.Get("skipChecksums") == "true"
+}
+
 func (o *runCmdOptions) getTargetPath() string {
 	return o.RegistryOptions.Get("targetPath")
 }
@@ -1005,6 +1009,10 @@ func (o *runCmdOptions) uploadAsMavenArtifact(dependency maven.Dependency, path
 		return err
 	}
 	o.PrintfVerboseOutf(cmd, "Uploaded: %s to %s \n", path, options.Target)
+	if o.skipChecksums() {
+		o.PrintfVerboseOutf(cmd, "Skipping generating and uploading checksum files for %s \n", path)
+		return nil
+	}
 	return o.uploadChecksumFiles(path, options, platform, artifactHTTPPath, dependency)
 }
 


[camel-k] 01/03: feat(cli): Add option to specify registry url when uploading artifacts. Move options into file:// URI syntax

Posted by jp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jpoth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit d545b70be9b7483716bf10c16fad3e05e9c09df7
Author: John Poth <po...@gmail.com>
AuthorDate: Thu May 19 18:18:52 2022 +0200

    feat(cli): Add option to specify registry url when uploading artifacts. Move options into file:// URI syntax
---
 e2e/registry/registry_maven_wagon_test.go |  4 +-
 pkg/cmd/run.go                            | 66 ++++++++++++++++++-------------
 pkg/cmd/run_test.go                       | 66 -------------------------------
 3 files changed, 41 insertions(+), 95 deletions(-)

diff --git a/e2e/registry/registry_maven_wagon_test.go b/e2e/registry/registry_maven_wagon_test.go
index 76e2bbc99..7a978d46d 100644
--- a/e2e/registry/registry_maven_wagon_test.go
+++ b/e2e/registry/registry_maven_wagon_test.go
@@ -89,7 +89,7 @@ func TestImageRegistryIsAMavenRepository(t *testing.T) {
 			Expect(Kamel("run", "files/LaughingRoute.java",
 				"--name", name,
 				"-p", fmt.Sprintf("location=%s", customPath),
-				"-d", fmt.Sprintf("file://files/laugh.txt:%slaugh.txt", customPath),
+				"-d", fmt.Sprintf("file://files/laugh.txt?targetPath=%slaugh.txt", customPath),
 				"-n", ns,
 			).Execute()).To(Succeed())
 
@@ -104,7 +104,7 @@ func TestImageRegistryIsAMavenRepository(t *testing.T) {
 			Expect(Kamel("run", "files/LaughingRoute.java",
 				"--name", name,
 				"-p", "location=files/",
-				"-d", fmt.Sprintf("file://files/laughs/:files/"),
+				"-d", fmt.Sprintf("file://files/laughs/?targetPath=files/"),
 				"-n", ns,
 			).Execute()).To(Succeed())
 
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index a51154c5e..82b16a513 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -34,6 +34,7 @@ import (
 	"io"
 	"io/fs"
 	"io/ioutil"
+	"net/url"
 	"os"
 	"os/signal"
 	"path/filepath"
@@ -95,7 +96,7 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *runCmdOptions)
 
 	cmd.Flags().String("name", "", "The integration name")
 	cmd.Flags().StringArrayP("connect", "c", nil, "A Service that the integration should bind to, specified as [[apigroup/]version:]kind:[namespace/]name")
-	cmd.Flags().StringArrayP("dependency", "d", nil, "A dependency that should be included, e.g., \"-d camel-mail\" for a Camel component, \"-d mvn:org.my:app:1.0\" for a Maven dependency or \"file://localPath[:targetPath]\" for local files (experimental)")
+	cmd.Flags().StringArrayP("dependency", "d", nil, "A dependency that should be included, e.g., \"-d camel-mail\" for a Camel component, \"-d mvn:org.my:app:1.0\" for a Maven dependency or \"file://localPath[?targetPath=<path>&registry=<registry URL>]\" for local files (experimental)")
 	cmd.Flags().BoolP("wait", "w", false, "Wait for the integration to be running")
 	cmd.Flags().StringP("kit", "k", "", "The kit used to run the integration")
 	cmd.Flags().StringArrayP("property", "p", nil, "Add a runtime property or properties file (syntax: [my-key=my-value|file:/path/to/my-conf.properties])")
@@ -155,6 +156,7 @@ type runCmdOptions struct {
 	Labels          []string `mapstructure:"labels" yaml:",omitempty"`
 	Annotations     []string `mapstructure:"annotations" yaml:",omitempty"`
 	Sources         []string `mapstructure:"sources" yaml:",omitempty"`
+	RegistryOptions url.Values
 }
 
 func (o *runCmdOptions) preRunE(cmd *cobra.Command, args []string) error {
@@ -801,9 +803,36 @@ func resolvePodTemplate(ctx context.Context, cmd *cobra.Command, templateSrc str
 	return err
 }
 
+func parseFileURI(uri string) *url.URL {
+	file := new(url.URL)
+	file.Scheme = "file"
+	path := strings.TrimPrefix(uri, "file://")
+	i := strings.IndexByte(path, '?')
+	if i > 0 {
+		file.Path = path[:i]
+		file.RawQuery = path[i+1:]
+	} else {
+		file.Path = path
+	}
+	return file
+}
+
+func (o *runCmdOptions) getRegistry(platform *v1.IntegrationPlatform) string {
+	registry := o.RegistryOptions.Get("registry")
+	if registry != "" {
+		return registry
+	}
+	return platform.Status.Build.Registry.Address
+}
+
+func (o *runCmdOptions) getTargetPath() string {
+	return o.RegistryOptions.Get("targetPath")
+}
+
 func (o *runCmdOptions) uploadFileOrDirectory(platform *v1.IntegrationPlatform, item string, integrationName string, cmd *cobra.Command, integration *v1.Integration) error {
-	path := strings.TrimPrefix(item, "file://")
-	localPath, targetPath := getPaths(path, runtimeos.GOOS, filepath.IsAbs(path))
+	uri := parseFileURI(item)
+	o.RegistryOptions = uri.Query()
+	localPath, targetPath := uri.Path, o.getTargetPath()
 	options := o.getSpectrumOptions(platform, cmd)
 	dirName, err := getDirName(localPath)
 	if err != nil {
@@ -849,23 +878,6 @@ func (o *runCmdOptions) uploadFileOrDirectory(platform *v1.IntegrationPlatform,
 	})
 }
 
-func getPaths(path string, os string, isAbs bool) (localPath string, targetPath string) {
-	localPath = path
-	targetPath = ""
-	parts := strings.Split(path, ":")
-	if len(parts) > 1 {
-		if os != "windows" || !isAbs {
-			localPath = parts[0]
-			targetPath = parts[1]
-		} else if isAbs && len(parts) == 3 {
-			// special case on Windows for absolute paths e.g C:\foo\bar\test.csv:remote/path
-			localPath = fmt.Sprintf("%s:%s", parts[0], parts[1])
-			targetPath = parts[2]
-		}
-	}
-	return localPath, targetPath
-}
-
 func getMountPath(targetPath string, dirName string, path string) (string, error) {
 	// if the target path is a file then use that as the exact mount path
 	if filepath.Ext(targetPath) != "" {
@@ -978,7 +990,7 @@ func (o *runCmdOptions) extractGav(src *zip.File, localPath string, cmd *cobra.C
 
 func (o *runCmdOptions) uploadAsMavenArtifact(dependency maven.Dependency, path string, platform *v1.IntegrationPlatform, ns string, options spectrum.Options, cmd *cobra.Command) error {
 	artifactHTTPPath := getArtifactHTTPPath(dependency, platform, ns)
-	options.Target = fmt.Sprintf("%s/%s:%s", platform.Status.Build.Registry.Address, artifactHTTPPath, dependency.Version)
+	options.Target = fmt.Sprintf("%s/%s:%s", o.getRegistry(platform), artifactHTTPPath, dependency.Version)
 	if runtimeos.GOOS == "windows" {
 		// workaround for https://github.com/container-tools/spectrum/issues/8
 		// work with relative paths instead
@@ -993,7 +1005,7 @@ func (o *runCmdOptions) uploadAsMavenArtifact(dependency maven.Dependency, path
 		return err
 	}
 	o.PrintfVerboseOutf(cmd, "Uploaded: %s to %s \n", path, options.Target)
-	return uploadChecksumFiles(path, options, platform, artifactHTTPPath, dependency)
+	return o.uploadChecksumFiles(path, options, platform, artifactHTTPPath, dependency)
 }
 
 // Deprecated: workaround for https://github.com/container-tools/spectrum/issues/8
@@ -1041,18 +1053,18 @@ func extractGavFromPom(path string, gav maven.Dependency) maven.Dependency {
 	return gav
 }
 
-func uploadChecksumFiles(path string, options spectrum.Options, platform *v1.IntegrationPlatform, artifactHTTPPath string, dependency maven.Dependency) error {
+func (o *runCmdOptions) uploadChecksumFiles(path string, options spectrum.Options, platform *v1.IntegrationPlatform, artifactHTTPPath string, dependency maven.Dependency) error {
 	return util.WithTempDir("camel-k", func(tmpDir string) error {
 		// #nosec G401
-		if err := uploadChecksumFile(md5.New(), tmpDir, "_md5", path, options, platform, artifactHTTPPath, dependency); err != nil {
+		if err := o.uploadChecksumFile(md5.New(), tmpDir, "_md5", path, options, platform, artifactHTTPPath, dependency); err != nil {
 			return err
 		}
 		// #nosec G401
-		return uploadChecksumFile(sha1.New(), tmpDir, "_sha1", path, options, platform, artifactHTTPPath, dependency)
+		return o.uploadChecksumFile(sha1.New(), tmpDir, "_sha1", path, options, platform, artifactHTTPPath, dependency)
 	})
 }
 
-func uploadChecksumFile(hash hash.Hash, tmpDir string, ext string, path string, options spectrum.Options, platform *v1.IntegrationPlatform, artifactHTTPPath string, dependency maven.Dependency) error {
+func (o *runCmdOptions) uploadChecksumFile(hash hash.Hash, tmpDir string, ext string, path string, options spectrum.Options, platform *v1.IntegrationPlatform, artifactHTTPPath string, dependency maven.Dependency) error {
 	file, err := os.Open(path)
 	if err != nil {
 		return err
@@ -1078,7 +1090,7 @@ func uploadChecksumFile(hash hash.Hash, tmpDir string, ext string, path string,
 	if err = writeChecksumToFile(filepath, hash); err != nil {
 		return err
 	}
-	options.Target = fmt.Sprintf("%s/%s%s:%s", platform.Status.Build.Registry.Address, artifactHTTPPath, ext, dependency.Version)
+	options.Target = fmt.Sprintf("%s/%s%s:%s", o.getRegistry(platform), artifactHTTPPath, ext, dependency.Version)
 	_, err = spectrum.Build(options, fmt.Sprintf("%s:.", filepath))
 	return err
 }
diff --git a/pkg/cmd/run_test.go b/pkg/cmd/run_test.go
index 46c032bc0..be71a8425 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/run_test.go
@@ -677,69 +677,3 @@ func TestMissingTrait(t *testing.T) {
 	assert.Equal(t, "Error: bogus.fail=i-must-fail is not a valid trait property\n", output)
 	assert.NotNil(t, err)
 }
-
-func TestGetsPaths(t *testing.T) {
-	tests := []struct {
-		path       string
-		localPath  string
-		remotePath string
-		os         string
-		isAbs      bool
-	}{
-		{
-			path:       "C:\\USER\\HOME\\:remote/path",
-			localPath:  "C:\\USER\\HOME\\",
-			remotePath: "remote/path",
-			os:         "windows",
-			isAbs:      true,
-		},
-		{
-			path:       "src\\main\\resources:remote/path",
-			localPath:  "src\\main\\resources",
-			remotePath: "remote/path",
-			os:         "windows",
-		},
-		{
-			path:       "C:\\USER\\HOME\\",
-			localPath:  "C:\\USER\\HOME\\",
-			remotePath: "",
-			os:         "windows",
-			isAbs:      true,
-		},
-		{
-			path:       "src\\main\\resources",
-			localPath:  "src\\main\\resources",
-			remotePath: "",
-			os:         "windows",
-		},
-		{
-			path:       "/home/user/name/dir:/remote/path",
-			localPath:  "/home/user/name/dir",
-			remotePath: "/remote/path",
-			os:         "linux",
-			isAbs:      true,
-		}, {
-			path:       "/home/user/name/dir",
-			localPath:  "/home/user/name/dir",
-			remotePath: "",
-			os:         "linux",
-			isAbs:      true,
-		}, {
-			path:       "src/main/resources:remote/path",
-			localPath:  "src/main/resources",
-			remotePath: "remote/path",
-			os:         "linux",
-		}, {
-			path:       "src/main/resources",
-			localPath:  "src/main/resources",
-			remotePath: "",
-			os:         "linux",
-		},
-	}
-	for _, test := range tests {
-		localPath, targetPath := getPaths(test.path, test.os, test.isAbs)
-		assert.Equal(t, test.localPath, localPath)
-		assert.Equal(t, test.remotePath, targetPath)
-
-	}
-}


[camel-k] 03/03: feat(cli): Add option to skip uploading POM from JAR when uploading artifacts to the image registry

Posted by jp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jpoth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit f5e39aaa4dcf97ce9ef9fd4e0d8517ca0a35f61f
Author: John Poth <po...@gmail.com>
AuthorDate: Tue May 24 09:31:40 2022 +0200

    feat(cli): Add option to skip uploading POM from JAR  when uploading artifacts to the image registry
---
 e2e/registry/registry_maven_wagon_test.go |  2 +-
 pkg/cmd/run.go                            | 16 ++++++++++++----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/e2e/registry/registry_maven_wagon_test.go b/e2e/registry/registry_maven_wagon_test.go
index 7a978d46d..4abebc239 100644
--- a/e2e/registry/registry_maven_wagon_test.go
+++ b/e2e/registry/registry_maven_wagon_test.go
@@ -50,7 +50,7 @@ func TestImageRegistryIsAMavenRepository(t *testing.T) {
 		t.Run("image registry is a maven repository", func(t *testing.T) {
 			// Create integration that should decrypt an encrypted message to "foobar" and log it
 			name := "foobar-decryption"
-			jar, err := filepath.Abs("files/sample-decryption-1.0.jar")
+			jar, err := filepath.Abs("files/sample-decryption-1.0.jar?skipPOM=true")
 			assert.Nil(t, err)
 			pom, err := filepath.Abs("files/sample-decryption-1.0.pom")
 			assert.Nil(t, err)
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 04f342665..ae9e3384c 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -96,7 +96,7 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *runCmdOptions)
 
 	cmd.Flags().String("name", "", "The integration name")
 	cmd.Flags().StringArrayP("connect", "c", nil, "A Service that the integration should bind to, specified as [[apigroup/]version:]kind:[namespace/]name")
-	cmd.Flags().StringArrayP("dependency", "d", nil, "A dependency that should be included, e.g., \"-d camel-mail\" for a Camel component, \"-d mvn:org.my:app:1.0\" for a Maven dependency or \"file://localPath[?targetPath=<path>&registry=<registry URL>&skipChecksums=<true>]\" for local files (experimental)")
+	cmd.Flags().StringArrayP("dependency", "d", nil, "A dependency that should be included, e.g., \"-d camel-mail\" for a Camel component, \"-d mvn:org.my:app:1.0\" for a Maven dependency or \"file://localPath[?targetPath=<path>&registry=<registry URL>&skipChecksums=<true>&skipPOM=<true>]\" for local files (experimental)")
 	cmd.Flags().BoolP("wait", "w", false, "Wait for the integration to be running")
 	cmd.Flags().StringP("kit", "k", "", "The kit used to run the integration")
 	cmd.Flags().StringArrayP("property", "p", nil, "Add a runtime property or properties file (syntax: [my-key=my-value|file:/path/to/my-conf.properties])")
@@ -829,6 +829,10 @@ func (o *runCmdOptions) skipChecksums() bool {
 	return o.RegistryOptions.Get("skipChecksums") == "true"
 }
 
+func (o *runCmdOptions) skipPom() bool {
+	return o.RegistryOptions.Get("skipPOM") == "true"
+}
+
 func (o *runCmdOptions) getTargetPath() string {
 	return o.RegistryOptions.Get("targetPath")
 }
@@ -925,9 +929,13 @@ func (o *runCmdOptions) uploadPomFromJar(gav maven.Dependency, path string, plat
 			}
 		}
 		if pomExtracted {
-			gav.Type = "pom"
-			// Swallow error as this is not a mandatory step
-			o.uploadAsMavenArtifact(gav, pomPath, platform, ns, options, cmd)
+			if o.skipPom() {
+				o.PrintfVerboseOutf(cmd, "Skipping uploading extracted POM from %s \n", path)
+			} else {
+				gav.Type = "pom"
+				// Swallow error as this is not a mandatory step
+				o.uploadAsMavenArtifact(gav, pomPath, platform, ns, options, cmd)
+			}
 		}
 		return nil
 	})