This is an automated email from the ASF dual-hosted git repository.
ricardozanini pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-tools.git
The following commit(s) were added to refs/heads/main by this push:
new b6658df8b9f kie-issues#3112 [kn-workflow] Provide an option to
generate build resources for gitop… (#3144)
b6658df8b9f is described below
commit b6658df8b9f187c0c5fdecfc6517a640d823823f
Author: Dmitrii Tikhomirov <[email protected]>
AuthorDate: Mon Jun 30 12:26:57 2025 -0700
kie-issues#3112 [kn-workflow] Provide an option to generate build resources
for gitop… (#3144)
---
packages/kn-plugin-workflow/Makefile | 5 +-
packages/kn-plugin-workflow/env/index.js | 8 ++-
packages/kn-plugin-workflow/package.json | 3 +-
packages/kn-plugin-workflow/pkg/command/create.go | 63 +++++++++++++++++++---
.../kn-plugin-workflow/pkg/command/gen_manifest.go | 24 +--------
.../template/SonataFlow-Builder.containerfile | 57 ++++++++++++++++++++
packages/kn-plugin-workflow/pkg/common/checks.go | 20 +++++++
.../metadata/{devModeImage.go => builderImage.go} | 9 ++--
.../pkg/metadata/devModeImage.go | 7 ++-
pnpm-lock.yaml | 3 ++
10 files changed, 156 insertions(+), 43 deletions(-)
diff --git a/packages/kn-plugin-workflow/Makefile
b/packages/kn-plugin-workflow/Makefile
index 69a8a377243..c88439b9282 100644
--- a/packages/kn-plugin-workflow/Makefile
+++ b/packages/kn-plugin-workflow/Makefile
@@ -29,9 +29,10 @@ METADATA_PATH :=
github.com/apache/incubator-kie-tools/packages/
SET_QUARKUS_PLATFORM_GROUP_ID :=
$(METADATA_PATH).QuarkusPlatformGroupId=$(QUARKUS_PLATFORM_GROUP_ID)
SET_QUARKUS_VERSION :=
$(METADATA_PATH).QuarkusVersion=$(QUARKUS_VERSION)
SET_DEV_MODE_IMAGE :=
$(METADATA_PATH).DevModeImage=$(DEV_MODE_IMAGE_URL)
+SET_BUILDER_IMAGE :=
$(METADATA_PATH).BuilderImage=$(BUILD_IMAGE_URL)
SET_VERSION :=
$(METADATA_PATH).PluginVersion=$(PLUGIN_VERSION)
SET_KOGITO_VERSION :=
$(METADATA_PATH).KogitoVersion=$(KOGITO_VERSION)
-LDFLAGS := "-X $(SET_QUARKUS_PLATFORM_GROUP_ID) -X
$(SET_QUARKUS_VERSION) -X $(SET_VERSION) -X $(SET_DEV_MODE_IMAGE) -X
$(SET_KOGITO_VERSION)"
+LDFLAGS := "-X $(SET_QUARKUS_PLATFORM_GROUP_ID) -X
$(SET_QUARKUS_VERSION) -X $(SET_VERSION) -X $(SET_DEV_MODE_IMAGE) -X
$(SET_KOGITO_VERSION) -X $(SET_BUILDER_IMAGE)"
KIND_VERSION ?= v0.20.0
OLM_VERSION = v0.31.0
@@ -98,4 +99,4 @@ go-test-e2e-report:
go run github.com/jstemmer/go-junit-report/v2 \
-set-exit-code \
-in ./dist-tests-e2e/go-test-output-e2e.txt \
- -out ./dist-tests-e2e/junit-report-it.xml
\ No newline at end of file
+ -out ./dist-tests-e2e/junit-report-it.xml
diff --git a/packages/kn-plugin-workflow/env/index.js
b/packages/kn-plugin-workflow/env/index.js
index a6ec7558357..d8c3e3684dc 100644
--- a/packages/kn-plugin-workflow/env/index.js
+++ b/packages/kn-plugin-workflow/env/index.js
@@ -21,8 +21,9 @@ const { varsWithName, getOrDefault, composeEnv } =
require("@kie-tools-scripts/b
const packageJson = require("@kie-tools/kn-plugin-workflow/package.json");
const rootEnv = require("@kie-tools/root-env/env");
const sonataflowDevModeImageEnv =
require("@kie-tools/sonataflow-devmode-image/env");
+const sonataflowBuilderImageEnv =
require("@kie-tools/sonataflow-builder-image/env");
-module.exports = composeEnv([rootEnv, sonataflowDevModeImageEnv], {
+module.exports = composeEnv([rootEnv, sonataflowBuilderImageEnv,
sonataflowDevModeImageEnv], {
vars: varsWithName({
KN_PLUGIN_WORKFLOW__version: {
name: "KN_PLUGIN_WORKFLOW__version",
@@ -38,6 +39,10 @@ module.exports = composeEnv([rootEnv,
sonataflowDevModeImageEnv], {
default:
`${sonataflowDevModeImageEnv.env.sonataflowDevModeImage.registry}/${sonataflowDevModeImageEnv.env.sonataflowDevModeImage.account}/${sonataflowDevModeImageEnv.env.sonataflowDevModeImage.name}:${sonataflowDevModeImageEnv.env.sonataflowDevModeImage.buildTag}`,
description: "Kogito SWF DevMode image URL.",
},
+ KN_PLUGIN_WORKFLOW__sonataflowBuilderImage: {
+ default:
`${sonataflowBuilderImageEnv.env.sonataflowBuilderImage.registry}/${sonataflowBuilderImageEnv.env.sonataflowBuilderImage.account}/${sonataflowBuilderImageEnv.env.sonataflowBuilderImage.name}:${sonataflowBuilderImageEnv.env.sonataflowBuilderImage.buildTag}`,
+ description: "Sonataflow Builder image",
+ },
}),
get env() {
return {
@@ -45,6 +50,7 @@ module.exports = composeEnv([rootEnv,
sonataflowDevModeImageEnv], {
version: getOrDefault(this.vars.KN_PLUGIN_WORKFLOW__version),
quarkusPlatformGroupId:
getOrDefault(this.vars.KN_PLUGIN_WORKFLOW__quarkusPlatformGroupId),
devModeImageUrl:
getOrDefault(this.vars.KN_PLUGIN_WORKFLOW__devModeImageUrl),
+ builderImage:
getOrDefault(this.vars.KN_PLUGIN_WORKFLOW__sonataflowBuilderImage),
},
};
},
diff --git a/packages/kn-plugin-workflow/package.json
b/packages/kn-plugin-workflow/package.json
index 3adfb267afd..fab1fa2e164 100644
--- a/packages/kn-plugin-workflow/package.json
+++ b/packages/kn-plugin-workflow/package.json
@@ -39,7 +39,7 @@
"go:test-e2e:report": "go run github.com/jstemmer/go-junit-report/v2
-set-exit-code -in ./dist-tests-e2e/go-test-output-e2e.txt -out
./dist-tests-e2e/junit-report-it.xml",
"install": "go mod tidy",
"powershell": "@powershell -NoProfile -ExecutionPolicy Unrestricted
-Command",
- "setup:env": "cross-env QUARKUS_PLATFORM_GROUP_ID=$(build-env
knPluginWorkflow.quarkusPlatformGroupId) QUARKUS_VERSION=$(build-env
versions.quarkus) PLUGIN_VERSION=$(build-env knPluginWorkflow.version)
DEV_MODE_IMAGE_URL=$(build-env knPluginWorkflow.devModeImageUrl)
KOGITO_VERSION=$(build-env versions.kogito)",
+ "setup:env": "cross-env QUARKUS_PLATFORM_GROUP_ID=$(build-env
knPluginWorkflow.quarkusPlatformGroupId) QUARKUS_VERSION=$(build-env
versions.quarkus) PLUGIN_VERSION=$(build-env knPluginWorkflow.version)
DEV_MODE_IMAGE_URL=$(build-env knPluginWorkflow.devModeImageUrl)
BUILD_IMAGE_URL=$(build-env knPluginWorkflow.builderImage)
KOGITO_VERSION=$(build-env versions.kogito)",
"setup:env:win32": "pnpm powershell \"cross-env
QUARKUS_PLATFORM_GROUP_ID=$(build-env knPluginWorkflow.quarkusPlatformGroupId)
QUARKUS_VERSION=$(build-env versions.quarkus) DEV_MODE_IMAGE_URL=$(build-env
knPluginWorkflow.devModeImageUrl) KOGITO_VERSION=$(build-env versions.kogito)
PLUGIN_VERSION=$(build-env knPluginWorkflow.version)\"",
"test": "run-script-if --ignore-errors \"$(build-env
tests.ignoreFailures)\" --bool \"$(build-env tests.run)\" --then \"pnpm
go:test\" \"pnpm go:test:report\"",
"test-e2e": "run-script-if --ignore-errors \"$(build-env
endToEndTests.ignoreFailures)\" --bool \"$(build-env endToEndTests.run)\"
--then \"make test-e2e\"",
@@ -56,6 +56,7 @@
},
"devDependencies": {
"@kie-tools/root-env": "workspace:*",
+ "@kie-tools/sonataflow-builder-image": "workspace:*",
"@kie-tools/sonataflow-devmode-image": "workspace:*",
"@kie-tools/sonataflow-operator": "workspace:*",
"cross-env": "^7.0.3",
diff --git a/packages/kn-plugin-workflow/pkg/command/create.go
b/packages/kn-plugin-workflow/pkg/command/create.go
index fb7e952e0ae..8f1bc4ea571 100644
--- a/packages/kn-plugin-workflow/pkg/command/create.go
+++ b/packages/kn-plugin-workflow/pkg/command/create.go
@@ -20,17 +20,23 @@
package command
import (
+ "bytes"
+ _ "embed"
"fmt"
+ "os"
+ "path"
+ "text/template"
+
"github.com/apache/incubator-kie-tools/packages/kn-plugin-workflow/pkg/common"
"github.com/apache/incubator-kie-tools/packages/kn-plugin-workflow/pkg/metadata"
"github.com/ory/viper"
"github.com/spf13/cobra"
- "os"
)
type CreateCmdConfig struct {
- ProjectName string
- YAML bool
+ ProjectName string
+ YAML bool
+ WithPersistence bool
}
func NewCreateCommand() *cobra.Command {
@@ -67,9 +73,13 @@ func NewCreateCommand() *cobra.Command {
# Creates a YAML sample workflow file (JSON is default)
{{.Name}} create --yaml-workflow
+
+ # Add Dockerfile with persistence support to the project (default:
false)
+ {{.Name}} create --with-persistence
+
`,
SuggestFor: []string{"vreate", "creaet", "craete", "new"},
//nolint:misspell
- PreRunE: common.BindEnv("name", "yaml-workflow"),
+ PreRunE: common.BindEnv("name", "yaml-workflow",
"with-persistence"),
}
cmd.RunE = func(cmd *cobra.Command, args []string) error {
@@ -82,11 +92,15 @@ func NewCreateCommand() *cobra.Command {
cmd.Flags().StringP("name", "n", "new-project", "Project name created
in the current directory.")
cmd.Flags().Bool("yaml-workflow", false, "Create a sample YAML workflow
file.")
+ cmd.Flags().BoolP("with-persistence", "w", false, "Add persistence
support to the project (default: false)")
cmd.SetHelpFunc(common.DefaultTemplatedHelp)
return cmd
}
+//go:embed template/SonataFlow-Builder.containerfile
+var SonataFlowBuilderContainerFile string
+
func runCreate(cfg CreateCmdConfig) error {
fmt.Println("🛠️ Creating SonataFlow project")
@@ -105,7 +119,12 @@ func runCreate(cfg CreateCmdConfig) error {
if err := common.CreateWorkflow(workflowPath, cfg.YAML); err != nil {
return fmt.Errorf("❌ ERROR: Error creating workflow file: %w",
err)
}
-
+ if cfg.WithPersistence {
+ err := addGitOpsDockerFile(cfg)
+ if err != nil {
+ return fmt.Errorf("❌ ERROR: Error creating Dockerfile
for gitops profile: %w", err)
+ }
+ }
fmt.Println("🎉 SonataFlow project successfully created")
return nil
@@ -115,8 +134,38 @@ func runCreate(cfg CreateCmdConfig) error {
func runCreateCmdConfig() (cfg CreateCmdConfig, err error) {
cfg = CreateCmdConfig{
- ProjectName: viper.GetString("name"),
- YAML: viper.GetBool("yaml-workflow"),
+ ProjectName: viper.GetString("name"),
+ YAML: viper.GetBool("yaml-workflow"),
+ WithPersistence: viper.GetBool("with-persistence"),
}
return cfg, nil
}
+
+func addGitOpsDockerFile(cfg CreateCmdConfig) error {
+ data := struct {
+ BuildImage string
+ }{
+ BuildImage: metadata.BuilderImage,
+ }
+
+ tmpl, err :=
template.New("dockerfile").Parse(SonataFlowBuilderContainerFile)
+ if err != nil {
+ return fmt.Errorf("error parsing Dockerfile template: %w", err)
+ }
+
+ var rendered bytes.Buffer
+ if err := tmpl.Execute(&rendered, data); err != nil {
+ return fmt.Errorf("error executing Dockerfile template: %w",
err)
+ }
+
+ dockerfilePath := path.Join(cfg.ProjectName, "Dockerfile.gitops")
+ file, err := os.Create(dockerfilePath)
+ if err != nil {
+ return fmt.Errorf("error creating Dockerfile %s: %w",
dockerfilePath, err)
+ }
+ defer file.Close()
+ if _, err := file.WriteString(rendered.String()); err != nil {
+ return fmt.Errorf("error writing to Dockerfile %s: %w",
dockerfilePath, err)
+ }
+ return nil
+}
diff --git a/packages/kn-plugin-workflow/pkg/command/gen_manifest.go
b/packages/kn-plugin-workflow/pkg/command/gen_manifest.go
index 93b8ae96826..a068b8193dd 100644
--- a/packages/kn-plugin-workflow/pkg/command/gen_manifest.go
+++ b/packages/kn-plugin-workflow/pkg/command/gen_manifest.go
@@ -23,11 +23,9 @@ import (
"fmt"
"os"
"path/filepath"
- "strings"
"github.com/apache/incubator-kie-tools/packages/kn-plugin-workflow/pkg/common"
"github.com/apache/incubator-kie-tools/packages/kn-plugin-workflow/pkg/metadata"
- apiMetadata
"github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/metadata"
"github.com/ory/viper"
"github.com/spf13/cobra"
)
@@ -140,7 +138,7 @@ func runGenManifestCmdConfig(cmd *cobra.Command) (cfg
DeployUndeployCmdConfig, e
if cmd.Flags().Changed("profile") && len(cfg.Profile) == 0 {
profile, _ := cmd.Flags().GetString("profile")
- if err := isValidProfile(profile); err != nil {
+ if err := common.IsValidProfile(profile); err != nil {
return cfg, err
}
cfg.Profile = profile
@@ -233,23 +231,3 @@ func resolveManifestDir(folderName string) (string, error)
{
return absPath, nil
}
-
-func isValidProfile(profile string) error {
- var allProfiles = []apiMetadata.ProfileType{
- apiMetadata.DevProfile,
- apiMetadata.ProdProfile,
- apiMetadata.PreviewProfile,
- apiMetadata.GitOpsProfile,
- }
-
- for _, t := range allProfiles {
- if t.String() == profile {
- return nil
- }
- }
- keys := make([]string, 0, len(allProfiles))
- for k := range allProfiles {
- keys = append(keys, allProfiles[k].String())
- }
- return fmt.Errorf("❌ ERROR: invalid profile: %s, valid profiles are:
%s", profile, strings.Join(keys, ","))
-}
diff --git
a/packages/kn-plugin-workflow/pkg/command/template/SonataFlow-Builder.containerfile
b/packages/kn-plugin-workflow/pkg/command/template/SonataFlow-Builder.containerfile
new file mode 100644
index 00000000000..7f5eb567037
--- /dev/null
+++
b/packages/kn-plugin-workflow/pkg/command/template/SonataFlow-Builder.containerfile
@@ -0,0 +1,57 @@
+# 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.
+
+FROM {{ .BuildImage }} AS builder
+
+# variables that can be overridden by the builder
+# To add a Quarkus extension to your application
+ARG QUARKUS_EXTENSIONS
+ENV
QUARKUS_EXTENSIONS="${QUARKUS_EXTENSIONS:-org.kie:kie-addons-quarkus-persistence-jdbc,io.quarkus:quarkus-jdbc-postgresql,io.quarkus:quarkus-agroal}"
+# Args to pass to the Quarkus CLI add extension command
+ARG QUARKUS_ADD_EXTENSION_ARGS
+# Additional java/mvn arguments to pass to the builder
+ARG MAVEN_ARGS_APPEND
+ENV MAVEN_ARGS_APPEND="${MAVEN_ARGS_APPEND:-} \
+ -DmaxYamlCodePoints=35000000 \
+ -Dkogito.persistence.type=jdbc \
+ -Dquarkus.datasource.db-kind=postgresql \
+ -Dkogito.persistence.proto.marshaller=false"
+
+# Copy from build context to skeleton resources project
+COPY --chown=1001 . ./resources
+
+RUN /home/kogito/launch/build-app.sh ./resources
+
+#=============================
+# Runtime Run
+#=============================
+FROM registry.access.redhat.com/ubi9/openjdk-17-runtime:latest
+
+ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'
+
+# We make four distinct layers so if there are application changes the library
layers can be re-used
+COPY --from=builder --chown=185
/home/kogito/serverless-workflow-project/target/quarkus-app/lib/
/deployments/lib/
+COPY --from=builder --chown=185
/home/kogito/serverless-workflow-project/target/quarkus-app/*.jar /deployments/
+COPY --from=builder --chown=185
/home/kogito/serverless-workflow-project/target/quarkus-app/app/
/deployments/app/
+COPY --from=builder --chown=185
/home/kogito/serverless-workflow-project/target/quarkus-app/quarkus/
/deployments/quarkus/
+
+EXPOSE 8080
+USER 185
+
+ENV AB_JOLOKIA_OFF=""
+ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0
-Djava.util.logging.manager=org.jboss.logmanager.LogManager"
+ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"
diff --git a/packages/kn-plugin-workflow/pkg/common/checks.go
b/packages/kn-plugin-workflow/pkg/common/checks.go
index 785bdae4cf1..694cdd863c9 100644
--- a/packages/kn-plugin-workflow/pkg/common/checks.go
+++ b/packages/kn-plugin-workflow/pkg/common/checks.go
@@ -30,6 +30,7 @@ import (
"strings"
"github.com/apache/incubator-kie-tools/packages/kn-plugin-workflow/pkg/metadata"
+ apiMetadata
"github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/metadata"
"github.com/docker/docker/client"
)
@@ -197,3 +198,22 @@ func CheckProjectName(name string) (err error) {
}
return
}
+
+func IsValidProfile(profile string) error {
+ var allProfiles = []apiMetadata.ProfileType{
+ apiMetadata.DevProfile,
+ apiMetadata.PreviewProfile,
+ apiMetadata.GitOpsProfile,
+ }
+
+ for _, t := range allProfiles {
+ if t.String() == profile {
+ return nil
+ }
+ }
+ keys := make([]string, 0, len(allProfiles))
+ for k := range allProfiles {
+ keys = append(keys, allProfiles[k].String())
+ }
+ return fmt.Errorf("❌ ERROR: invalid profile: %s, valid profiles are:
%s", profile, strings.Join(keys, ","))
+}
diff --git a/packages/kn-plugin-workflow/pkg/metadata/devModeImage.go
b/packages/kn-plugin-workflow/pkg/metadata/builderImage.go
similarity index 93%
copy from packages/kn-plugin-workflow/pkg/metadata/devModeImage.go
copy to packages/kn-plugin-workflow/pkg/metadata/builderImage.go
index d499c2057f3..725b1a6eeca 100644
--- a/packages/kn-plugin-workflow/pkg/metadata/devModeImage.go
+++ b/packages/kn-plugin-workflow/pkg/metadata/builderImage.go
@@ -6,18 +6,17 @@
* 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.
+ * under the License.
*/
package metadata
-var DevModeImage string
-
+var BuilderImage string
diff --git a/packages/kn-plugin-workflow/pkg/metadata/devModeImage.go
b/packages/kn-plugin-workflow/pkg/metadata/devModeImage.go
index d499c2057f3..3beb686fd8b 100644
--- a/packages/kn-plugin-workflow/pkg/metadata/devModeImage.go
+++ b/packages/kn-plugin-workflow/pkg/metadata/devModeImage.go
@@ -6,18 +6,17 @@
* 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.
+ * under the License.
*/
package metadata
var DevModeImage string
-
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 752cd57c133..5bb0cf5ae3e 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -7343,6 +7343,9 @@ importers:
'@kie-tools/root-env':
specifier: workspace:*
version: link:../root-env
+ '@kie-tools/sonataflow-builder-image':
+ specifier: workspace:*
+ version: link:../sonataflow-builder-image
'@kie-tools/sonataflow-devmode-image':
specifier: workspace:*
version: link:../sonataflow-devmode-image
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]