Skip to content

Commit

Permalink
swf-builder generate manifests using kn-workflow
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rgolangh committed Mar 3, 2024
1 parent ce62b9d commit a649be2
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 0 deletions.
2 changes: 2 additions & 0 deletions kogito-swf-builder-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 2 additions & 0 deletions modules/kogito-swf/common/scripts/added/build-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
29 changes: 29 additions & 0 deletions modules/kogito-workflow-manifests/added/generate-manifests.sh
Original file line number Diff line number Diff line change
@@ -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

30 changes: 30 additions & 0 deletions modules/kogito-workflow-manifests/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/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

cp /tmp/artifacts/kn-workflow-"$(uname --machine)" /usr/local/bin/kn-workflow
chmod +x-w /usr/local/bin/kn-workflow

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
34 changes: 34 additions & 0 deletions modules/kogito-workflow-manifests/module.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# 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
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit a649be2

Please sign in to comment.