diff --git a/serverless-workflow-examples/pom.xml b/serverless-workflow-examples/pom.xml index f9760817fa..26dfba64a6 100644 --- a/serverless-workflow-examples/pom.xml +++ b/serverless-workflow-examples/pom.xml @@ -38,6 +38,7 @@ serverless-workflow-functions-events-quarkus serverless-workflow-functions-quarkus serverless-workflow-funqy + serverless-workflow-github-showcase serverless-workflow-greeting-quarkus serverless-workflow-greeting-rpc-quarkus serverless-workflow-hello-world diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/README.md b/serverless-workflow-examples/serverless-workflow-github-showcase/README.md index db2a5c4904..d5c11e4e4f 100644 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/README.md +++ b/serverless-workflow-examples/serverless-workflow-github-showcase/README.md @@ -1,8 +1,3 @@ -**DEPRECATION NOTICE** - -> This example has a few old concepts from architecture and integration perspective. [We are working on an updated version of this example](https://issues.redhat.com/browse/KOGITO-8169). Until there, please try our other examples in this directory. -> In case you still need to run it, latest Kogito version which worked was KOGITO 1.29.0.Final. - ## Serverless Workflow GitHub Showcase In this example we will deploy a GitHub "bot" application that will @@ -29,23 +24,6 @@ notify a given channel. ### Prerequisites -> **IMPORTANT!** Before proceeding, please make sure you have everything listed in this section ready. - -You may use CRC or Minikube if you don't have a cluster available with cluster admin rights. -Or you can ask an administrator to install the prerequisites for you. - -To deploy this example in your Kubernetes/OpenShift cluster, you will need: - -1. A [Quay.io](https://quay.io/repository/) account -2. A Kubernetes/OpenShift namespace to deploy the example: `kubectl create ns kogito-github` or `oc new-project kogito-github -3. [**Istio**](https://istio.io/docs/setup/install/istioctl/) installed because it's [required by Knative platform](https://knative.dev/docs/install/). -You can follow the [Knative documentation](https://knative.dev/docs/install/serving/installing-istio/) for a very basic and simple installation. -4. **Knative** Serving and Eventing components installed. -We recommend [installing the Knative Operator](https://knative.dev/docs/install/knative-with-operators/) and install the rest of the components -through it as described in their documentation. -5. **Kogito Operator** installed in the namespace `kogito-github`. [Download the latest release](https://github.com/kiegroup/kogito-operator/releases), and run: `NAMESPACE=kogito-github ./hack/install.sh`. -Alternatively, you can also install it via [OperatorHub](https://operatorhub.io/operator/kogito-operator). - In your local machine you will need: 1. To clone this repository and go to `serverless-workflow-github-showcase` directory (`git clone https://github.com/kiegroup/kogito-examples.git && cd serverless-workflow-github-showcase`) @@ -54,6 +32,40 @@ In your local machine you will need: 4. [Podman](https://podman.io/getting-started/installation.html) or Docker to build the images 5. `kubectl` or `oc` client +## Deploying on Minikube + +You can easily deploy this example on Minikube by using the provided `deploy.sh` script. But first, make sure that you have: + +1. Installed Minikube +2. Installed [Knative Quickstart](https://knative.dev/docs/getting-started/quickstart-install/) on your Minikube installation. It adds a new `knative` profile to your cluster, so bear in mind that every command on Minikube must be followed by `-p knative`. +3. Installed JDK 11, Maven, NPM, and Docker in order to build all the parts of the example. + +### Minimum Requirements + +- Minikube with at least 4 CPU cores +- Minikube RAM of 12GB + +Start the tunnel in a separate terminal: + +```shell +minikube tunnel -p knative +``` + +Now just run `./deploy.sh`. It will build all the services, create the Kubernetes object, and push the images to your Minikube's internal registry. + + +Once the services are deployed, discover the URLs managed by Knative: + +```shell +$ kubectl get ksvc -n github-showcase +NAME URL LATESTCREATED LATESTREADY READY REASON +event-display http://event-display.github-showcase.10.101.75.92.sslip.io event-display-00001 event-display-00001 True +github-service http://github-service.github-showcase.10.101.75.92.sslip.io github-service-00001 github-service-00001 True +notification-service http://notification-service.github-showcase.10.101.75.92.sslip.io notification-service-00001 notification-service-00001 True +pr-checker-flow http://pr-checker-flow.github-showcase.10.101.75.92.sslip.io pr-checker-flow-00001 pr-checker-flow-00001 True +``` + + ### Deploying the examples Follow the instructions for each service to try them locally as standalone services @@ -72,13 +84,5 @@ In case of any problems, please file an issue or reach out to us at the [Kogito You can easily clean up the demo by deleting the namespace: ```shell script -kubectl delete ns kogito-github -``` - -To clean up your `/etc/hosts` file, run the following script: - -```shell script -./scripts/cleanup-hosts-file.sh -``` - -It will remove all the lines added by the `expose-on-minikube.sh` script while deploying the services. \ No newline at end of file +kubectl delete ns github-showcase +``` \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/deploy.sh b/serverless-workflow-examples/serverless-workflow-github-showcase/deploy.sh new file mode 100755 index 0000000000..713e04e9fe --- /dev/null +++ b/serverless-workflow-examples/serverless-workflow-github-showcase/deploy.sh @@ -0,0 +1,123 @@ +#!/bin/bash + +# Build every project using docker +# configure the ports as: +# - flow:8080 +# - aggregator: 8181 +# - credit-bureau: 8282 +# - ui: 8383 +# - bank1: 8484 (we will have only one bank since we can't broadcast the message locally) +# the connectivity between the images works like this: +# flow -> credit-bureau -> flow -> bank1 -> aggregator -> flow -> aggregator -> flow -> ui + +# every image must name ko.local/loanbroker- + +# build the flow +# cd loanbroker-flow +# mvn clean install -DskipTests +# docker run --rm -it -p 8080:8080 -e K_SINK=http://localhost:8383 dev.local/loanbroker-aggregator + +# build credit bureau +# no need of any additional env variable or setup +# cd credit-bureau +# kn func build --image dev.local/loanbroker-credit-bureau +# docker run --rm -it -p 8181:8080 dev.local/loanbroker-credit-bureau + +# build the aggregator +# cd aggregator +# mvn clean install -DskipTests +# docker run --rm -it -p 8282:8080 -e K_SINK=http://localhost:8080 dev.local/loanbroker-aggregator + +# build the UI +# cd loanbroker-ui +# mvn clean install -DskipTests +# docker run --rm -it -p 8383:8080 dev.local/loanbroker-ui + +# build the banks +# cd banks +# kn func build --image dev.local/loanbroker-bank +# docker run --rm -it -p 8484:8080 --env-file=bank1.env dev.local/loanbroker-bank +# docker run --rm -it -p 8585:8080 --env-file=bank2.env dev.local/loanbroker-bank +# docker run --rm -it -p 8686:8080 --env-file=bank3.env dev.local/loanbroker-bank + +SKIP_BUILD=$1 +DEPLOY_LOG=deploy.log +# remember to change in kubernetes.yml +NAMESPACE=github-showcase + +print_build_header() { + PROJ=$1 + echo -e "*********** IMAGE BUILD LOG $PROJ ***********\n" >> ../$DEPLOY_LOG + echo "Building image for project $PROJ" +} + +print_build_footer() { + PROJ=$1 + RETURN_CODE=$2 + if [ $RETURN_CODE -gt 0 ] + then + echo "Image build for $PROJ failed" >&2 + exit 1 + fi + echo -e "\n" >> ../$DEPLOY_LOG +} + +apply_kube() { + YAML_FILE=$1 + NAME=$2 + echo "*********** CREATING $NAME k8s OBJECTS ***********\n" >> ../$DEPLOY_LOG + echo "Creating k8s $NAME" + kubectl apply -n $NAMESPACE -f $YAML_FILE >> $DEPLOY_LOG + RETURN_CODE=$? + if [ "${RETURN_CODE}" -gt 0 ] + then + echo "Failed to create $NAME objects" >&2 + exit 1 + fi + echo -e "\n" >> $DEPLOY_LOG +} +expose_pr_checker_workflow() { + echo "Exposing flow, please run 'minikube tunnel -p knative' in a separate terminal" + DEPLOYMENT=$(kubectl get deployment --selector=serving.knative.dev/service=pr-checker-flow -n github-showcase | awk 'NR==2{print $1}') + kubectl expose deployment $DEPLOYMENT --name=pr-checker-flow-external --type=LoadBalancer --port=8080 -n ${NAMESPACE} +} + +expose_github_service() { + echo "Exposing flow, please run 'minikube tunnel -p knative' in a separate terminal" + DEPLOYMENT=$(kubectl get deployment --selector=serving.knative.dev/service=github-service -n github-showcase | awk 'NR==2{print $1}') + kubectl expose deployment $DEPLOYMENT --name=github-service-external --type=LoadBalancer --port=8080 -n ${NAMESPACE} +} + +expose_notification_service() { + echo "Exposing flow, please run 'minikube tunnel -p knative' in a separate terminal" + DEPLOYMENT=$(kubectl get deployment --selector=serving.knative.dev/service=notification-service -n github-showcase | awk 'NR==2{print $1}') + kubectl expose deployment $DEPLOYMENT --name=notification-service-external --type=LoadBalancer --port=8080 -n ${NAMESPACE} +} + +rm -rf $DEPLOY_LOG + +if [ "$SKIP_BUILD" != true ] +then + echo "Setting Docker Env to Minikube" + eval $(minikube -p minikube docker-env --profile knative) + if [ $? -gt 0 ] + then + echo "Failed to set docker-env to minikube" >&2 + exit 1 + fi + echo "mvn -B clean install -Dquarkus.kubernetes.namespace=$NAMESPACE -DskipTests -Pknative >> ../$DEPLOY_LOG" +fi + +apply_kube "kubernetes/github-showcase-database.yml" "Database and Namespace" +apply_kube "kubernetes/jobs-service-postgresql.yml" "Kogito Jobs Service" +apply_kube "kubernetes/kubernetes.yml" "Event Display and triggers" +apply_kube "kubernetes/github-webhook-secret.yml" "Github webhook secret" +apply_kube "kubernetes/github-source.yml" "GithubSource" +apply_kube "github-service/target/kubernetes/knative.yml" "Github Service" +apply_kube "notification-service/target/kubernetes/knative.yml" "Notification Service" +apply_kube "pr-checker-workflow/target/kubernetes/knative.yml" "Flow Kogito Binding" +apply_kube "pr-checker-workflow/target/kubernetes/kogito.yml" "Flow Service" + +expose_pr_checker_workflow +expose_github_service +expose_notification_service diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/README.md b/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/README.md index d091f9d89b..9420059580 100644 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/README.md +++ b/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/README.md @@ -85,80 +85,32 @@ Then access the Swagger UI to play around with the API: http://localhost:8080/sw 1. Open a test PR to have some data to play with 2. Invite a friend to be a contributor to your repo, so you can make the service request for their review in the PRs :kissing: -### Deploying on Kubernetes +### Running on knative > **IMPORTANT! :warning:** we assume you have read the prerequisites section in the main > [README file](../README.md). Please follow those instructions before continuing. -**Heads up!** This service will be deployed as a Knative Service instead of a regular Kubernetes -Deployment. + Run `mvn clean install -Pknative` -To make things easier there is a [script in this directory](deploy-kubernetes.sh) to generate the template -files, build the application and the image, and then deploy it to your Kubernetes cluster. - -**IMPORTANT!** You **must** be authenticated to the target Kubernetes cluster as a **cluster administrator** for this script -to work. - -You can run the script once and all the required files will be generated in the `kubernetes` directory, -and the image will be published to your Quay.io account. - -Fill the value for the variables as shown below and run the script: - -```shell script -# the script accepts positional arguments as following: -QUAY_NAMESPACE= -APP_ID= -INSTALLATION_ID= -DER_FILE= - -./deploy-kubernetes.sh $QUAY_NAMESPACE $APP_ID $INSTALLATION_ID $DER_FILE -``` - -You should see a similar output like this: - -
Build logs -``` -// build logs surpressed ----> Building and pushing image using tag quay.io/ricardozanini/github-service:latest -STEP 1: FROM adoptopenjdk:11-jre-hotspot -STEP 2: RUN mkdir -p /opt/app/lib ---> Using cache 26183c5ad8a51a030030a250db0c99e649fdd9668ef4766d0b66782d0dad7573 -STEP 3: COPY target/github-service-2.0.0-SNAPSHOT-runner.jar /opt/app ---> 31bc2627d32 -STEP 4: COPY target/lib/*.jar /opt/app/lib ---> 62eae5cdde7 -STEP 5: CMD ["java", "-jar", "/opt/app/github-service-2.0.0-SNAPSHOT-runner.jar"] -STEP 6: COMMIT quay.io/ricardozanini/github-service:latest ---> 7c555a3060c -7c555a3060c666582824552d8824f2787b59b67b506fb933b171764bde894730 -Getting image source signatures -Copying config 7c555a3060 [--------------------------------------] 0.0b / 6.2KiB -Writing manifest to image destination -Writing manifest to image destination -Storing signatures ----> Applying objects to the cluster in the namespace kogito-github. -configmap/github-service-properties unchanged -secret/github-app-ids unchanged -secret/github-app-key unchanged -service.serving.knative.dev/github-service configured -``` -
+ Deploy the service with the following command: + ```shell + # install the github-service + $ kubectl apply -f github-service/target/kubernetes/knative.yml -n github-showcase + ``` To verify if the service have been correctly deployed run: ``` -$ kubectl get ksvc github-service -n kogito-github + $ kubectl get ksvc github-service -n github-showcase +NAME URL LATESTCREATED LATESTREADY READY REASON +github-service http://github-service.github-showcase.10.104.64.247.sslip.io github-service-00001 github-service-00001 True -NAME URL LATESTCREATED LATESTREADY READY REASON -github-service http://github-service.kogito-github.example.com github-service-7frvw github-service-7frvw True ``` - The `READY` column should be true. #### Exposing the service on Minikube -If you're running on another cluster than Minikube, the service's route exposed by Knative Serving probably is accessible to you. -On Minikube there are some additional steps to be made. +Execute the following command to expose the knative service Run a new terminal window: @@ -168,23 +120,22 @@ minikube tunnel Leave the process executing and then execute: -```shell script -./expose-on-minikube.sh +```shell + # expose the github-service + $ kubectl expose deployment github-service --name=github-service-external --type=LoadBalancer --port=8080 -n github-showcase ``` -This script will fetch the Minikube IP exposed by the `tunnel` command and add the route to your local `/etc/hosts` file. - You can then access the service via the service URL: ``` -$ kubectl get ksvc github-service -n kogito-github --output jsonpath="{.status.url}" +$ kubectl get ksvc github-service -n github-showcase --output jsonpath="{.status.url}" -http://github-service.kogito-github.example.com +http://github-service.github-showcase.10.104.64.247.sslip.io ``` As we did when running through the `jar` file, we can access the Swagger UI and play around with the API: -http://github-service.kogito-github.example.com/swagger-ui +http://github-service.github-showcase.10.104.64.247.sslip.io/q/swagger-ui The first query may take a little time to return since Knative will start the service's pod on demand. After some time the pod will just terminate. @@ -193,4 +144,4 @@ Congratulations! The GitHub functions is now available in the cluster ready to b ### Cleaning up! -See the project root's [README](./README.md) documentation. \ No newline at end of file +See the project root's [README](./README.md) documentation. diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/configure.sh b/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/configure.sh deleted file mode 100755 index 9ad2bcf03c..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/configure.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/bash -# Copyright 2020 Red Hat, Inc. and/or its affiliates -# -# Licensed 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. - -QUAY_NAMESPACE=$1 -APP_ID=$2 -INSTALLATION_ID=$3 -DER_FILE=$4 - -CURR_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -# shellcheck source=../scripts/common.sh -source "${CURR_DIR}/../scripts/common.sh" - -function print_usage() { - echo "---> Script to deploy the GitHub service to the Kubernetes cluster. Usage:" - echo "---> ./deploy-kubernetes.sh QUAY_NAMESPACE GITHUB_APP_ID INSTALLATION_ID PATH_FOR_DER_FILE" - echo "---> Example: " - echo "---> ./deploy-kubernetes.sh namespace 12345 56788 /path/to/the/private_key.der" -} - -function verify_input() { - local return_code=0 - if [ -z "${QUAY_NAMESPACE}" ]; then - echo "---> Quay namespace not set" - return_code=1 - fi - - if [ -z "${APP_ID}" ]; then - echo "---> GitHub Application ID not set" - return_code=1 - fi - - if [ -z "${INSTALLATION_ID}" ]; then - echo "---> GitHub Application Installation ID not set" - return_code=1 - fi - - if [ -z "${DER_FILE}" ]; then - echo "---> DER file not set" - return_code=1 - elif [ ! -f "${DER_FILE}" ]; then - echo "---> DER file ${DER_FILE} does not exist, make sure that the file informed is correct" - return_code=1 - fi - - return ${return_code} -} - -function apply_vars() { - cp ./kubernetes/apply_image_ns.yaml.tpl ./kubernetes/apply_image_ns.yaml - cp ./kubernetes/github-app.env.tpl ./kubernetes/github-app.env - - sed -i "s/{QUAY_NAMESPACE}/${QUAY_NAMESPACE}/g" ./kubernetes/apply_image_ns.yaml - sed -i "s/{APP_ID}/${APP_ID}/g" ./kubernetes/github-app.env - sed -i "s/{INSTALLATION_ID}/${INSTALLATION_ID}/g" ./kubernetes/github-app.env -} - -if ! verify_input; then - print_usage - exit -fi - -if ! check_binaries; then - echo "---> exiting installation script, not all required binaries have been found in your system" - exit -fi - -apply_vars - -# copy DER file -cp "${DER_FILE}" ./kubernetes/github-app-key.der diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/deploy-kubernetes.sh b/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/deploy-kubernetes.sh deleted file mode 100755 index 3687ff50a9..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/deploy-kubernetes.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -# Copyright 2020 Red Hat, Inc. and/or its affiliates -# -# Licensed 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. - -source ./configure.sh - -echo "---> Building application" -mvn clean install -DskipTests - -build_push_image "${QUAY_NAMESPACE}" "github-service" - -echo "---> Applying objects to the cluster in the namespace kogito-github." -kubectl apply -k ./kubernetes diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/expose-on-minikube.sh b/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/expose-on-minikube.sh deleted file mode 100755 index 7029b6c874..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/expose-on-minikube.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# Copyright 2020 Red Hat, Inc. and/or its affiliates -# -# Licensed 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. - -CURR_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -# shellcheck source=../scripts/add-route-to-hosts.sh -source "${CURR_DIR}/../scripts/add-route-to-hosts.sh" github-service diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/kubernetes/00-deployment.yaml b/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/kubernetes/00-deployment.yaml deleted file mode 100644 index 0a93e54ea6..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/kubernetes/00-deployment.yaml +++ /dev/null @@ -1,34 +0,0 @@ -apiVersion: serving.knative.dev/v1 # Current version of Knative (0.17.x) -kind: Service -metadata: - name: github-service -spec: - template: - spec: - containers: - - env: - - name: APP_ID - valueFrom: - secretKeyRef: - key: githubAppId - name: github-app-ids - - name: INSTALLATION_ID - valueFrom: - secretKeyRef: - key: githubInstallationId - name: github-app-ids - image: image_placeholder - volumeMounts: - - name: github-app-key - mountPath: "/opt/data" - readOnly: true - - name: properties - mountPath: "/config/application.properties" - subPath: application.properties - volumes: - - name: github-app-key - secret: - secretName: github-app-key - - name: properties - configMap: - name: github-service-properties \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/kubernetes/application.properties b/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/kubernetes/application.properties deleted file mode 100644 index 8276e150f4..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/kubernetes/application.properties +++ /dev/null @@ -1,3 +0,0 @@ -org.kogito.examples.sw.github.service.key=/opt/data/github-app-key.der -org.kogito.examples.sw.github.service.installation_id=${INSTALLATION_ID} -org.kogito.examples.sw.github.service.app_id=${APP_ID} \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/kubernetes/apply_image_ns.yaml.tpl b/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/kubernetes/apply_image_ns.yaml.tpl deleted file mode 100644 index 6b432c037f..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/kubernetes/apply_image_ns.yaml.tpl +++ /dev/null @@ -1,3 +0,0 @@ -- op: replace - path: /spec/template/spec/containers/0/image - value: quay.io/{QUAY_NAMESPACE}/github-service:latest \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/kubernetes/github-app.env.tpl b/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/kubernetes/github-app.env.tpl deleted file mode 100644 index 972a4ed45e..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/kubernetes/github-app.env.tpl +++ /dev/null @@ -1,2 +0,0 @@ -githubAppId={APP_ID} -githubInstallationId={INSTALLATION_ID} \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/kubernetes/kustomization.yaml b/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/kubernetes/kustomization.yaml deleted file mode 100644 index 0b2529c940..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/kubernetes/kustomization.yaml +++ /dev/null @@ -1,26 +0,0 @@ -namespace: kogito-github -resources: - - 00-deployment.yaml -patchesJson6902: - - path: apply_image_ns.yaml - target: - kind: Service - name: github-service - version: v1 - group: serving.knative.dev -generatorOptions: - disableNameSuffixHash: true - labels: - app: github-service -configMapGenerator: - - files: - - application.properties - name: github-service-properties -secretGenerator: - - env: github-app.env - name: github-app-ids - type: Opaque - - files: - - github-app-key.der - name: github-app-key - type: Opaque \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/pom.xml b/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/pom.xml index f7ba06c583..2288a12a79 100644 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/pom.xml +++ b/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/pom.xml @@ -10,13 +10,7 @@ github-service Kogito Example :: Serverless Workflow Github Showcase :: GitHub Service - true - 2.13.1.Final - quarkus-bom - io.quarkus - 2.13.1.Final - 3.8.1 - 11 + true @@ -46,6 +40,10 @@ io.quarkus quarkus-smallrye-openapi + + io.quarkus + quarkus-swagger-ui + io.jsonwebtoken @@ -101,19 +99,6 @@ - - io.smallrye - jandex-maven-plugin - ${jandex-plugin.version} - - - make-index - - jandex - - - - ${quarkus.platform.group-id} quarkus-maven-plugin @@ -130,6 +115,42 @@ + + native + + + native + + + + native + + + + knative + + + github-showcase + false + + ${namespace} + ${deploy} + true + knative + true + true + + + + io.quarkus + quarkus-kubernetes + + + io.quarkus + quarkus-container-image-jib + + + container @@ -141,6 +162,10 @@ container + + io.quarkus + quarkus-kubernetes + io.quarkus quarkus-container-image-jib diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/src/main/resources/application.properties b/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/src/main/resources/application.properties index 385adbe6b5..17a4413f94 100644 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/src/main/resources/application.properties +++ b/serverless-workflow-examples/serverless-workflow-github-showcase/github-service/src/main/resources/application.properties @@ -1,18 +1,27 @@ -# Packaging -# quarkus.package.type=fast-jar - -quarkus.swagger-ui.always-include=true -# for future reference, unfortunately the GitHub Client API library used in this -# project is not compatible with native builds out of the box -quarkus.native.enable-all-security-services=true -quarkus.native.enable-https-url-handler=true - -# profile to pack this example into a container, to use it execute activate the maven container profile, -Dcontainer -%container.quarkus.container-image.build=true -%container.quarkus.container-image.push=false -%container.quarkus.container-image.group=${USER} -%container.quarkus.container-image.registry=dev.local -%container.quarkus.container-image.tag=1.0-SNAPSHOT -%container.quarkus.jib.jvm-entrypoint=/home/kogito/kogito-app-launch.sh -%container.quarkus.jib.base-jvm-image=quay.io/kiegroup/kogito-runtime-jvm:latest -%container.quarkus.jib.working-directory=/home/kogito/bin \ No newline at end of file +# When the application is generated with the knative profile, it'll require a PostgreSQL database. + +# Enable the PostgreSqlSubscriptionRepository component. +enable.resource.postgresql=true + +## DB configuration: +quarkus.datasource.db-kind=postgresql + +org.kogito.examples.sw.github.service.key= +org.kogito.examples.sw.github.service.installation_id= +org.kogito.examples.sw.github.service.app_id= + +## Knative integration: + +# This env var will be generated with the quarkus-kubernetes plugin. See below. +quarkus.datasource.reactive.url=postgresql://${POSTGRES_HOST:localhost}:5432/postgres +quarkus.datasource.username=postgres +quarkus.datasource.password=pass + +quarkus.kubernetes.deployment-target=knative +quarkus.knative.name=github-service +quarkus.knative.image-pull-policy=IfNotPresent + +quarkus.container-image.build=true +quarkus.container-image.group=dev.local +quarkus.container-image.name=github-service + diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/kubernetes/github-showcase-database.yml b/serverless-workflow-examples/serverless-workflow-github-showcase/kubernetes/github-showcase-database.yml new file mode 100644 index 0000000000..116c0e8078 --- /dev/null +++ b/serverless-workflow-examples/serverless-workflow-github-showcase/kubernetes/github-showcase-database.yml @@ -0,0 +1,56 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: github-showcase +--- +# Database deployment for the loanbroker-example. +apiVersion: v1 +data: + postgrespass: cGFzcwo= +kind: Secret +metadata: + name: github-showcase-database + namespace: github-showcase +type: Opaque +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: github-showcase-database + namespace: github-showcase +spec: + replicas: 1 + selector: + matchLabels: + app: github-showcase-database + template: + metadata: + labels: + app: github-showcase-database + spec: + containers: + - env: + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + key: postgrespass + name: github-showcase-database + image: postgres:13.4-alpine3.14 + imagePullPolicy: Always + name: github-showcase-database + ports: + - containerPort: 5432 + name: tcp + protocol: TCP +--- +kind: Service +apiVersion: v1 +metadata: + name: github-showcase-database + namespace: github-showcase +spec: + selector: + app: github-showcase-database + ports: + - port: 5432 + type: ClusterIP diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/01-github-source.yaml b/serverless-workflow-examples/serverless-workflow-github-showcase/kubernetes/github-source.yml similarity index 89% rename from serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/01-github-source.yaml rename to serverless-workflow-examples/serverless-workflow-github-showcase/kubernetes/github-source.yml index 539132bba4..be31974c3b 100644 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/01-github-source.yaml +++ b/serverless-workflow-examples/serverless-workflow-github-showcase/kubernetes/github-source.yml @@ -3,7 +3,7 @@ kind: GitHubSource metadata: name: github-event-listener spec: - ownerAndRepository: repository_placeholder + ownerAndRepository: VaniHaripriya/TestRepository eventTypes: - pull_request accessToken: diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/kubernetes/github-webhook-secret.yml b/serverless-workflow-examples/serverless-workflow-github-showcase/kubernetes/github-webhook-secret.yml new file mode 100644 index 0000000000..28a847e46d --- /dev/null +++ b/serverless-workflow-examples/serverless-workflow-github-showcase/kubernetes/github-webhook-secret.yml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +metadata: + name: github-webhook-secret +type: Opaque +stringData: + accessToken: no_need + secretToken: super-kogito-demo-secret \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/kubernetes/jobs-service-postgresql.yml b/serverless-workflow-examples/serverless-workflow-github-showcase/kubernetes/jobs-service-postgresql.yml new file mode 100644 index 0000000000..cf883759db --- /dev/null +++ b/serverless-workflow-examples/serverless-workflow-github-showcase/kubernetes/jobs-service-postgresql.yml @@ -0,0 +1,135 @@ +--- +apiVersion: sources.knative.dev/v1 +kind: SinkBinding +metadata: + name: jobs-service-postgresql-sb + namespace: github-showcase +spec: + sink: + ref: + apiVersion: eventing.knative.dev/v1 + kind: Broker + name: default + subject: + apiVersion: apps/v1 + kind: Deployment + selector: + matchLabels: + app.kubernetes.io/name: jobs-service-postgresql + app.kubernetes.io/version: 2.0.0-SNAPSHOT +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app.kubernetes.io/name: jobs-service-postgresql + app.kubernetes.io/version: 2.0.0-SNAPSHOT + name: jobs-service-postgresql + namespace: github-showcase +spec: + ports: + - name: http + port: 80 + targetPort: 8080 + selector: + app.kubernetes.io/name: jobs-service-postgresql + app.kubernetes.io/version: 2.0.0-SNAPSHOT + type: ClusterIP +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app.kubernetes.io/name: jobs-service-postgresql + app.kubernetes.io/version: 2.0.0-SNAPSHOT + name: jobs-service-postgresql + namespace: github-showcase +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: jobs-service-postgresql + app.kubernetes.io/version: 2.0.0-SNAPSHOT + template: + metadata: + labels: + app.kubernetes.io/name: jobs-service-postgresql + app.kubernetes.io/version: 2.0.0-SNAPSHOT + spec: + containers: + - name: jobs-service-postgresql + image: quay.io/kiegroup/kogito-jobs-service-postgresql-nightly:latest + imagePullPolicy: Always + ports: + - containerPort: 8080 + name: http + protocol: TCP + env: + - name: KUBERNETES_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: KOGITO_JOBS_SERVICE_KNATIVE_EVENTS + value: "false" + - name: QUARKUS_DATASOURCE_USERNAME + value: postgres + - name: QUARKUS_DATASOURCE_PASSWORD + value: pass + - name: QUARKUS_DATASOURCE_JDBC_URL + value: jdbc:postgresql://github-showcase-database:5432/postgres?currentSchema=jobs-service + - name: QUARKUS_DATASOURCE_REACTIVE_URL + value: postgresql://github-showcase-database:5432/postgres?search_path=jobs-service + livenessProbe: + failureThreshold: 3 + httpGet: + path: /q/health/live + port: 8080 + scheme: HTTP + initialDelaySeconds: 0 + periodSeconds: 30 + successThreshold: 1 + timeoutSeconds: 10 + readinessProbe: + failureThreshold: 3 + httpGet: + path: /q/health/ready + port: 8080 + scheme: HTTP + initialDelaySeconds: 0 + periodSeconds: 30 + successThreshold: 1 + timeoutSeconds: 10 +--- +apiVersion: eventing.knative.dev/v1 +kind: Trigger +metadata: + name: jobs-service-postgresql-create-job-trigger + namespace: github-showcase +spec: + broker: default + filter: + attributes: + type: job.create + subscriber: + ref: + apiVersion: v1 + kind: Service + name: jobs-service-postgresql + uri: /v2/jobs/events +--- +apiVersion: eventing.knative.dev/v1 +kind: Trigger +metadata: + name: jobs-service-postgresql-cancel-job-trigger + namespace: github-showcase +spec: + broker: default + filter: + attributes: + type: job.delete + subscriber: + ref: + apiVersion: v1 + kind: Service + name: jobs-service-postgresql + uri: /v2/jobs/events diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/kubernetes/kubernetes.yml b/serverless-workflow-examples/serverless-workflow-github-showcase/kubernetes/kubernetes.yml new file mode 100644 index 0000000000..fb7289b5c2 --- /dev/null +++ b/serverless-workflow-examples/serverless-workflow-github-showcase/kubernetes/kubernetes.yml @@ -0,0 +1,92 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: github-showcase +--- +# use for debugging +# simple knative application to display the routed messages +apiVersion: serving.knative.dev/v1 +kind: Service +metadata: + name: event-display + namespace: github-showcase +spec: + template: + spec: + containers: + - # This corresponds to + # https://github.com/knative/eventing-contrib/tree/main/cmd/event_display + image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display@sha256:a214514d6ba674d7393ec8448dd272472b2956207acb3f83152d3071f0ab1911 +--- +apiVersion: eventing.knative.dev/v1 +kind: Trigger +metadata: + name: trigger-eventdisplay + namespace: github-showcase +spec: + broker: default + subscriber: + ref: + apiVersion: serving.knative.dev/v1 + kind: Service + name: event-display +--- +apiVersion: sources.knative.dev/v1 +kind: SinkBinding +metadata: + name: pr-checker-sink +spec: + subject: + apiVersion: apps/v1 + kind: Deployment + selector: + matchLabels: + app: pr-checker-flow + # any cloud event produced by our application will then be delivered to the Broker + sink: + ref: + apiVersion: eventing.knative.dev/v1 + kind: Broker + name: default +--- +apiVersion: eventing.knative.dev/v1 +kind: Trigger +metadata: + name: pr-checker-listener +spec: + broker: default + filter: + attributes: + # anything from our repo + source: placeholder + # pull requests events only :) + type: dev.knative.source.github.pull_request + # the subscriber is the deployed kogito service + subscriber: + ref: + apiVersion: v1 + kind: Service + name: pr-checker-flow +--- +apiVersion: eventing.knative.dev/v1 +kind: Trigger +metadata: + name: notification-trigger +spec: + # the default broker has been enabled in the cluster since the namespace is labeled with knative-eventing-injection=enabled + broker: default + filter: + attributes: + # this message is produced by the pr-checker-workflow + type: process.handle_backend.checker_workflow_backend + # the subscriber is the knative service we just deployed + subscriber: + ref: + apiVersion: serving.knative.dev/v1 + kind: Service + name: notification-service +--- +apiVersion: eventing.knative.dev/v1 +kind: Broker +metadata: + name: default \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/README.md b/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/README.md index abc92831e2..935b1b294a 100644 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/README.md +++ b/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/README.md @@ -47,113 +47,58 @@ curl -X POST "http://localhost:8080/plain" -H "Content-Type: text/plain" -d "th As always, we included the Swagger UI in the service, access it at http:localhost:8080/swagger-ui/. -### Deploying on Kubernetes - -> **HEADS UP!** delete the Slack WebHook from the `application.properties` file. -> We're going to build an image from the source, you don't want your credentials to be exposed to the world!! +### Running on knative > **IMPORTANT! :warning:** we assume you have read the prerequisites section in the main > [README file](../README.md). Please follow those instructions before continuing. -**Heads up!** This service will be deployed as a Knative Service instead of a regular Kubernetes -Deployment. - -To make things easier there is a [script in this directory](deploy-kubernetes.sh) to generate the template -files, build the application and the image, and then deploy it to your Kubernetes cluster. - -**IMPORTANT!** You **must** be authenticated to the target Kubernetes cluster as a **cluster administrator** for this script -to work. - -You can run the script once and all the required files will be generated in the `kubernetes` directory, -and the image will be published to your Quay.io account. - -Fill the value for the variables as shown below and run the script: +Run `mvn clean install -Pknative` -```shell script -# the script accepts positional arguments as following: -QUAY_NAMESPACE= -SLACK_WEBHOOK= - -./deploy-kubernetes.sh $QUAY_NAMESPACE $SLACK_WEBHOOK -``` - -You should see a similar output like this: - -
Build logs -``` -// build logs surpressed ----> Building and pushing image using tag quay.io/your_namespace/notification-service:latest -STEP 1: FROM adoptopenjdk:11-jre-hotspot -STEP 2: RUN mkdir -p /opt/app/lib ---> Using cache 26183c5ad8a51a030030a250db0c99e649fdd9668ef4766d0b66782d0dad7573 -STEP 3: COPY target/notification-service-2.0.0-SNAPSHOT-runner.jar /opt/app ---> 2a5b658411b -STEP 4: COPY target/lib/*.jar /opt/app/lib ---> 5fedac21977 -STEP 5: CMD ["java", "-jar", "/opt/app/notification-service-2.0.0-SNAPSHOT-runner.jar"] -STEP 6: COMMIT quay.io/your_namespace/notification-service:latest ---> afe502d1940 -afe502d1940d65f151c051008bb2057344607408c192787a726399d23d90c2d3 -Getting image source signatures -Copying config afe502d194 done -Writing manifest to image destination -Copying config afe502d194 [--------------------------------------] 0.0b / 6.2KiB -Writing manifest to image destination -Writing manifest to image destination -Storing signatures ----> Applying objects to the cluster in the namespace kogito-github. -configmap/notification-service-properties unchanged -secret/slack-ids configured -service.serving.knative.dev/notification-service configured -broker.eventing.knative.dev/default unchanged -trigger.eventing.knative.dev/notification-trigger unchanged -``` -
+Deploy the service with the following command: + ```shell + # install the notification-service + $ kubectl apply -f notification-service/target/kubernetes/knative.yml -n github-showcase + ``` To verify if the service have been correctly deployed run: ``` -$ kubectl get ksvc notification-service -n kogito-github - -NAME URL LATESTCREATED LATESTREADY READY REASON -notification-service http://notification-service.kogito-github.example.com notification-service-9mgww notification-service-9mgww True -``` + $ kubectl get ksvc notification-service -n github-showcase + NAME URL LATESTCREATED LATESTREADY READY REASON +notification-service http://notification-service.github-showcase.10.104.64.247.sslip.io notification-service-00001 notification-service-00001 True +``` The `READY` column should be true. #### Exposing the service on Minikube -If you're running on another cluster than Minikube, the service's route exposed by Knative Serving probably is accessible to you. -On Minikube there are some additional steps to be made. +Execute the following command to expose the knative service Run a new terminal window: ```shell script minikube tunnel ``` - Leave the process executing and then execute: -```shell script -./expose-on-minikube.sh -``` - -This script will fetch the Minikube IP exposed by the `tunnel` command and add the route to your local `/etc/hosts` file. +```shell + # expose the github-service + $ kubectl expose deployment notification-service --name=notification-service-external --type=LoadBalancer --port=8080 -n github-showcase + ``` You can then access the service via the service URL: ``` -$ kubectl get ksvc notification-service -n kogito-github --output jsonpath="{.status.url}" - -http://notification-service.kogito-github.example.com +$ kubectl get ksvc notification-service -n github-showcase --output jsonpath="{.status.url}" + http://notification-service.github-showcase.10.104.64.247.sslip.io ``` -As we did when running through the `jar` file, we can access the Swagger UI and play around with the API: +As we did when running through the `jar` file, we can access the Swagger UI and play around with the API: -http://notification-service.kogito-github.example.com/swagger-ui +http://notification-service.github-showcase.10.104.64.247.sslip.io/q/swagger-ui -The first query may take a little time to return since Knative will start the service's pod on demand. -After some time the pod will just terminate. +The first query may take a little time to return since Knative will start the service's pod on demand. +After some time the pod will just terminate. Congratulations! The Notification service is now available in the cluster ready to be consumed by the Kogito Workflow. diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/configure.sh b/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/configure.sh deleted file mode 100755 index 3625445487..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/configure.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/bash -# Copyright 2020 Red Hat, Inc. and/or its affiliates -# -# Licensed 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. - -QUAY_NAMESPACE=$1 -SLACK_WEBHOOK=$2 - -CURR_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -# shellcheck source=../scripts/common.sh -source "${CURR_DIR}/../scripts/common.sh" - -function print_usage() { - echo "---> Script to deploy the Notification service to the Kubernetes cluster. Usage:" - echo "---> ./deploy-kubernetes.sh QUAY_NAMESPACE SLACK_WEBHOOK" - echo "---> Example: " - echo "---> ./deploy-kubernetes.sh namespace " -} - -function verify_input() { - local return_code=0 - if [ -z "${QUAY_NAMESPACE}" ]; then - echo "---> Quay namespace not set" - return_code=1 - fi - - if [ -z "${SLACK_WEBHOOK}" ]; then - echo "---> Slack WebHook ID not set" - return_code=1 - fi - - return ${return_code} -} - -function apply_vars() { - cp ./kubernetes/apply_image_ns.yaml.tpl ./kubernetes/apply_image_ns.yaml - cp ./kubernetes/slack.env.tpl ./kubernetes/slack.env - - sed -i "s/{QUAY_NAMESPACE}/${QUAY_NAMESPACE}/g" ./kubernetes/apply_image_ns.yaml - sed -i "s,{SLACK_WEBHOOK},${SLACK_WEBHOOK},g" ./kubernetes/slack.env -} - -if ! verify_input; then - print_usage - exit -fi - -if ! check_binaries; then - echo "---> exiting installation script, not all required binaries have been found in your system" - exit -fi - -apply_vars \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/deploy-kubernetes.sh b/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/deploy-kubernetes.sh deleted file mode 100755 index b24a26a0f4..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/deploy-kubernetes.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -# Copyright 2020 Red Hat, Inc. and/or its affiliates -# -# Licensed 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. - -# imports.. - -source ./configure.sh - -echo "---> Building application" -mvn clean install -DskipTests - -build_push_image "${QUAY_NAMESPACE}" "notification-service" - -echo "---> Applying objects to the cluster in the namespace kogito-github." -kubectl apply -k ./kubernetes diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/expose-on-minikube.sh b/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/expose-on-minikube.sh deleted file mode 100755 index c081666847..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/expose-on-minikube.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# Copyright 2020 Red Hat, Inc. and/or its affiliates -# -# Licensed 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. - -CURR_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -# shellcheck source=../scripts/add-route-to-hosts.sh -source "${CURR_DIR}/../scripts/add-route-to-hosts.sh" notification-service diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/00-broker.yaml b/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/00-broker.yaml deleted file mode 100644 index 3e3e089613..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/00-broker.yaml +++ /dev/null @@ -1,6 +0,0 @@ -# this is where all the messages coming to the cluster will pass -# we can use triggers and sinkbinding to route/filter the messages as we pleased -apiVersion: eventing.knative.dev/v1 -kind: Broker -metadata: - name: default diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/01-deployment.yaml b/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/01-deployment.yaml deleted file mode 100644 index c7e9c1bdcf..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/01-deployment.yaml +++ /dev/null @@ -1,23 +0,0 @@ -apiVersion: serving.knative.dev/v1 # Current version of Knative (0.17.x) -kind: Service -metadata: - name: notification-service -spec: - template: - spec: - containers: - - env: - - name: SLACK_WEBHOOK - valueFrom: - secretKeyRef: - key: slackWebHook - name: slack-ids - image: image_placeholder - volumeMounts: - - name: properties - mountPath: "/config/application.properties" - subPath: application.properties - volumes: - - name: properties - configMap: - name: notification-service-properties \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/02-trigger.yaml b/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/02-trigger.yaml deleted file mode 100644 index ff18e244b3..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/02-trigger.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: eventing.knative.dev/v1 -kind: Trigger -metadata: - name: notification-trigger -spec: - # the default broker has been enabled in the cluster since the namespace is labeled with knative-eventing-injection=enabled - broker: default - filter: - attributes: - # this message is produced by the pr-checker-workflow - type: process.handle_backend.checker_workflow_backend - # the subscriber is the knative service we just deployed - subscriber: - ref: - apiVersion: serving.knative.dev/v1 - kind: Service - name: notification-service \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/application.properties b/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/application.properties deleted file mode 100644 index 1f770525cf..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/application.properties +++ /dev/null @@ -1 +0,0 @@ -org.kogito.examples.sw.notification.slack.incoming=${SLACK_WEBHOOK} \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/apply_image_ns.yaml.tpl b/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/apply_image_ns.yaml.tpl deleted file mode 100644 index c28fcf8d88..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/apply_image_ns.yaml.tpl +++ /dev/null @@ -1,3 +0,0 @@ -- op: replace - path: /spec/template/spec/containers/0/image - value: quay.io/{QUAY_NAMESPACE}/notification-service:latest \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/kustomization.yaml b/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/kustomization.yaml deleted file mode 100644 index c45706fb2d..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/kustomization.yaml +++ /dev/null @@ -1,24 +0,0 @@ -namespace: kogito-github -resources: - - 00-broker.yaml - - 01-deployment.yaml - - 02-trigger.yaml -generatorOptions: - disableNameSuffixHash: true - labels: - app: notification-service -patchesJson6902: - - path: apply_image_ns.yaml - target: - kind: Service - name: notification-service - version: v1 - group: serving.knative.dev -configMapGenerator: - - files: - - application.properties - name: notification-service-properties -secretGenerator: - - env: slack.env - name: slack-ids - type: Opaque diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/slack.env.tpl b/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/slack.env.tpl deleted file mode 100644 index 8a6367cd88..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/kubernetes/slack.env.tpl +++ /dev/null @@ -1 +0,0 @@ -slackWebHook={SLACK_WEBHOOK} \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/pom.xml b/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/pom.xml index db514c9073..1dcd0e37fb 100644 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/pom.xml +++ b/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/pom.xml @@ -10,14 +10,7 @@ notification-service Kogito Example :: Serverless Workflow Github Showcase :: Notification Service - true - 2.13.1.Final - quarkus-bom - io.quarkus - 2.13.1.Final - 2.3.0 - 3.8.1 - 11 + true @@ -53,6 +46,10 @@ io.quarkus quarkus-smallrye-openapi
+ + io.quarkus + quarkus-swagger-ui + org.apache.camel.quarkus camel-quarkus-slack @@ -92,19 +89,6 @@
- - io.smallrye - jandex-maven-plugin - ${jandex-plugin.version} - - - make-index - - jandex - - - - ${quarkus.platform.group-id} quarkus-maven-plugin @@ -121,6 +105,42 @@ + + native + + + native + + + + native + + + + knative + + + github-showcase + false + + ${namespace} + ${deploy} + true + knative + true + true + + + + io.quarkus + quarkus-kubernetes + + + io.quarkus + quarkus-container-image-jib + + + container @@ -132,6 +152,10 @@ container + + io.quarkus + quarkus-kubernetes + io.quarkus quarkus-container-image-jib diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/src/main/resources/application.properties b/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/src/main/resources/application.properties index c3b1c6454b..4657b54db9 100644 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/src/main/resources/application.properties +++ b/serverless-workflow-examples/serverless-workflow-github-showcase/notification-service/src/main/resources/application.properties @@ -1,15 +1,29 @@ quarkus.swagger-ui.always-include=true org.kogito.examples.sw.notification.slack.channel=github-showcase -quarkus.index-dependency.cloudevents.group-id=io.cloudevents -quarkus.index-dependency.cloudevents.artifact-id=cloudevents-http-restful-ws - -# profile to pack this example into a container, to use it execute activate the maven container profile, -Dcontainer -%container.quarkus.container-image.build=true -%container.quarkus.container-image.push=false -%container.quarkus.container-image.group=${USER} -%container.quarkus.container-image.registry=dev.local -%container.quarkus.container-image.tag=1.0-SNAPSHOT -%container.quarkus.jib.jvm-entrypoint=/home/kogito/kogito-app-launch.sh -%container.quarkus.jib.base-jvm-image=quay.io/kiegroup/kogito-runtime-jvm:latest -%container.quarkus.jib.working-directory=/home/kogito/bin +mp.openapi.extensions.smallrye.operationIdStrategy=METHOD +# knative configuration for sending the events to the query-answer-service +mp.messaging.outgoing.response_events.connector=quarkus-http +mp.messaging.outgoing.response_events.url=${K_SINK:http://localhost:8181} +mp.messaging.outgoing.response_events.method=POST + +# Build the application with the persistence profile to use a PostgreSQL database. +quarkus.datasource.db-kind=postgresql +# This env var will be generated with the quarkus-kubernetes plugin. See below. +quarkus.datasource.reactive.url=postgresql://${POSTGRES_HOST:localhost}:5432/postgres +quarkus.datasource.username=postgres +quarkus.datasource.password=pass + + +quarkus.knative.image-pull-policy=IfNotPresent +quarkus.kubernetes.deployment-target=knative +quarkus.knative.name=notification-service +quarkus.container-image.build=true +quarkus.container-image.group=dev.local +quarkus.container-image.name=notification-service +quarkus.container-image.tag=1.0-SNAPSHOT + + + + + diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pom.xml b/serverless-workflow-examples/serverless-workflow-github-showcase/pom.xml index 9ecf1a0cf9..53211ecdf8 100644 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pom.xml +++ b/serverless-workflow-examples/serverless-workflow-github-showcase/pom.xml @@ -4,22 +4,48 @@ 4.0.0 org.kie.kogito.examples + Kogito Example :: Serverless Workflow Github showcase + Kogito Serverless Workflow example showcasing the Github Showcase use case serverless-workflow-github-showcase 1.0-SNAPSHOT - pom - Kogito Example :: Serverless Workflow Github Showcase - - pr-checker-workflow - github-service - notification-service - - 3.0.5 + 2.16.0.Final + io.quarkus + quarkus-bom + 2.16.0.Final + org.kie.kogito + kogito-bom + 2.0.0-SNAPSHOT + + UTF-8 + UTF-8 + + 2.33.2 + 1.17.3 + 2.3.0 + + + 2.14.0 + + 3.0.0-M7 + 3.8.1 + 11 + 3.0.0-M7 0.11.2 1.116 - 2.13.0 + 2.16.0 2.33.2 + ${version.surefire.plugin} + 5.1.3 + 3.6.0 + + + pr-checker-workflow + github-service + notification-service + + diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/README.md b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/README.md index 0b2e3c2cff..979893003f 100644 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/README.md +++ b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/README.md @@ -52,75 +52,15 @@ Just make sure that the Webhook link is correct._ ### Install Knative GitHub Source -Install the GitHub source from [eventing-contrib](https://github.com/knative/eventing-contrib/releases) releases that match your Knative Eventing -platform. To know the Knative eventing version run: +Install the GitHub source from [eventing-github](https://github.com/knative-sandbox/eventing-github/releases) releases that match your Knative Eventing +platform. ```shell script -$ kubectl get KnativeEventing knative-eventing -n knative-eventing - -NAME VERSION READY REASON -knative-eventing 0.17.3 True -``` - -Then run: - -```shell script -$ kubectl apply -f https://github.com/knative/eventing-contrib/releases/download/v/github.yaml +$ kubectl apply -f https://github.com/knative-sandbox/eventing-github/releases/download/k/github.yaml ``` **Note:** replace `` with the correct Knative Eventing version. -### Deploying on Kubernetes - -> **IMPORTANT! :warning:** we assume you have read the prerequisites section in the main -> [README file](../README.md). Please follow those instructions before continuing. - -**Please do not proceed any further if you haven't deployed the [GitHub](../github-service) and [Notification](../notification-service) services.** - -To make things easier there is a [script in this directory](deploy-kubernetes.sh) to generate the template -files, build the application and the image, and then deploy it to your Kubernetes cluster. - -**IMPORTANT!** You **must** be authenticated to the target Kubernetes cluster as a **cluster administrator** for this script -to work. - -You can run the script once and all the required files will be generated in the `kubernetes/base` directory, -and the image will be published to your Quay.io account. - -Fill the value for the variables as shown below and run the script: - -```shell script -# the script accepts positional arguments as following: -QUAY_NAMESPACE= -GITHUB_REPO= - -./deploy-kubernetes.sh $QUAY_NAMESPACE $GITHUB_REPO -``` - -You should see a similar output like this: - -
Build logs -``` ----> Building and pushing image using tag quay.io/your_namespace/pr-checker-workflow:latest -STEP 1: FROM quay.io/kiegroup/kogito-runtime-jvm:latest -STEP 2: ENV RUNTIME_TYPE quarkus -STEP 3: COPY target/*-runner.jar $KOGITO_HOME/bin ---> 58760d128d8 -STEP 4: COPY target/lib $KOGITO_HOME/bin/lib -STEP 5: COMMIT quay.io/your_namespace/pr-checker-workflow:latest ---> 7bea1f647bc -Writing manifest to image destination -Writing manifest to image destination -Storing signatures ----> Applying objects to the cluster in the namespace kogito-github. -secret/github-webhook-secret unchanged -service/pr-checker-workflow-default-http unchanged -kogitoruntime.app.kiegroup.org/pr-checker-workflow configured -broker.eventing.knative.dev/default unchanged -trigger.eventing.knative.dev/pr-checker-listener unchanged -githubsource.sources.knative.dev/github-event-listener unchanged -sinkbinding.sources.knative.dev/pr-checker-sink unchanged -``` -
If your cluster is already ready to receive GitHub Webhooks calls, just create a new PR in your repository with a file named "backend", and you should see the PR @@ -145,22 +85,15 @@ $ minikube tunnel Now run: ``` -$ ./expose-on-minikube.sh +$ kubectl expose deployment pr-checker-flow --name=pr-checker-flow-external --type=LoadBalancer --port=8080 -n github-showcase ``` - -This command will create a new Istio `VirtualService` to access the Knative GitHub Source -from the Smee CLI tool. Since this tool adds a `Host: smee.io` in the request before redirecting -it to the cluster, Istio will reply with a 404 (Not Found) status code because it uses the -HTTP header `Host` to route requests within the cluster. - -Our just created `github-event-listener-smee` will take care of redirecting any requests -with `Host: smee.io` to the right service. +This will expose pr-checker-flow service to be accessed from outside of cluster. Now on a new terminal window run: ``` $ SMEE_WEBHOOK= -$ ROUTE=$(kubectl get routes -l receive-adapter=github -o jsonpath="{.items[*].status.url}" -n kogito-github) +$ ROUTE=$( kubectl get route pr-checker-flow -o jsonpath='{.status.url}' -n github-showcase) $ smee -u $SMEE_WEBHOOK -t $ROUTE ``` @@ -171,10 +104,6 @@ The Smee CLI will capture all events coming from your repository and redirect to your local cluster, you should see the Knative pods starting on demand and in the end a message in the Slack channel. :) -#### Kubernetes or OpenShift 4.x - -Talk to the cluster administrator to understand how your cluster and Istio Ingress can be exposed to the world. - ### Cleaning up! -See the project root's [README](./README.md) documentation. \ No newline at end of file +See the project root's [README](./README.md) documentation. diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/configure.sh b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/configure.sh deleted file mode 100755 index f4661bdd52..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/configure.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/bash -# Copyright 2020 Red Hat, Inc. and/or its affiliates -# -# Licensed 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. - -QUAY_NAMESPACE=$1 -GITHUB_REPO=$2 - -CURR_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -# shellcheck source=../scripts/common.sh -source "${CURR_DIR}/../scripts/common.sh" - -function print_usage() { - echo "---> Script to deploy the GitHub service to the Kubernetes cluster. Usage:" - echo "---> ./deploy-kubernetes.sh QUAY_NAMESPACE GITHUB_REPO" - echo "---> Example: " - echo "---> ./deploy-kubernetes.sh namespace user/repo" -} - -function verify_input() { - local return_code=0 - if [ -z "${QUAY_NAMESPACE}" ]; then - echo "---> Quay namespace not set" - return_code=1 - fi - - if [ -z "${GITHUB_REPO}" ]; then - echo "---> GitHub owner and repository not set" - return_code=1 - fi - - return ${return_code} -} - -function apply_vars() { - cp ./kubernetes/base/apply_image_ns.yaml.tpl ./kubernetes/base/apply_image_ns.yaml - cp ./kubernetes/base/patch_repository.yaml.tpl ./kubernetes/base/patch_repository.yaml - cp ./kubernetes/base/patch_trigger.yaml.tpl ./kubernetes/base/patch_trigger.yaml - - sed -i "s/{QUAY_NAMESPACE}/${QUAY_NAMESPACE}/g" ./kubernetes/base/apply_image_ns.yaml - sed -i "s,{GITHUB_REPO},${GITHUB_REPO},g" ./kubernetes/base/patch_repository.yaml - sed -i "s,{GITHUB_REPO},${GITHUB_REPO},g" ./kubernetes/base/patch_trigger.yaml -} - -if ! verify_input; then - print_usage - exit -fi - -if ! check_binaries; then - echo "---> exiting installation script, not all required binaries have been found in your system" - exit -fi - -apply_vars \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/deploy-kubernetes.sh b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/deploy-kubernetes.sh deleted file mode 100755 index 1fa4eb7d73..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/deploy-kubernetes.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -# Copyright 2020 Red Hat, Inc. and/or its affiliates -# -# Licensed 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. - -# imports.. - -source ./configure.sh - -echo "---> Building application" -mvn clean install -DskipTests - -build_push_image "${QUAY_NAMESPACE}" "pr-checker-workflow" - -echo "---> Applying objects to the cluster in the namespace kogito-github." -kubectl apply -k ./kubernetes/base diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/expose-on-minikube.sh b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/expose-on-minikube.sh deleted file mode 100755 index 199f20feeb..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/expose-on-minikube.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -# Copyright 2020 Red Hat, Inc. and/or its affiliates -# -# Licensed 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. - -route=$(kubectl get routes -l receive-adapter=github -o jsonpath="{.items[*].metadata.name}" -n kogito-github) -svc=$(kubectl get svc -l serving.knative.dev/service="${route}",networking.internal.knative.dev/serviceType=Public -o jsonpath="{.items[*].metadata.name}" -n kogito-github) - -cp ./kubernetes/local/patch-virtual-service.yaml.tpl ./kubernetes/local/patch-virtual-service.yaml -sed -i "s,{EVENT_LISTENER_SVC},${svc},g" ./kubernetes/local/patch-virtual-service.yaml - -kubectl apply -k kubernetes/local - -CURR_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -# shellcheck source=../scripts/add-route-to-hosts.sh -source "${CURR_DIR}/../scripts/add-route-to-hosts.sh" "${route}" diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/00-broker.yaml b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/00-broker.yaml deleted file mode 100644 index b22378c304..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/00-broker.yaml +++ /dev/null @@ -1,4 +0,0 @@ -apiVersion: eventing.knative.dev/v1 -kind: Broker -metadata: - name: default diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/02-kogito-service.yaml b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/02-kogito-service.yaml deleted file mode 100644 index e8d52beb4b..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/02-kogito-service.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: app.kiegroup.org/v1beta1 -kind: KogitoRuntime -metadata: - name: pr-checker-workflow -spec: - replicas: 1 - image: placeholder - env: - - name: GITHUB_SERVICE_URI - value: http://github-service.kogito-github.svc.cluster.local \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/03-pr-checker-trigger.yaml b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/03-pr-checker-trigger.yaml deleted file mode 100644 index 73eefa0cf1..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/03-pr-checker-trigger.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: eventing.knative.dev/v1 -kind: Trigger -metadata: - name: pr-checker-listener -spec: - broker: default - filter: - attributes: - # anything from our repo - source: placeholder - # pull requests events only :) - type: dev.knative.source.github.pull_request - # the subscriber is the deployed kogito service - subscriber: - ref: - apiVersion: v1 - kind: Service - name: pr-checker-workflow \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/04-pr-checker-sinkbinding.yaml b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/04-pr-checker-sinkbinding.yaml deleted file mode 100644 index de5f393804..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/04-pr-checker-sinkbinding.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: sources.knative.dev/v1alpha1 -kind: SinkBinding -metadata: - name: pr-checker-sink -spec: - subject: - apiVersion: apps/v1 - kind: Deployment - selector: - matchLabels: - app: pr-checker-workflow - # any cloud event produced by our application will then be delivered to the Broker - sink: - ref: - apiVersion: eventing.knative.dev/v1 - kind: Broker - name: default \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/apply_image_ns.yaml.tpl b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/apply_image_ns.yaml.tpl deleted file mode 100644 index 9f74cfe53a..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/apply_image_ns.yaml.tpl +++ /dev/null @@ -1,3 +0,0 @@ -- op: replace - path: /spec/image - value: quay.io/{QUAY_NAMESPACE}/pr-checker-workflow:latest \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/kustomization.yaml b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/kustomization.yaml deleted file mode 100644 index 392d4b60a6..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/kustomization.yaml +++ /dev/null @@ -1,36 +0,0 @@ -namespace: kogito-github -resources: - - 00-broker.yaml - - 01-github-source.yaml - - 02-kogito-service.yaml - - 03-pr-checker-trigger.yaml - - 04-pr-checker-sinkbinding.yaml -patchesJson6902: - - target: - kind: KogitoRuntime - name: pr-checker-workflow - version: v1alpha1 - group: app.kiegroup.org - path: apply_image_ns.yaml - - target: - kind: GitHubSource - name: github-event-listener - version: v1alpha1 - group: sources.knative.dev - path: patch_repository.yaml - - target: - kind: Trigger - name: pr-checker-listener - version: v1 - group: eventing.knative.dev - path: patch_trigger.yaml -generatorOptions: - disableNameSuffixHash: true - labels: - app: pr-checker-workflow -secretGenerator: - - name: github-webhook-secret - type: Opaque - literals: - - secretToken=super-kogito-demo-secret - - accessToken=no_need \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/patch_repository.yaml.tpl b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/patch_repository.yaml.tpl deleted file mode 100644 index 45996355db..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/patch_repository.yaml.tpl +++ /dev/null @@ -1,3 +0,0 @@ -- op: replace - path: /spec/ownerAndRepository - value: {GITHUB_REPO} \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/patch_trigger.yaml.tpl b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/patch_trigger.yaml.tpl deleted file mode 100644 index 53a9c07b1e..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/base/patch_trigger.yaml.tpl +++ /dev/null @@ -1,3 +0,0 @@ -- op: replace - path: /spec/filter/attributes/source - value: https://github.com/{GITHUB_REPO} \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/local/00-github-smee-virtualservice.yaml b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/local/00-github-smee-virtualservice.yaml deleted file mode 100644 index f5f5ccb002..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/local/00-github-smee-virtualservice.yaml +++ /dev/null @@ -1,23 +0,0 @@ -apiVersion: networking.istio.io/v1beta1 -kind: VirtualService -metadata: - name: github-event-listener-smee -spec: - gateways: - - knative-serving/cluster-local-gateway - - knative-serving/knative-ingress-gateway - hosts: - - smee.io - http: - - route: - - destination: - host: placeholder - port: - number: 80 - headers: - request: - set: - Knative-Serving-Namespace: kogito-github - Knative-Serving-Revision: placeholder - weight: 100 - timeout: 172800s diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/local/01-kogito-service-ingress.yaml b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/local/01-kogito-service-ingress.yaml deleted file mode 100644 index 1a68668846..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/local/01-kogito-service-ingress.yaml +++ /dev/null @@ -1,16 +0,0 @@ -# See: https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/ -apiVersion: networking.k8s.io/v1beta1 # for versions before 1.14 use extensions/v1beta1 -kind: Ingress -metadata: - name: pr-checker-workflow-ingress - annotations: - nginx.ingress.kubernetes.io/rewrite-target: / -spec: - rules: - - host: pr-checker-workflow.kogito.com - http: - paths: - - path: / - backend: - serviceName: pr-checker-workflow - servicePort: 8080 diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/local/kustomization.yaml b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/local/kustomization.yaml deleted file mode 100644 index a63cba5f21..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/local/kustomization.yaml +++ /dev/null @@ -1,12 +0,0 @@ -bases: - - ../base -resources: - - 00-github-smee-virtualservice.yaml - - 01-kogito-service-ingress.yaml -patchesJson6902: - - target: - kind: VirtualService - name: github-event-listener-smee - version: v1beta1 - group: networking.istio.io - path: patch-virtual-service.yaml \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/local/patch-virtual-service.yaml.tpl b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/local/patch-virtual-service.yaml.tpl deleted file mode 100644 index b8f6232eb2..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/kubernetes/local/patch-virtual-service.yaml.tpl +++ /dev/null @@ -1,6 +0,0 @@ -- op: replace - path: /spec/http/0/route/0/destination/host - value: {EVENT_LISTENER_SVC}.kogito-github.svc.cluster.local -- op: replace - path: /spec/http/0/route/0/headers/request/set/Knative-Serving-Revision - value: {EVENT_LISTENER_SVC} diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/pom.xml b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/pom.xml index ad08b61a68..9c8138999e 100644 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/pom.xml +++ b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/pom.xml @@ -10,16 +10,7 @@ pr-checker-workflow Kogito Example :: Serverless Workflow Github Showcase :: PR Checker Workflow - true - 2.13.1.Final - quarkus-bom - io.quarkus - 2.13.1.Final - org.kie.kogito - kogito-bom - 1.29.0.Final - 3.8.1 - 11 + true @@ -40,6 +31,7 @@ + org.kie.kogito kogito-quarkus-serverless-workflow @@ -48,9 +40,15 @@ org.kie.kogito kogito-addons-quarkus-knative-eventing + + io.quarkus - quarkus-resteasy + quarkus-smallrye-openapi + + + io.quarkus + quarkus-swagger-ui io.quarkus @@ -58,12 +56,37 @@ io.quarkus - quarkus-smallrye-openapi + quarkus-arc io.quarkus - quarkus-smallrye-health + quarkus-kubernetes + + + org.kie.kogito + kogito-quarkus-serverless-workflow-devui + + + org.kie.kogito + kogito-addons-quarkus-source-files + + io.quarkus + quarkus-webjars-locator + + + org.webjars + bootstrap + ${version.org.webjars.bootstrap} + + + org.webjars + jquery + ${version.org.webjars.jquery} + + + + io.quarkus quarkus-junit5 @@ -77,52 +100,42 @@ com.github.tomakehurst wiremock-jre8 - ${version.com.github.tomakehurst.wiremock} + ${version.com.github.tomakehurst} + test + + + org.testcontainers + junit-jupiter + ${version.org.testcontainers} test - ${project.artifactId} - - maven-compiler-plugin - ${version.compiler.plugin} - - ${maven.compiler.release} - - - - org.codehaus.mojo - properties-maven-plugin - 1.0.0 - - - - set-system-properties - - - - - jbpm.enable.multi.con - true - - - - - - ${quarkus.platform.group-id} quarkus-maven-plugin - ${quarkus-plugin.version} + ${quarkus.platform.version} + true build + generate-code + generate-code-tests + + maven-compiler-plugin + ${version.compiler.plugin} + + + -parameters + + + maven-surefire-plugin ${version.surefire.plugin} @@ -133,10 +146,80 @@ + + maven-failsafe-plugin + ${version.surefire.plugin} + + + + integration-test + verify + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + - + + native + + + native + + + + native + + + + knative + + + github-showcase + false + + ${namespace} + ${deploy} + true + knative + true + true + + + + io.quarkus + quarkus-kubernetes + + + io.quarkus + quarkus-container-image-jib + + + org.kie.kogito + kogito-addons-quarkus-persistence-jdbc + + + io.quarkus + quarkus-jdbc-postgresql + + + io.quarkus + quarkus-agroal + + + org.kie.kogito + kogito-addons-quarkus-jobs-knative-eventing + + + container diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/src/main/resources/application.properties b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/src/main/resources/application.properties index 0febd93dca..89f1f83fd0 100644 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/src/main/resources/application.properties +++ b/serverless-workflow-examples/serverless-workflow-github-showcase/pr-checker-workflow/src/main/resources/application.properties @@ -1,28 +1,44 @@ -quarkus.log.level=INFO -quarkus.swagger-ui.always-include=true - -org.kogito.examples.sw.github.workflow.GitHubClient/mp-rest/url=${GITHUB_SERVICE_URI} -org.kogito.examples.sw.github.workflow.GitHubClient/mp-rest/scope=javax.inject.Singleton +# Kogito persistence configurations for enabling the serverless workflow persistence +quarkus.datasource.db-kind=postgresql +quarkus.flyway.migrate-at-start=true +kogito.persistence.type=jdbc +kogito.persistence.proto.marshaller=false +kogito.persistence.query.timeout.millis=10000 +enable.resource.postgresql=true -mp.messaging.incoming.kogito_incoming_stream.connector=quarkus-http -mp.messaging.incoming.kogito_incoming_stream.path=/ +# This env var will be generated with the quarkus-kubernetes plugin. See below. +quarkus.datasource.jdbc.url=jdbc:postgresql://${POSTGRES_HOST:localhost}:5432/postgres +quarkus.datasource.username=postgres +quarkus.datasource.password=pass +# Use the Kogito service discovery mechanism to get the current service url. +# For more information see: https://kiegroup.github.io/kogito-docs/serverlessworkflow/latest/cloud/kubernetes-service-discovery.html +kogito.service.url=knative:serving.knative.dev/v1/Service/github-showcase/pr-checker-flow -mp.messaging.outgoing.pr_verified.connector=quarkus-http -mp.messaging.outgoing.pr_verified.url=${K_SINK} +kogito.messaging.as-cloudevents=true +quarkus.http.cors.origins=* +quarkus.swagger-ui.always-include=true +quarkus.kubernetes.deploy=false -mp.messaging.outgoing.checker_workflow_frontend.connector=quarkus-http -mp.messaging.outgoing.checker_workflow_frontend.url=${K_SINK} -mp.messaging.outgoing.checker_workflow_backend.connector=quarkus-http -mp.messaging.outgoing.checker_workflow_backend.url=${K_SINK} +# Events produced by kogito-addons-quarkus-jobs-knative-eventing to program the timers on the jobs service. +mp.messaging.outgoing.kogito-job-service-job-request-events.connector=quarkus-http +mp.messaging.outgoing.kogito-job-service-job-request-events.url=${K_SINK:http://localhost:8280/v2/jobs/events} +mp.messaging.outgoing.kogito-job-service-job-request-events.method=POST +quarkus.knative.env.vars.github_service_url=knative:serving.knative.dev/v1/Service/github-showcase/github-service -# profile to pack this example into a container, to use it execute activate the maven container profile, -Dcontainer -%container.quarkus.container-image.build=true -%container.quarkus.container-image.push=false -%container.quarkus.container-image.group=${USER} -%container.quarkus.container-image.registry=dev.local -%container.quarkus.container-image.tag=1.0-SNAPSHOT -%container.quarkus.jib.jvm-entrypoint=/home/kogito/kogito-app-launch.sh -%container.quarkus.jib.base-jvm-image=quay.io/kiegroup/kogito-runtime-jvm:latest -%container.quarkus.jib.working-directory=/home/kogito/bin +# This enables Knative to fetch the image information on Minikube. +# You can change this property with -Pknative -Dquarkus.container-image.group from the command line. +quarkus.container-image.build=true +quarkus.container-image.group=dev.local +quarkus.container-image.name=pr-checker-flow +quarkus.kubernetes.deployment-target=knative +quarkus.knative.image-pull-policy=IfNotPresent +quarkus.knative.env.vars.postgres_host=github-showcase-database +quarkus.knative.name=pr-checker-flow +#Optional push to a registry +#quarkus.container-image.registry=quay.io +#quarkus.container-image.push=true +# Kogito Knative integration +# We opt to use the Knative objects instead of the Kogito Source. +org.kie.kogito.addons.knative.eventing.generate-kogito-source=false diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/scripts/add-route-to-hosts.sh b/serverless-workflow-examples/serverless-workflow-github-showcase/scripts/add-route-to-hosts.sh deleted file mode 100755 index cce8fc3fad..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/scripts/add-route-to-hosts.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash -# Copyright 2020 Red Hat, Inc. and/or its affiliates -# -# Licensed 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. - -# see: https://knative.dev/docs/serving/using-a-custom-domain/#local-dns-setup - -ROUTE_NAME=$1 -if [ -z "${ROUTE_NAME}" ]; then - echo "---> Please inform the route name. You can get it by running 'kubectl get route ROUTE -n NAMESPACE'" - exit -fi - -GATEWAY_IP=$(kubectl get svc istio-ingressgateway --namespace istio-system --output jsonpath="{.status.loadBalancer.ingress[*]['ip']}") -if [ -z "${GATEWAY_IP}" ]; then - echo "---> Failed to obtain Gateway IP. Have you run 'minikube tunnel' on a separate terminal?" - exit -fi - -echo "---> Trying to connect to ${GATEWAY_IP}" - -if ! curl -m 3 -vv "${GATEWAY_IP}"; then - echo "---> Failed to reach Istio Ingress endpoint. Have you run 'minikube tunnel' on a separate terminal?" - exit -fi - -DOMAIN_NAME=$(kubectl get route "${ROUTE_NAME}" --output jsonpath="{.status.url}" | cut -d'/' -f 3) -if [ -z "${DOMAIN_NAME}" ]; then - echo "---> Route ${ROUTE_NAME} not valid. You can get it by running 'kubectl get route ROUTE -n NAMESPACE'" - exit -fi - -echo "---> Add the record of Gateway IP and Route domain name into file '/etc/hosts'" -echo -e "${GATEWAY_IP}\t${DOMAIN_NAME}" | sudo tee -a /etc/hosts diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/scripts/cleanup-hosts-file.sh b/serverless-workflow-examples/serverless-workflow-github-showcase/scripts/cleanup-hosts-file.sh deleted file mode 100755 index 50127fdf2e..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/scripts/cleanup-hosts-file.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -# Copyright 2020 Red Hat, Inc. and/or its affiliates -# -# Licensed 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. - -sudo sed -i '/pr-checker-workflow/d' /etc/hosts -sudo sed -i '/github-event-listener/d' /etc/hosts -sudo sed -i '/github-service/d' /etc/hosts -sudo sed -i '/notification-service/d' /etc/hosts \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-github-showcase/scripts/common.sh b/serverless-workflow-examples/serverless-workflow-github-showcase/scripts/common.sh deleted file mode 100755 index cf64493932..0000000000 --- a/serverless-workflow-examples/serverless-workflow-github-showcase/scripts/common.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash -# Copyright 2020 Red Hat, Inc. and/or its affiliates -# -# Licensed 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. - -BUILDER=podman - -function check_binaries() { - local return_code=0 - - if ! command -v kubectl &>/dev/null; then - echo "---> kubectl not found, please install it to run this script" - return_code=1 - fi - - if ! command -v podman &>/dev/null; then - echo "---> podman not found, setting default builder to docker" - BUILDER=docker - if ! command -v docker &>/dev/null; then - echo "---> docker not found, please install it to run this script" && return_code=1 - fi - fi - - return ${return_code} -} - -function build_push_image() { - image_ns=$1 - image_name=$2 - # defining image tag - image_tag="quay.io/${image_ns}/${image_name}:latest" - - echo "---> Building and pushing image using tag ${image_tag}" - # build image - if [ "${BUILDER}" == "docker" ]; then - docker build --tag "${image_tag}" . - docker push "${image_tag}" - else - podman build --tag "${image_tag}" . - podman push "${image_tag}" - fi -}