Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KOGITO-8169]- Upgrade Github Showcase Example #1635

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions serverless-workflow-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<module>serverless-workflow-functions-events-quarkus</module>
<module>serverless-workflow-functions-quarkus</module>
<module>serverless-workflow-funqy</module>
<module>serverless-workflow-github-showcase</module>
<module>serverless-workflow-greeting-quarkus</module>
<module>serverless-workflow-greeting-rpc-quarkus</module>
<module>serverless-workflow-hello-world</module>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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`)
Expand All @@ -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
Expand All @@ -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.
kubectl delete ns github-showcase
```
Original file line number Diff line number Diff line change
@@ -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-<servicename>

# 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
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<details><summary>Build logs</summary>
```
// 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
```
</details>
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:

Expand All @@ -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.
Expand All @@ -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.
See the project root's [README](./README.md) documentation.
Loading