From 86fedf86dfe0971c1d0cfe73760a456f5f15180f Mon Sep 17 00:00:00 2001 From: Roy Golan Date: Wed, 28 Feb 2024 22:14:38 +0200 Subject: [PATCH] WIP: swf-builder generate manifests using kn-workflow Generate manifests and save them in the runtime image. Generating manifests is an opt-in as part of the build ran by /launch/build-app.sh When setting GEN_MANIFESTS=true during container build the build-app.sh script will call a new generate-manifests.sh script that will use _kn-workflow_ cli and will store the manifests under $KOGITO_HOME/build/manifests Later in the runtime image user can copy and store those manifests for later use: COPY --from=builder --chown=185 /home/kogito/build/manifests /deployments/manifests The manifests can be extracted for example by echoing them from the image: podman run builder:latest cat /deployment/manifests/* > manifests-all.yaml or by podman cp: podman cp $(podman create builder:latest):/deployment/manifests . Signed-off-by: Roy Golan --- kogito-swf-builder-image.yaml | 2 + .../common/scripts/added/build-app.sh | 2 + .../added/generate-manifests.sh | 29 ++++++++ modules/kogito-workflow-manifests/configure | 28 +++++++ modules/kogito-workflow-manifests/install.sh | 23 ++++++ modules/kogito-workflow-manifests/module.yaml | 35 +++++++++ .../tests/bats/kogito-workflow-manifest.bats | 74 +++++++++++++++++++ 7 files changed, 193 insertions(+) create mode 100755 modules/kogito-workflow-manifests/added/generate-manifests.sh create mode 100644 modules/kogito-workflow-manifests/configure create mode 100644 modules/kogito-workflow-manifests/install.sh create mode 100644 modules/kogito-workflow-manifests/module.yaml create mode 100644 modules/kogito-workflow-manifests/tests/bats/kogito-workflow-manifest.bats diff --git a/kogito-swf-builder-image.yaml b/kogito-swf-builder-image.yaml index 5749630e2..ee0a707f1 100644 --- a/kogito-swf-builder-image.yaml +++ b/kogito-swf-builder-image.yaml @@ -68,7 +68,9 @@ - name: org.kie.kogito.project.versions - name: org.kie.kogito.swf.common.scripts - name: org.kie.kogito.swf.builder.runtime.community + - name: org.kie.kogito.workflow-manifests run: workdir: "/home/kogito/${PROJECT_ARTIFACT_ID}" user: 1001 + diff --git a/modules/kogito-swf/common/scripts/added/build-app.sh b/modules/kogito-swf/common/scripts/added/build-app.sh index c85927c4b..2158d7982 100755 --- a/modules/kogito-swf/common/scripts/added/build-app.sh +++ b/modules/kogito-swf/common/scripts/added/build-app.sh @@ -62,3 +62,5 @@ cd ${KOGITO_HOME}/serverless-workflow-project -DskipTests \ -Dquarkus.container-image.build=false \ clean install + +"${script_dir_path}"/generate-manifests.sh "${resources_path}" diff --git a/modules/kogito-workflow-manifests/added/generate-manifests.sh b/modules/kogito-workflow-manifests/added/generate-manifests.sh new file mode 100755 index 000000000..b409ceda7 --- /dev/null +++ b/modules/kogito-workflow-manifests/added/generate-manifests.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# +# 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. +# +set -x +resource_dir="${1:-${KOGITO_HOME}/serverless-workflow-project/src/main/resources}" +target_dir="${KOGITO_HOME}/build/manifests" +if [ "${GEN_MANIFESTS}" = "true" ]; then + # kn-workflow doesn't support source dir yet, we have to get in + pushd "${resource_dir}" || exit + kn-workflow gen-manifest --custom-generated-manifests-dir "${target_dir}" --namespace "" + popd || exit +fi + diff --git a/modules/kogito-workflow-manifests/configure b/modules/kogito-workflow-manifests/configure new file mode 100644 index 000000000..60cb313ab --- /dev/null +++ b/modules/kogito-workflow-manifests/configure @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# +# 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. +# +# +set -x + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +cp -v "${SCRIPT_DIR}"/added/* "${KOGITO_HOME}"/launch + +chown -R 1001:0 "${KOGITO_HOME}"/launch +chmod -R ug+rwX "${KOGITO_HOME}"/launch diff --git a/modules/kogito-workflow-manifests/install.sh b/modules/kogito-workflow-manifests/install.sh new file mode 100644 index 000000000..bcb816b66 --- /dev/null +++ b/modules/kogito-workflow-manifests/install.sh @@ -0,0 +1,23 @@ +#!/bin/sh +# +# 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. +# +set -x + +cp /tmp/artifacts/kn-workflow-"$(uname --machine)" /usr/local/bin/kn-workflow +chmod +x-w /usr/local/bin/kn-workflow diff --git a/modules/kogito-workflow-manifests/module.yaml b/modules/kogito-workflow-manifests/module.yaml new file mode 100644 index 000000000..30f1cda7c --- /dev/null +++ b/modules/kogito-workflow-manifests/module.yaml @@ -0,0 +1,35 @@ +# +# 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. +# +schema_version: 1 +name: org.kie.kogito.workflow-manifests +version: "999-SNAPSHOT" +description: Module to install kn-workflow tool and scripts +execute: + - script: configure +envs: + - name: KN_CLI + value: /usr/local/bin/kn-workflow + - name: GEN_MANIFESTS + value: false + +artifacts: + - name: kn-workflow-x86_64 + url: https://github.com/rgolangh/kie-tools/releases/download/0.0.2/kn-workflow-linux-amd64 + md5: defdb771fd65d47c0255fd4389127656 + script: install.sh diff --git a/modules/kogito-workflow-manifests/tests/bats/kogito-workflow-manifest.bats b/modules/kogito-workflow-manifests/tests/bats/kogito-workflow-manifest.bats new file mode 100644 index 000000000..90fcf24cc --- /dev/null +++ b/modules/kogito-workflow-manifests/tests/bats/kogito-workflow-manifest.bats @@ -0,0 +1,74 @@ +#!/usr/bin/env bats +# +# 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. +# + + +setup() { + export KOGITO_HOME=/tmp/kogito + export HOME="${KOGITO_HOME}" + mkdir -p "${KOGITO_HOME}"/launch + mock_bin kn-workflow + mkdir -p "${KOGITO_HOME}"/serverless-workflow-project/src/main/resources/schemas + + touch "${KOGITO_HOME}"/launch/configure-jvm-mvn.sh + cp $BATS_TEST_DIRNAME/../../added/generate-manifests.sh "${KOGITO_HOME}"/launch/ + cp $BATS_TEST_DIRNAME/../../../kogito-logging/added/logging.sh "${KOGITO_HOME}"/launch/ + cp $BATS_TEST_DIRNAME/../../../kogito-swf/common/scripts/added/build-app.sh "${KOGITO_HOME}"/launch/ +} + +teardown() { + rm -rf "${KOGITO_HOME}" + rm -rf /tmp/resources +} + +@test "verify generate manifest is working" { + TEMPD=$(mktemp -d) + cp -r $BATS_TEST_DIRNAME/../../../../tests/shell/kogito-swf-builder/resources/greet-with-inputschema/* ${TEMPD} + + # opt-in to generate-manifests + export GEN_MANIFESTS=true + # We don't care about the errors to try to execute and build the program, just the copy matters + source ${KOGITO_HOME}/launch/build-app.sh ${TEMPD} || true + + # this tests the call to kn-workflow actually happend + [ -f "${KOGITO_HOME}"/bin/kn-workflow_invocation.txt ] +} + +@test "verify generate manifest is an opt-in" { + TEMPD=$(mktemp -d) + cp -r $BATS_TEST_DIRNAME/../../../../tests/shell/kogito-swf-builder/resources/greet-with-inputschema/* ${TEMPD} + + # opt-out to generate-manifests + export GEN_MANIFESTS=false + # We don't care about the errors to try to execute and build the program, just the copy matters + source ${KOGITO_HOME}/launch/build-app.sh ${TEMPD} || true + + # this tests that the call to kn-workflow didn't happend + [ ! -f "${KOGITO_HOME}"/bin/kn-workflow_invocation.txt ] +} + +mock_bin() { + mkdir -p "${KOGITO_HOME}"/bin + PATH+=":${KOGITO_HOME}/bin/" + cat << EOF > "${KOGITO_HOME}"/bin/$1 + echo $1 "$@" > $"${KOGITO_HOME}"/bin/$1_invocation.txt +EOF + chmod +x "${KOGITO_HOME}"/bin/$1 +} +