Skip to content

Commit

Permalink
[KOGITO-705] - Refactor data-index image in the same way kogito-jobs-…
Browse files Browse the repository at this point in the history
…service image is structured

Signed-off-by: Filippe Spolti <fspolti@redhat.com>
  • Loading branch information
spolti committed Dec 19, 2019
1 parent 77aa968 commit 1c256d4
Show file tree
Hide file tree
Showing 16 changed files with 206 additions and 223 deletions.
2 changes: 1 addition & 1 deletion s2i/image.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
schema_version: 1

name: "kogito-image-real-name-on-overrides-file"
version: "0.6.1"
version: "0.7.0-rc1"
# until this issue is not fixed use 8.0 tag.
# https://github.com/rpm-software-management/microdnf/issues/50
# https://bugzilla.redhat.com/show_bug.cgi?id=1769831
Expand Down
31 changes: 8 additions & 23 deletions s2i/kogito-data-index-overrides.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,22 @@ labels:
- name: "io.openshift.expose-services"
value: "8080:http"

envs:
- name: "INFINISPAN_USEAUTH"
value: "false"
description: "Flag that signals to Infinispan Hotrod client to use authentication (Used to set the infinispan.client.hotrod.use_auth system property)"
- name: "INFINISPAN_USERNAME"
value: ""
description: "Username for the user credential used by the Hotrod client (Used to set the infinispan.client.hotrod.auth_username system property)"
- name: "INFINISPAN_PASSWORD"
value: ""
description: "Password for the user credential used by the Hotrod client (Used to set the infinispan.client.hotrod.auth_password system property)"
- name: "INFINISPAN_AUTHREALM"
value: ""
description: "Infinispan authentication realm (Used to set the infinispan.client.hotrod.auth_realm system property)"
- name: "INFINISPAN_SASLMECHANISM"
value: ""
description: "Sasl mechanism to use during authentication. Example: PLAIN (Used to set the infinispan.client.hotrod.sasl_mechanism system property)"

ports:
- value: 8080

modules:
install:
- name: org.kie.kogito.image.dependencies
- name: org.kie.kogito.system.user
- name: org.kie.kogito.openjdk
version: "1.8.0-headless"
- name: org.kie.kogito.launch.scripts
- name: org.kie.kogito.infinispan.properties
- name: org.kie.kogito.dataindex

packages:
install:
- java-1.8.0-openjdk

run:
workdir: "/home/kogito/"
user: 1001
cmd:
- "/home/kogito/bin/start"
cmd:
- "/home/kogito/kogito-app-launch.sh"

21 changes: 21 additions & 0 deletions s2i/modules/kogito-data-index/added/kogito-app-launch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

if [ "${SCRIPT_DEBUG}" = "true" ] ; then
set -x
SHOW_JVM_SETTINGS="-XshowSettings:properties"
echo "Script debugging is enabled, allowing bash commands and their arguments to be printed as they are executed"
echo "JVM settings debug is enabled."
fi


# Configuration scripts
# Any configuration script that needs to run on image startup must be added here.
CONFIGURE_SCRIPTS=(
${KOGITO_HOME}/launch/kogito-infinispan-properties.sh
)
source ${KOGITO_HOME}/launch/configure.sh
#############################################

exec java ${SHOW_JVM_SETTINGS} ${JAVA_OPTIONS} ${INFINISPAN_PROPERTIES}-Djava.library.path=$KOGITO_HOME/lib \
-Dquarkus.http.host=0.0.0.0 -Dquarkus.http.port=8080 \
-jar $KOGITO_HOME/bin/kogito-data-index-runner.jar
48 changes: 0 additions & 48 deletions s2i/modules/kogito-data-index/added/start

This file was deleted.

8 changes: 6 additions & 2 deletions s2i/modules/kogito-data-index/configure
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ SOURCES_DIR=/tmp/artifacts
SCRIPT_DIR=$(dirname $0)
ADDED_DIR=${SCRIPT_DIR}/added

mv ${SOURCES_DIR}/data-index-service-*-runner.jar ${KOGITO_HOME}/bin/
mv ${ADDED_DIR}/* ${KOGITO_HOME}/bin/
cp -v ${SOURCES_DIR}/kogito-data-index-runner.jar ${KOGITO_HOME}/bin/

chown -R 1001:0 ${KOGITO_HOME}
chmod -R ug+rwX ${KOGITO_HOME}


cp -v ${ADDED_DIR}/kogito-app-launch.sh ${KOGITO_HOME}
chmod +x-w ${KOGITO_HOME}/kogito-app-launch.sh

2 changes: 1 addition & 1 deletion s2i/modules/kogito-data-index/module.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: org.kie.kogito.dataindex
version: "0.6.1"

artifacts:
- name: data-index-service-0.6.1-runner.jar
- name: kogito-data-index-runner.jar
url: https://repository.jboss.org/org/kie/kogito/data-index-service/0.6.1/data-index-service-0.6.1-runner.jar
md5: ec8de0f37fc6e51137121e80ea112627

Expand Down
101 changes: 101 additions & 0 deletions s2i/modules/kogito-data-index/tests/bats/kogito-data-index.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env bats

export KOGITO_HOME=/tmp/kogito
export HOME=$KOGITO_HOME
mkdir -p ${KOGITO_HOME}/launch
cp $BATS_TEST_DIRNAME/../../../kogito-infinispan-properties/added/kogito-infinispan-properties.sh ${KOGITO_HOME}/launch/

load ${KOGITO_HOME}/launch/kogito-infinispan-properties.sh

teardown() {
rm -rf ${KOGITO_HOME}
}

function clear_vars() {
unset INFINISPAN_USEAUTH
unset INFINISPAN_USERNAME
unset INFINISPAN_PASSWORD
unset INFINISPAN_AUTHREALM
unset INFINISPAN_SASLMECHANISM
}

@test "check if infinispan properties is blank" {
clear_vars
local expected=""
configure_infinispan_props
echo "Result is ${INFINISPAN_PROPERTIES} and expected is ${expected}" >&2
[ "${expected}" = "${INFINISPAN_PROPERTIES}" ]
}


@test "check if infinispan auth is false" {
clear_vars
export INFINISPAN_USEAUTH="false"
local expected=" -Dquarkus.infinispan-client.use-auth=false"
configure_infinispan_props
echo "Result is ${INFINISPAN_PROPERTIES} and expected is ${expected}" >&2
[ "${expected}" = "${INFINISPAN_PROPERTIES}" ]
}

@test "check if infinispan has auth props" {
clear_vars
export INFINISPAN_USERNAME="developer"
export INFINISPAN_USEAUTH="true"
export INFINISPAN_PASSWORD="developer"
export INFINISPAN_AUTHREALM="default"
export INFINISPAN_SASLMECHANISM="PLAIN"

local expected=" -Dquarkus.infinispan-client.auth-username=developer -Dquarkus.infinispan-client.auth-password=developer -Dquarkus.infinispan-client.use-auth=true -Dquarkus.infinispan-client.auth-realm=default -Dquarkus.infinispan-client.sasl-mechanism=PLAIN"
configure_infinispan_props

echo "Result is ${INFINISPAN_PROPERTIES} and expected is ${expected}" >&2
[ "${expected}" = "${INFINISPAN_PROPERTIES}" ]
}

@test "setting username, useauth is true" {
clear_vars
export INFINISPAN_USERNAME="developer"
export INFINISPAN_USEAUTH="false"
local expected=" -Dquarkus.infinispan-client.auth-username=developer -Dquarkus.infinispan-client.use-auth=true"

configure_infinispan_props

echo "Result is ${INFINISPAN_PROPERTIES} and expected is ${expected}" >&2
[ "${expected}" = "${INFINISPAN_PROPERTIES}" ]
}

@test "when use auth is set to nonsense and no credentials" {
clear_vars
export INFINISPAN_USEAUTH="dsadsadasdsa"
local expected=" -Dquarkus.infinispan-client.use-auth=false"

configure_infinispan_props

echo "Result is ${INFINISPAN_PROPERTIES} and expected is ${expected}" >&2
[ "${expected}" = "${INFINISPAN_PROPERTIES}" ]
}

@test "when use auth is set to nonsense and has credentials" {
clear_vars
export INFINISPAN_USEAUTH="dsadsadasdsa"
export INFINISPAN_USERNAME="developer"
local expected=" -Dquarkus.infinispan-client.auth-username=developer -Dquarkus.infinispan-client.use-auth=true"

configure_infinispan_props

echo "Result is ${INFINISPAN_PROPERTIES} and expected is ${expected}" >&2
[ "${expected}" = "${INFINISPAN_PROPERTIES}" ]
}

@test "when use auth is set to true and no credentials" {
clear_vars
export INFINISPAN_USEAUTH="true"

run configure_infinispan_props

expected="[ERROR] Flag INFINISPAN_USEAUTH set to true, but no username or password informed. Please use INFINISPAN_USERNAME and INFINISPAN_PASSWORD variables to set the right credentials."
echo "Result is ${output} and expected is ${expected}"
echo "Expected status is 1, outcome status is ${status}"
[ "$status" -eq 1 ]
[ "${output}" = "${expected}" ]
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
#!/bin/bash -e

function prepareEnv() {
# keep it on alphabetical order
unset INFINISPAN_AUTHREALM
unset INFINISPAN_PASSWORD
unset INFINISPAN_SASLMECHANISM
unset INFINISPAN_USEAUTH
unset INFINISPAN_USERNAME
}

function configure() {
configure_infinispan_props
}


# see https://quarkus.io/guides/infinispan-client-guide#quarkus-infinispan-client_configuration
function set_infinispan_props() {
function configure_infinispan_props() {
local infinispan_props=""

if [[ "${INFINISPAN_USEAUTH}" == "true" ]] && [[ -z "${INFINISPAN_USERNAME}" || -z "${INFINISPAN_PASSWORD}" ]]; then
Expand All @@ -21,6 +35,6 @@ function set_infinispan_props() {
if [ ! -z "${INFINISPAN_AUTHREALM}" ]; then infinispan_props=$(echo "${infinispan_props} -Dquarkus.infinispan-client.auth-realm=${INFINISPAN_AUTHREALM}"); fi
if [ ! -z "${INFINISPAN_SASLMECHANISM}" ]; then infinispan_props=$(echo "${infinispan_props} -Dquarkus.infinispan-client.sasl-mechanism=${INFINISPAN_SASLMECHANISM}"); fi

echo $infinispan_props
INFINISPAN_PROPERTIES="${infinispan_props}"
}

Loading

0 comments on commit 1c256d4

Please sign in to comment.