Skip to content

Commit

Permalink
[KOGITO-9729] SonataFlow builder image is not preserving resources pa…
Browse files Browse the repository at this point in the history
…th (#1677)

* [KOGITO-9729] SonataFlow builder image is not preserving resources path

Signed-off-by: Davide Salerno <[email protected]>

* [KOGITO-9729] Added shell test

Signed-off-by: Davide Salerno <[email protected]>

* Update modules/kogito-swf/common/scripts/added/build-app.sh

Co-authored-by: Tristan Radisson <[email protected]>

* [KOGITO-9729] Stopping containers into the same shell test

Signed-off-by: Davide Salerno <[email protected]>

---------

Signed-off-by: Davide Salerno <[email protected]>
Co-authored-by: Tristan Radisson <[email protected]>
  • Loading branch information
davidesalerno and radtriste authored Sep 27, 2023
1 parent 9ad98ac commit 5fac5e9
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 5 deletions.
2 changes: 1 addition & 1 deletion modules/kogito-swf/common/scripts/added/build-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fi
SUPPORTED_FILES=(".yaml" ".yml" ".json" ".properties" ".mvn/jvm.config")
log_info "-> Copying files from ${resources_path}, if any..."
if [ ! -z "${resources_path}" ]; then
find "${resources_path}" -regex '.*\.\(yaml\|yml\|json\|properties\)$' -exec cp -v {} src/main/resources/ \;
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/ \;
else
log_warning "-> Nothing to copy from ${resources_path}"
Expand Down
34 changes: 30 additions & 4 deletions tests/shell/kogito-swf-builder/RunTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ public class RunTests {
private Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(LOGGER);

@Container
private GenericContainer builtImage = new GenericContainer(
private GenericContainer greetBuiltImage = new GenericContainer(
new ImageFromDockerfile("dev.local/jbang-test/swf-test:" + Math.round(Math.random() * 1000000.00))
.withDockerfile(Paths.get(getScriptDirPath(), "resources", "Dockerfile"))
.withDockerfile(Paths.get(getScriptDirPath(), "resources/greet", "Dockerfile"))
.withBuildArg("BUILDER_IMAGE_TAG", getTestImage()))
.withExposedPorts(8080)
.waitingFor(Wait.forHttp("/jsongreet"))
.withLogConsumer(logConsumer);

@Test
public void testBuiltContainerAnswerCorrectly() throws URISyntaxException, IOException, InterruptedException {
builtImage.start();
greetBuiltImage.start();
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI("http://" + builtImage.getHost() + ":" + builtImage.getFirstMappedPort() + "/jsongreet"))
.uri(new URI("http://" + greetBuiltImage.getHost() + ":" + greetBuiltImage.getFirstMappedPort() + "/jsongreet"))
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.timeout(Duration.ofSeconds(10))
Expand All @@ -67,6 +67,32 @@ public void testBuiltContainerAnswerCorrectly() throws URISyntaxException, IOExc
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, BodyHandlers.ofString());
assertEquals(201, response.statusCode());
greetBuiltImage.stop();
}

@Container
private GenericContainer greetWithInputSchemaBuiltImage = new GenericContainer(
new ImageFromDockerfile("dev.local/jbang-test/swf-test:" + Math.round(Math.random() * 1000000.00))
.withDockerfile(Paths.get(getScriptDirPath(), "resources/greet-with-inputschema", "Dockerfile"))
.withBuildArg("BUILDER_IMAGE_TAG", getTestImage()))
.withExposedPorts(8080)
.waitingFor(Wait.forHttp("/greeting"))
.withLogConsumer(logConsumer);

@Test
public void testBuiltContainerWithInputSchemaAnswerCorrectly() throws URISyntaxException, IOException, InterruptedException {
greetWithInputSchemaBuiltImage.start();
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI("http://" + greetWithInputSchemaBuiltImage.getHost() + ":" + greetWithInputSchemaBuiltImage.getFirstMappedPort() + "/greeting"))
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.timeout(Duration.ofSeconds(10))
.POST(HttpRequest.BodyPublishers
.ofString("{\"name\": \"John\", \"language\": \"English\"}"))
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, BodyHandlers.ofString());
assertEquals(201, response.statusCode());
greetWithInputSchemaBuiltImage.stop();
}

public static void main(String... args) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
ARG BUILDER_IMAGE_TAG="quay.io/kiegroup/kogito-swf-builder:2.0"

FROM ${BUILDER_IMAGE_TAG} AS builder

# Kogito user
USER 1001

ARG QUARKUS_PACKAGE_TYPE="jar"
ARG SCRIPT_DEBUG="true"
ARG MAVEN_DOWNLOAD_OUTPUT="true"
ARG MAVEN_OFFLINE_MODE="true"

# Copy from build context to resources directory
COPY ./ ./resources/

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

#=============================
# Runtime Run
#=============================
FROM registry.access.redhat.com/ubi8/openjdk-11-runtime:latest

ARG QUARKUS_LAUNCH_DEVMODE=false

ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'
# Default name is 'serverless-workflow-project'
ARG PROJECT_ARTIFACT_ID='serverless-workflow-project'

# 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/${PROJECT_ARTIFACT_ID}/target/quarkus-app/lib/ /deployments/lib/
COPY --from=builder --chown=185 /home/kogito/${PROJECT_ARTIFACT_ID}/target/quarkus-app/*.jar /deployments/
COPY --from=builder --chown=185 /home/kogito/${PROJECT_ARTIFACT_ID}/target/quarkus-app/app/ /deployments/app/
COPY --from=builder --chown=185 /home/kogito/${PROJECT_ARTIFACT_ID}/target/quarkus-app/quarkus/ /deployments/quarkus/

EXPOSE 8080
USER 185
ENV AB_JOLOKIA_OFF=""
ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Dquarkus.http.port=8080 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"id": "greeting",
"description": "Greeting example on k8s!",
"version": "0.0.1",
"start": {
"stateName": "ChooseOnLanguage"
},
"dataInputSchema": {
"schema": "schemas/input.json",
"failOnValidationErrors": true
},
"specVersion": "0.8",
"expressionLang": "jq",
"states": [
{
"name": "ChooseOnLanguage",
"type": "switch",
"defaultCondition": {
"transition": {
"nextState": "GreetInEnglish"
}
},
"dataConditions": [
{
"condition": "${ .language == \"English\" }",
"transition": {
"nextState": "GreetInEnglish"
}
},
{
"condition": "${ .language == \"Spanish\" }",
"transition": {
"nextState": "GreetInSpanish"
}
}
]
},
{
"name": "GreetInEnglish",
"type": "inject",
"transition": {
"nextState": "GreetPerson"
},
"data": {
"greeting": "Hello from JSON Workflow, "
}
},
{
"name": "GreetInSpanish",
"type": "inject",
"transition": {
"nextState": "GreetPerson"
},
"data": {
"greeting": "Saludos desde JSON Workflow, "
}
},
{
"name": "GreetPerson",
"type": "operation",
"end": {
"terminate": true
},
"actionMode": "sequential",
"actions": [
{
"name": "greetAction",
"functionRef": {
"refName": "greetFunction",
"arguments": {
"message": ".greeting+.name"
},
"invoke": "sync"
},
"actionDataFilter": {
"useResults": true
}
}
]
}
],
"functions": [
{
"name": "greetFunction",
"operation": "sysout",
"type": "custom"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"language": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"language",
"name"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Xms1024m

0 comments on commit 5fac5e9

Please sign in to comment.