You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "squakez (via GitHub)" <gi...@apache.org> on 2023/05/03 15:00:00 UTC

[GitHub] [camel-k] squakez commented on a diff in pull request #4315: feat(#1656) : jib poc basic integration use case

squakez commented on code in PR #4315:
URL: https://github.com/apache/camel-k/pull/4315#discussion_r1183808568


##########
pkg/util/maven/maven_command.go:
##########
@@ -240,6 +245,11 @@ func generateProjectStructure(context Context, project Project) error {
 	return nil
 }
 
+// Create a MAVEN_CONTEXT file containing all arguments for a maven command
+func generateMavenContext(context Context, args []string) error {
+	return util.WriteToFile(filepath.Join(context.Path, "MAVEN_CONTEXT"), strings.Join(args, " "))

Review Comment:
   What is this doing?



##########
pkg/builder/jib.go:
##########
@@ -0,0 +1,175 @@
+/*
+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 builder
+
+import (
+	"context"
+	"io/ioutil"
+	"os"
+	"os/exec"
+	"path/filepath"
+	"strings"
+
+	v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
+	"github.com/apache/camel-k/v2/pkg/client"
+	"github.com/apache/camel-k/v2/pkg/util"
+	"github.com/apache/camel-k/v2/pkg/util/log"
+)
+
+type jibTask struct {
+	c     client.Client
+	build *v1.Build
+	task  *v1.JibTask
+}
+
+var _ Task = &jibTask{}
+
+var (
+	logger = log.WithName("jib")
+
+	loggerInfo  = func(s string) string { logger.Info(s); return "" }
+	loggerError = func(s string) string { logger.Error(nil, s); return "" }
+)
+
+func (t *jibTask) Do(ctx context.Context) v1.BuildStatus {
+	status := v1.BuildStatus{}
+
+	baseImage := t.build.Status.BaseImage
+	if baseImage == "" {
+		baseImage = t.task.BaseImage
+		status.BaseImage = baseImage
+	}
+
+	contextDir := t.task.ContextDir
+	if contextDir == "" {
+		// Use the working directory.
+		// This is useful when the task is executed in-container,
+		// so that its WorkingDir can be used to share state and
+		// coordinate with other tasks.
+		pwd, err := os.Getwd()
+		if err != nil {
+			return status.Failed(err)
+		}
+		contextDir = filepath.Join(pwd, ContextDir)
+	}
+
+	exists, err := util.DirectoryExists(contextDir)
+	if err != nil {
+		return status.Failed(err)
+	}
+	empty, err := util.DirectoryEmpty(contextDir)
+	if err != nil {
+		return status.Failed(err)
+	}
+	if !exists || empty {
+		// this can only indicate that there are no more resources to add to the base image,
+		// because transitive resolution is the same even if spec differs.
+		log.Infof("No new image to build, reusing existing image %s", baseImage)
+		status.Image = baseImage
+		return status
+	}
+	mavenDir := strings.ReplaceAll(contextDir, "context", "maven")
+
+	pullInsecure := t.task.Registry.Insecure // incremental build case
+
+	if !strings.HasPrefix(baseImage, t.task.Registry.Address) {
+		if pullInsecure {
+			log.Info("Assuming secure pull because the registry for the base image and the main registry are different")
+			pullInsecure = false
+		}
+	}
+
+	registryConfigDir := ""
+	if t.task.Registry.Secret != "" {
+		registryConfigDir, err = MountSecret(ctx, t.c, t.build.Namespace, t.task.Registry.Secret)
+		if err != nil {
+			return status.Failed(err)
+		}
+	}
+
+	if registryConfigDir != "" {
+		if err := os.RemoveAll(registryConfigDir); err != nil {
+			return status.Failed(err)
+		}
+	}
+
+	// Then do poc actions for jib
+	log.Infof("Registry address: %s", t.task.Registry.Address)
+	log.Infof("Base image: %s", baseImage)
+
+	/*mavenPom, errPom := readFile(mavenDir + "/pom.xml")
+	if errPom != nil {
+		return status.Failed(errPom)
+	}
+	log.Info(string(mavenPom))*/
+
+	mavenCommand, err := readFile(mavenDir + "/MAVEN_CONTEXT")
+	if err != nil {
+		return status.Failed(err)
+	}
+	log.Info(string(mavenCommand))
+
+	// ugly replaces

Review Comment:
   Just use `fmt.Sprintf` and I think should be fine.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org