Skip to content

Commit

Permalink
[KOGITO-9729] - (fix) Preserve directory structure while copying file…
Browse files Browse the repository at this point in the history
…s in builder image (#1711)

Signed-off-by: Ricardo Zanini <[email protected]>
  • Loading branch information
ricardozanini committed Dec 1, 2023
1 parent 5fac5e9 commit a7f997b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
14 changes: 9 additions & 5 deletions modules/kogito-swf/common/scripts/added/build-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

script_dir_path="$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)"
resources_path="$1"
if [ ! -z "${resources_path}" ]; then
if [ -n "${resources_path}" ]; then
resources_path="$(realpath "${resources_path}")"
fi

Expand All @@ -13,15 +13,17 @@ if [ "${SCRIPT_DEBUG}" = "true" ] ; then
set -x
export MAVEN_ARGS_APPEND="${MAVEN_ARGS_APPEND} -X --batch-mode"
log_info "Script debugging is enabled, allowing bash commands and their arguments to be printed as they are executed"
log_info "Resources path is ${resources_path}"
printenv
fi

# Copy resources if exists
SUPPORTED_FILES=(".yaml" ".yml" ".json" ".properties" ".mvn/jvm.config")
log_info "-> Copying files from ${resources_path}, if any..."
if [ ! -z "${resources_path}" ]; then
cd "${resources_path}" && find . -regex '.*\.\(yaml\|yml\|json\|properties\)$' | sed 's|^./||' | xargs cp -v --parents -t "${swf_home_dir}"/src/main/resources/ && cd -
find "${resources_path}" -name 'jvm.config' -exec echo "--> found {}" \; -exec mkdir -p .mvn \; -exec cp -v {} .mvn/ \;
if [ -n "${resources_path}" ]; then
destination="${KOGITO_HOME}/serverless-workflow-project/src/main/resources/"
log_info "-> Destination folder is ${destination}"
cp -vR ${resources_path}/* ${destination}
find "${resources_path}" -name 'jvm.config' -exec echo "--> found {}" \; -exec mkdir -p ${destination}/.mvn \; -exec cp -v {} ${destination}/.mvn/ \;
else
log_warning "-> Nothing to copy from ${resources_path}"
fi
Expand All @@ -33,6 +35,8 @@ if [ ! -z "${QUARKUS_EXTENSIONS}" ]; then
${script_dir_path}/add-extension.sh "${QUARKUS_EXTENSIONS}" "true"
fi

cd ${KOGITO_HOME}/serverless-workflow-project

"${MAVEN_HOME}"/bin/mvn -B ${MAVEN_ARGS_APPEND} \
-nsu \
-s "${MAVEN_SETTINGS_PATH}" \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bats

setup() {
export KOGITO_HOME=/tmp/kogito
export HOME="${KOGITO_HOME}"
mkdir -p "${KOGITO_HOME}"/launch
mkdir -p "${KOGITO_HOME}"/serverless-workflow-project/src/main/resources/
cp $BATS_TEST_DIRNAME/../../../../../kogito-logging/added/logging.sh "${KOGITO_HOME}"/launch/
cp $BATS_TEST_DIRNAME/../../added/jvm-settings.sh "${KOGITO_HOME}"/launch/
cp $BATS_TEST_DIRNAME/../../added/build-app.sh "${KOGITO_HOME}"/launch/
}

teardown() {
rm -rf "${KOGITO_HOME}"
rm -rf /tmp/resources
}

@test "verify copy resources is working" {
TEMPD=$(mktemp -d)
cp -r $BATS_TEST_DIRNAME/../../../../../../tests/shell/kogito-swf-builder/resources/greet-with-inputschema/* ${TEMPD}

# 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

[[ -f "${KOGITO_HOME}"/serverless-workflow-project/src/main/resources/greet.sw.json ]]
[[ -f "${KOGITO_HOME}"/serverless-workflow-project/src/main/resources/schemas/input.json ]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ARG MAVEN_DOWNLOAD_OUTPUT="true"
ARG MAVEN_OFFLINE_MODE="true"

# Copy from build context to resources directory
COPY ./ ./resources/
COPY --chown=1001 . ./resources

# Build app with given resources
RUN "${KOGITO_HOME}"/launch/build-app.sh './resources'
Expand Down
2 changes: 1 addition & 1 deletion tests/shell/kogito-swf-builder/resources/greet/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ARG MAVEN_DOWNLOAD_OUTPUT="true"
ARG MAVEN_OFFLINE_MODE="true"

# Copy from build context to resources directory
COPY * ./resources/
COPY --chown=1001 . ./resources

# Build app with given resources
RUN "${KOGITO_HOME}"/launch/build-app.sh './resources'
Expand Down

0 comments on commit a7f997b

Please sign in to comment.