diff --git a/README.md b/README.md index 70cd61d8d2..acd40a4249 100644 --- a/README.md +++ b/README.md @@ -108,3 +108,8 @@ shows timers (intermediate and boundary) that allows to introduce delays in proc Every example has a directory named `operator` including the YAML files to deploy it using the Kogito Operator in an OpenShift cluster. Please refer to the [Kogito Documentation](https://docs.jboss.org/kogito/release/latest/html_single/#chap_kogito-deploying-on-openshift) of how to install the operator to your environment in order to try it there. + +## Deploying the Kogito example applications locally with OpenShift CRC using Ansible playbooks + +In the [Kogito Ansible folder](kogito-ansible/README.md) you find the documentation plus some external videos about how to +setup Openshift locally (CRC) and deploy the kogito examples using ansible, with few commands \ No newline at end of file diff --git a/kogito-ansible/README.md b/kogito-ansible/README.md new file mode 100644 index 0000000000..405f3c3d44 --- /dev/null +++ b/kogito-ansible/README.md @@ -0,0 +1,57 @@ +# Openshift (CRC) Kogito ansible automation + +### Prerequisite +Tested on Fedora 31/32 +Default values for the installation are 13GB of ram and 22GB of diskspace. + +Ansible scripts to automate creation of CRC cluster and the deploy of one of the Kogito examples with just one command line. +[Ansible must be installed](https://docs.ansible.com/ansible/latest/installation_guide/index.html) +. + + +### Create an account on cloud.redhat.com +https://cloud.redhat.com/openshift/install and download or copy your Pull secret from the laptop installation https://cloud.redhat.com/openshift/install/crc/installer-provisioned + + +## Fedora + +### Install LibVirt libs +```sh +sudo ansible-playbook ./playbook_libs.yaml +``` + +### Install CRC +(If you haven't already installed) + +Download and copy CRC in the user's path (2GB), +change the app_name (my-kafka-project) in the file if you want different name +```sh +ansible-playbook ./playbook_crc.yaml +``` + +### Install Kogito on CRC +The create playbook will create from scratch the crc setup, the project namespace, then download and install Kogito Operator and Kogito CLI. +The name of the Project to create and the Pull secret will be asked in the beginning of the run. +To use the default project name (my-kogito-project) just press enter. +```sh +ansible-playbook ./playbook_create.yaml +``` + +### Deploy Kogito Examples +To deploy one of the kogito examples, enter the name of one of the example, +at the end the browser show you the login page, the output of the deploy with the instructions to see +the logs from cli will be on the ansible output. +```sh +ansible-playbook ./playbook_deploy.yaml +``` + +## Videos +Note: The CRC start spent 10 minute on a laptop, cut to few seconds in the video recording + +### Setup CRC +Video Duration: 1:39 min. +[![asciicast](https://asciinema.org/a/313700.png)](https://asciinema.org/a/313700) + +### Deploy Kpgotp Examples +Video Duration 27:sec +[![asciicast](https://asciinema.org/a/313703.png)](https://asciinema.org/a/313703) diff --git a/kogito-ansible/playbook_crc.yaml b/kogito-ansible/playbook_crc.yaml new file mode 100644 index 0000000000..434a3048d2 --- /dev/null +++ b/kogito-ansible/playbook_crc.yaml @@ -0,0 +1,84 @@ +--- +- name: Install CRC + hosts: localhost + + vars: + release_file: "https://mirror.openshift.com/pub/openshift-v4/clients/crc/latest/release-info.json" + crc_url_file: "https://mirror.openshift.com/pub/openshift-v4/clients/crc/latest/crc-linux-amd64.tar.xz" + + pre_tasks: + + - name : read json + uri: + url: "{{ release_file }}" + return_content: yes + timeout: 60 + register: jsoncontent + + - set_fact: + crcVersion: "{{ jsoncontent.json.version.crcVersion }}" + register: crcVersion + + - debug: msg="Crc version {{ crcVersion }}" + + - set_fact: + openshiftVersion: "{{ jsoncontent.json.version.openshiftVersion }}" + register: openshiftVersion + + - debug: msg="Openshift version {{ openshiftVersion }}" + + + - set_fact: + crc_tmp_dest: "/tmp/crc-linux-{{ crcVersion }}-amd64.tar.xz" + register: crc_tmp_dest + + - set_fact: + crc_package_name: "crc-linux-{{ crcVersion }}-amd64" + register: crc_package_name + + tasks: + - + - name: Create .local/bin/ + file: + path: /home/{{ansible_user_id}}/.local/bin/ + state: directory + + - name: Check if crc exists in /home/{{ansible_user_id}}/.local/bin/ + stat: + path: "/home/{{ ansible_user_id }}/.local/bin/crc" + register: stat_result + + - name: Check if crc-linux-{{ crcVersion }}-amd64 /crc exists in /tmp/ + stat: + path: "/tmp/{{ crc_package_name }}/crc" + register: stat_result + + - name: "Download crc ~2GB into {{ crc_tmp_dest }}, this takes time and depends on your connection speed" + get_url: + url: "{{ crc_url_file }}" + dest: "{{ crc_tmp_dest }}" + when: stat_result.stat.exists == False + + - name: Extract {{ crc_package_name }}.tar.xz into tmp + unarchive: + src: "{{ crc_tmp_dest }}" + dest: /tmp + when: stat_result.stat.exists == False + + - name: Check if {{ crc_package_name }}/crc exists in /tmp/ + stat: + path: "/tmp/{{ crc_package_name }}/crc" + register: stat_result + + - name: Check if crc exists in /home/{{ansible_user_id}}/.local/bin/ + stat: + path: "/home/{{ ansible_user_id }}/.local/bin/crc" + register: stat_result + when: stat_result.stat.exists == True + + - name: Move crc from /tmp/crc-linux-{{crcVersion}}-amd64 to /home/{{ansible_user_id}}/.local/bin + command: "mv /tmp/{{ crc_package_name }}/crc /home/{{ansible_user_id}}/.local/bin/" + when: stat_result.stat.exists == False + + - name: crc libvirt group + shell: "crc config set skip-check-user-in-libvirt-group true" \ No newline at end of file diff --git a/kogito-ansible/playbook_create.yaml b/kogito-ansible/playbook_create.yaml new file mode 100644 index 0000000000..5f02a3ce4a --- /dev/null +++ b/kogito-ansible/playbook_create.yaml @@ -0,0 +1,169 @@ +--- +- name: Start CRC and deploy Kogito Operator and CLI + hosts: localhost + + vars: + release_file: "https://mirror.openshift.com/pub/openshift-v4/clients/crc/latest/release-info.json" + + vars_prompt: + - name: "nameSpace" + default: "my-kogito-project" + prompt: "Insert your Project Name/ NameSpace" + private: "no" + - name: "PullSecret" + prompt: "Insert your Pull secret" + - name: "ram" + default: "13312" + prompt: "Ram used in #MB" + private: "no" + - name: "kogitoTag" + default: "0.10.0" + prompt: "Kogito CLI and Operator tag" + private: "no" + + pre_tasks: + + - name: read json + uri: + url: "{{ release_file }}" + timeout: 60 + return_content: yes + register: jsoncontent + + - set_fact: + crcVersion: "{{ jsoncontent.json.version.crcVersion }}" + register: crcVersion + + - debug: msg="Crc version {{ crcVersion }}" + + - set_fact: + openshiftVersion: "{{ jsoncontent.json.version.openshiftVersion }}" + register: openshiftVersion + + - debug: msg="Openshift version {{ openshiftVersion }}" + + - debug: msg="Kogito CLI tag:{{ kogitoTag }}" + + - set_fact: + kogito_url_file: "https://github.com/kiegroup/kogito-cloud-operator/releases/download/{{ kogitoTag }}/kogito-cli-{{ kogitoTag }}-linux-amd64.tar.gz" + + - set_fact: + kogito_tmp_dest: "/tmp/kogito-{{ kogitoTag }}-linux-amd64.tar.gz" + + + tasks: + - debug: msg="Project Name {{ nameSpace }}" + + - name: Check that kogito cli exists in /home/{{ansible_user_id}}/.local/bin/ + stat: + path: "/home/{{ ansible_user_id }}/.local/bin/kogito" + register: stat_result + + - name: Copy Kogito cli + get_url: + url: "{{kogito_url_file}}" + dest: "{{ kogito_tmp_dest }}" + when: stat_result.stat.exists == False + + - name: Extract Kogito cli archive + unarchive: + src: "{{ kogito_tmp_dest }}" + dest: "/tmp/" + when: stat_result.stat.exists == False + + - name: Creates user home kogito dir + file: + path: "/home/{{ ansible_user_id}}/.local/bin/" + state: directory + when: stat_result.stat.exists == False + + - name: Move kogito from /tmp to /home/{{ansible_user_id}}/.local/bin + command: "mv /tmp/kogito /home/{{ansible_user_id}}/.local/bin/" + when: stat_result.stat.exists == False + + - name: CRC setup + shell: "crc setup" + register: crc_result + + - debug: msg="{{ crc_result }}" + + - name: Write pull secret + copy: + content: "{{ PullSecret }}" + dest: "~/.crc/crc-pull-secret" + + - name: Copy Kogito Examples pom + copy: + src: "./../pom.xml" + dest: "/tmp/examples_pom.xml" + + - name: "Get Kogito Examples " + shell: xmllint --xpath '/*[local-name()="project"]/*[local-name()="modules"]' /tmp/examples_pom.xml > ~/.crc/kogito-examples.txt + + - name: Replace modules tags + replace: + path: ~/.crc/kogito-examples.txt + regexp: '' + replace: '' + + - name: Replace module tags + replace: + path: ~/.crc/kogito-examples.txt + regexp: '' + replace: '- ' + + - name: Replace end module tags + replace: + path: ~/.crc/kogito-examples.txt + regexp: '' + replace: '' + + - name: Replace end modules tags + replace: + path: ~/.crc/kogito-examples.txt + regexp: '' + replace: '\n' + + - name: Start CRC with {{ ram }}MB (~ 10 minutes) + shell: "crc start -m {{ ram }} -p ~/.crc/crc-pull-secret" + + - set_fact: + kube_password: "{{ lookup('file', '/home/{{ ansible_user_id }}/.crc/cache/crc_libvirt_{{ openshiftVersion }}/kubeadmin-password') }}" + + - name: Login crc + shell: "oc login -u kubeadmin -p {{ kube_password }} https://api.crc.testing:6443" + + - name: Create {{ nameSpace }} + shell: "oc new-project {{ nameSpace }}" + + - name: Use {{ nameSpace }} proect + shell: "oc project {{ nameSpace }}" + + - name: Kogito use {{ nameSpace }} + shell: "kogito use-project {{ nameSpace }}" + register: kogito_use_project_result + ignore_errors: yes + + - debug: msg="{{ kogito_use_project_result }}" + + - name: Kogito install operator on {{ nameSpace }} + shell: "kogito install operator -p {{ nameSpace }}" + register: kogito_install_operator_result + + - name: Check AvailableReplica on Kogito operator first on {{ nameSpace }} + shell: "kubectl get pods --selector=name=kogito-operator -o jsonpath='{.items[*].status.phase}'" + register: result_one + + - debug: msg="{{ result_one }}" + + - name: Check AvailableReplica on Kogito operator first on {{ nameSpace }} wait for up to 120 sec, poll every 10 sec, 12 times + shell: "kubectl get pods --selector=name=kogito-operator -o jsonpath='{.items[*].status.phase}'" + register: result + until: result.stdout.find("Running") != -1 + async: 120 + poll: 10 + retries: 12 + + - debug: msg="Project Name {{ nameSpace }}" + + - debug: msg="Your Kube Password is {{ kube_password }}" \ No newline at end of file diff --git a/kogito-ansible/playbook_deploy.yaml b/kogito-ansible/playbook_deploy.yaml new file mode 100644 index 0000000000..d04fb97828 --- /dev/null +++ b/kogito-ansible/playbook_deploy.yaml @@ -0,0 +1,73 @@ +--- + - name: Start CRC and deploy kogito examples + hosts: localhost + + vars: + release_file: "https://mirror.openshift.com/pub/openshift-v4/clients/crc/latest/release-info.json" + examples: "{{ lookup('file', '~/.crc/kogito-examples.txt') }}" + examples_repo: "https://github.com/kiegroup/kogito-examples/" + + vars_prompt: + - name: "ram" + default: "13312" + prompt: "Ram used in MB, 13312 ->13GB" + private: "no" + + - name: "nameSpace" + prompt: "Insert your Project Name/ NameSpace" + default: "my-kogito-project" + private: "no" + + - name: "example" + prompt: "Choose the example to deploy" + default: "\n{{ examples }}" + private: "no" + + pre_tasks: + + - name: read json + uri: + url: "{{ release_file }}" + return_content: yes + register: jsoncontent + + - set_fact: + openshiftVersion: "{{ jsoncontent.json.version.openshiftVersion }}" + register: openshiftVersion + + - debug: msg="Openshift version {{ openshiftVersion }}" + + tasks: + + - debug: msg="Project Name {{ nameSpace }}" + + - name: Start CRC with {{ ram }}MB (~ 10 minutes) + shell: "crc start -m {{ ram }} -p ~/.crc/crc-pull-secret" + + - name: Login crc + shell: "oc login -u kubeadmin -p {{ kube_password }} https://api.crc.testing:6443" + ignore_errors: yes + + - name: Kogito use {{ nameSpace }} + shell: "kogito use-project {{ nameSpace }}" + register: kogito_use_project_result + ignore_errors: yes + + - debug: msg="{{ kogito_use_project_result }}" + + - name: Deploy {{ example }} + shell: "kogito deploy-service {{ example }} {{ examples_repo }} --context-dir={{ example }}" + register: install_drools_quarkus_example + ignore_errors: yes + + - debug: msg="{{ install_drools_quarkus_example }}" + + - debug: msg="Project Name {{ nameSpace }}" + + - set_fact: + kube_password: "{{ lookup('file', '/home/{{ ansible_user_id }}/.crc/cache/crc_libvirt_{{ openshiftVersion }}/kubeadmin-password') }}" + + - debug: msg="Your Kube Password is {{ kube_password }}" + + - name: Open browser + shell: "crc console" \ No newline at end of file diff --git a/kogito-ansible/playbook_libs.yaml b/kogito-ansible/playbook_libs.yaml new file mode 100644 index 0000000000..3ad4243916 --- /dev/null +++ b/kogito-ansible/playbook_libs.yaml @@ -0,0 +1,18 @@ +--- +- name: Install libs on Fedora + hosts: localhost + + tasks: + + - name: CheckOS + assert: + that: + - "ansible_os_family == 'RedHat'" + + + - name: Install Virtualization on Fedora + dnf: + name: + - "@virtualization" + become: yes + when: ansible_os_family == 'RedHat' \ No newline at end of file