Skip to content

Commit

Permalink
WIP: 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 e419825
Show file tree
Hide file tree
Showing 7 changed files with 193 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

28 changes: 28 additions & 0 deletions modules/kogito-workflow-manifests/configure
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions modules/kogito-workflow-manifests/install.sh
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions modules/kogito-workflow-manifests/module.yaml
Original file line number Diff line number Diff line change
@@ -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
sha256: 1fac4ceea4e5b39587c4423c59eb4ee6cfe957a48e73a97ffcc02e4a5d2ad5b5
script: install.sh
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 e419825

Please sign in to comment.