├── LICENSE ├── aloha.adoc ├── ansible.adoc ├── ansible ├── 3scale.yml ├── ansible.cfg ├── helloworld-msa.yml ├── inventory ├── jaeger.yaml ├── mysql-pv.yaml ├── pipeline-hola.yml ├── pipeline-pvc.yml ├── setup.yml ├── sso.yml └── vars.yml ├── anyuid.yaml ├── api-gateway.adoc ├── api-management.adoc ├── bonjour.adoc ├── cicd.adoc ├── config.adoc ├── create-project.adoc ├── deployments.adoc ├── frontend.adoc ├── generate-html.sh ├── hello.adoc ├── hola.adoc ├── images ├── abtesting.png ├── bluedeployment.png ├── canarydeployment.png ├── frontend.png ├── greendeployment.png ├── jaeger.png ├── keycloak.png ├── kubeflix.png ├── pipeline.png └── rhdevelopers.png ├── jaeger.adoc ├── kubeflix.adoc.deprecated ├── maintenance.adoc ├── namaste.adoc ├── ola.adoc ├── readme.adoc ├── readme.html ├── setup.adoc ├── sso.adoc └── troubleshooting.adoc /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /aloha.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | ### Deploy aloha (Vert.x) microservice 17 | 18 | #### (Option 1) Deploy project via oc CLI 19 | 20 | ##### Basic project creation 21 | 22 | ---- 23 | $ git clone https://github.com/redhat-helloworld-msa/aloha 24 | $ cd aloha/ 25 | $ oc new-build --binary --name=aloha -l app=aloha 26 | $ mvn package; oc start-build aloha --from-dir=. --follow 27 | $ oc new-app aloha -l app=aloha,hystrix.enabled=true 28 | $ oc expose service aloha 29 | ---- 30 | 31 | ##### Enable Jolokia and Readiness probe 32 | 33 | ---- 34 | $ oc set env dc/aloha AB_ENABLED=jolokia; oc patch dc/aloha -p '{"spec":{"template":{"spec":{"containers":[{"name":"aloha","ports":[{"containerPort": 8778,"name":"jolokia"}]}]}}}}' 35 | $ oc set probe dc/aloha --readiness --get-url=http://:8080/api/health 36 | ---- 37 | 38 | #### (Option 2) Deploy project via Fabric8 Maven Plugin 39 | 40 | ---- 41 | $ mvn package fabric8:deploy 42 | ---- 43 | 44 | #### Test the service endpoint 45 | 46 | ---- 47 | curl http://aloha-helloworld-msa.`minishift ip`.nip.io/api/aloha 48 | ---- 49 | 50 | -------------------------------------------------------------------------------- /ansible.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | 17 | link:https://www.ansible.com/[Ansible] can be used to automate the bootstrap process to setup Helloworld-MSA in CDK. 18 | 19 | Make sure you have the following requirenments installed: 20 | 21 | - Git 22 | - Ansible 2.4+ 23 | - Maven 3.1+ 24 | - JDK 1.8 25 | - NPM 26 | 27 | And run the following commands: 28 | 29 | ---- 30 | $ git clone https://github.com/redhat-helloworld-msa/helloworld-msa 31 | $ cd helloworld-msa/ansible 32 | ---- 33 | 34 | First, *edit the vars.yaml file* to define the *'workdir'* variable and set the absolute path where you want to "git checkout" the source code of the microservices. 35 | 36 | Then execute: 37 | 38 | ---- 39 | $ ansible-playbook helloworld-msa.yml 40 | ---- 41 | 42 | The playbook will take approximately 20 minutes to complete. After that OpenShift should take more 10 minutes to finish the installation and boot of each microservice. The bootstrap process should complete within 30 minutes. 43 | 44 | NOTE: This approach is used to make it easy to create an environment with all pieces of this demo. However in a real MSA environment, each microservice can *and should* be deployed independently. The following instructions allow you to understand the individual process to deploy each microservice. 45 | 46 | -------------------------------------------------------------------------------- /ansible/3scale.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Checkout Api-Management from Github 3 | git: 4 | repo: "https://github.com/redhat-helloworld-msa/api-management" 5 | dest: "{{ workdir }}/api-management" 6 | 7 | - name: Create Api-Management new-build 8 | shell: "oc new-build --binary --name=api-management -l app=api-management -e BACKEND_URL=http://127.0.0.1:8081" 9 | register: command_result 10 | failed_when: "'exists' not in command_result.stderr and command_result.rc != 0" 11 | changed_when: "'exists' not in command_result.stderr" 12 | 13 | - name: Define Api-Management client project and domain 14 | shell: "oc set env bc api-management OS_SUBDOMAIN={{ domain }} OS_PROJECT={{ project_name }}" 15 | register: command_result 16 | failed_when: "'exists' not in command_result.stderr and command_result.rc != 0" 17 | changed_when: "'exists' not in command_result.stderr" 18 | 19 | - name: Build and Api-Management images from the sources 20 | shell: "oc start-build api-management --from-dir={{ workdir }}/api-management --follow" 21 | 22 | - name: Create Api-Management application from previously created images 23 | shell: "oc new-app api-management -l app=api-management" 24 | register: command_result 25 | failed_when: "'exists' not in command_result.stderr and command_result.rc != 0" 26 | changed_when: "'exists' not in command_result.stderr" 27 | 28 | - name: Create Api-Management Readiness Probe 29 | shell: "oc set probe dc api-management --readiness --get-url=http://:8081/status/ready" 30 | register: command_result 31 | 32 | - name: Expose Api-Management routes 33 | shell: "oc expose service api-management --port=8080 --name=api-{{ item.name }} --hostname=api-{{ item.name }}-{{ project_name }}.{{ domain }}" 34 | with_items: "{{ msa_projects }}" 35 | register: command_result 36 | failed_when: "'exists' not in command_result.stderr and command_result.rc != 0" 37 | changed_when: "'exists' not in command_result.stderr" 38 | 39 | - name: Tell frontend to enable Api-Management 40 | shell: "oc set env dc frontend ENABLE_THREESCALE=true" 41 | register: command_result 42 | -------------------------------------------------------------------------------- /ansible/ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | inventory = inventory 3 | -------------------------------------------------------------------------------- /ansible/helloworld-msa.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Install Helloworld-MSA in OpenShift 3 | hosts: local 4 | vars_files: 5 | - vars.yml 6 | tasks: 7 | - name: Login in OpenShift 8 | shell: "oc login --insecure-skip-tls-verify=true -u {{ admin_username }} -p {{ admin_password }} {{ openshift }}" 9 | 10 | - name: Create a new OpenShift project 11 | shell: "oc new-project {{ project_name }}" 12 | register: command_result 13 | failed_when: "'exists' not in command_result.stderr and command_result.rc != 0" 14 | changed_when: "'exists' not in command_result.stderr" 15 | 16 | - name: Define OpenShift project 17 | shell: "oc project {{ project_name }}" 18 | 19 | - include_tasks: setup.yml 20 | tags: 21 | - setup 22 | - compile 23 | 24 | - name: Install Jaeger CRD 25 | shell: "oc apply -f jaeger.yaml" 26 | tags: 27 | - jaeger 28 | 29 | - name: Create OpenShift new-build 30 | shell: "oc new-build --binary --name={{ item.name }} -l app={{ item.name }}" 31 | register: command_result 32 | with_items: "{{ msa_projects }}" 33 | failed_when: "'exists' not in command_result.stderr and command_result.rc != 0" 34 | changed_when: "'exists' not in command_result.stderr" 35 | tags: 36 | - openshift 37 | 38 | - name: Build and Deploy OpenShift images from the sources 39 | shell: "oc start-build {{ item.name }} --from-dir={{ workdir }}/{{ item.name }} --follow" 40 | with_items: "{{ msa_projects }}" 41 | tags: 42 | - openshift 43 | - build 44 | 45 | - name: Create OpenShift applications from previously created images 46 | shell: "oc new-app {{ item.name }} -l app={{ item.name }}" 47 | register: command_result 48 | with_items: "{{ msa_projects }}" 49 | failed_when: "'exists' not in command_result.stderr and command_result.rc != 0" 50 | changed_when: "'exists' not in command_result.stderr" 51 | tags: 52 | - openshift 53 | 54 | - name: Tell microservices where to find the Jaeger server 55 | shell: "oc set env deploy {{ item.name }} ENABLE_JAEGER=true JAEGER_SAMPLER_TYPE=const JAEGER_SAMPLER_PARAM=1 && oc annotate deployment {{ item.name }} 'sidecar.jaegertracing.io/inject=true'" 56 | register: command_result 57 | with_items: "{{ msa_projects }}" 58 | tags: 59 | - jager 60 | - openshift 61 | - opentracing 62 | 63 | - name: Expose OpenShift applications 64 | shell: "oc expose service {{ item.name }} --hostname={{ item.name }}-{{ project_name }}.{{ domain }}" 65 | register: command_result 66 | with_items: "{{ msa_projects }}" 67 | failed_when: "'exists' not in command_result.stderr and command_result.rc != 0" 68 | changed_when: "'exists' not in command_result.stderr" 69 | tags: 70 | - openshift 71 | 72 | - name: Define Frontend domain 73 | shell: "oc set env deploy/frontend OS_SUBDOMAIN={{ domain }}" 74 | tags: 75 | - openshift 76 | 77 | - name: Create OpenShift Readiness Probe for applications 78 | shell: "oc set probe deploy/{{ item.name }} --readiness --get-url={{ item.probe }}" 79 | register: command_result 80 | with_items: "{{ msa_projects }}" 81 | # Avoid projects without probe 82 | when: "item.probe != False" 83 | tags: 84 | - openshift 85 | 86 | # Install SSO 87 | - include_tasks: sso.yml 88 | when: deploy_keycloak or deploy_3scale 89 | tags: 90 | - sso 91 | - 3scale 92 | 93 | # Install Api-Management with 3scale 94 | - include_tasks: 3scale.yml 95 | when: deploy_3scale 96 | tags: 97 | - 3scale 98 | 99 | - name: Use OpenShift MSA project 100 | shell: "oc project {{ project_name }}" 101 | tags: 102 | - openshift 103 | -------------------------------------------------------------------------------- /ansible/inventory: -------------------------------------------------------------------------------- 1 | [local] 2 | localhost ansible_connection=local -------------------------------------------------------------------------------- /ansible/jaeger.yaml: -------------------------------------------------------------------------------- 1 | kind: Jaeger 2 | apiVersion: jaegertracing.io/v1 3 | metadata: 4 | name: my-jaeger 5 | namespace: helloworld-msa 6 | spec: 7 | strategy: allInOne 8 | sampling: 9 | options: 10 | default_strategy: 11 | type: const 12 | param: 1 13 | -------------------------------------------------------------------------------- /ansible/mysql-pv.yaml: -------------------------------------------------------------------------------- 1 | kind: PersistentVolume 2 | apiVersion: v1 3 | metadata: 4 | name: mysql-data 5 | labels: 6 | type: local 7 | spec: 8 | capacity: 9 | storage: 100Mi 10 | accessModes: 11 | - ReadWriteOnce 12 | hostPath: 13 | path: "/tmp/data" -------------------------------------------------------------------------------- /ansible/pipeline-hola.yml: -------------------------------------------------------------------------------- 1 | apiVersion: tekton.dev/v1 2 | kind: Pipeline 3 | metadata: 4 | name: hola-build 5 | namespace: helloworld-msa 6 | spec: 7 | tasks: 8 | - name: git-clone 9 | params: 10 | - name: url 11 | value: "https://github.com/redhat-helloworld-msa/hola.git" 12 | - name: revision 13 | value: "" 14 | - name: refspec 15 | value: "" 16 | - name: submodules 17 | value: "true" 18 | - name: depth 19 | value: "1" 20 | - name: sslVerify 21 | value: "true" 22 | - name: crtFileName 23 | value: ca-bundle.crt 24 | - name: subdirectory 25 | value: "" 26 | - name: sparseCheckoutDirectories 27 | value: "" 28 | - name: deleteExisting 29 | value: "true" 30 | - name: httpProxy 31 | value: "" 32 | - name: httpsProxy 33 | value: "" 34 | - name: noProxy 35 | value: "" 36 | - name: verbose 37 | value: "true" 38 | - name: gitInitImage 39 | value: "registry.redhat.io/openshift-pipelines/pipelines-git-init-rhel8@sha256:66f219b4d54a41b945cb5715ecd1fbb5d25431cf8dad4b06914a4cdc65b298cc" 40 | - name: userHome 41 | value: /home/git 42 | taskRef: 43 | kind: ClusterTask 44 | name: git-clone 45 | workspaces: 46 | - name: output 47 | workspace: Source 48 | - name: maven 49 | params: 50 | - name: MAVEN_IMAGE 51 | value: "registry.redhat.io/ubi8/openjdk-17@sha256:a8165bc2cd5051a96d6937e25ed03155bbd4b731da6e58cebfe2ea83209c16d8" 52 | - name: GOALS 53 | value: 54 | - package 55 | - name: MAVEN_MIRROR_URL 56 | value: "" 57 | - name: SERVER_USER 58 | value: "" 59 | - name: SERVER_PASSWORD 60 | value: "" 61 | - name: PROXY_USER 62 | value: "" 63 | - name: PROXY_PASSWORD 64 | value: "" 65 | - name: PROXY_PORT 66 | value: "" 67 | - name: PROXY_HOST 68 | value: "" 69 | - name: PROXY_NON_PROXY_HOSTS 70 | value: "" 71 | - name: PROXY_PROTOCOL 72 | value: http 73 | - name: CONTEXT_DIR 74 | value: . 75 | runAfter: 76 | - git-clone 77 | taskRef: 78 | kind: ClusterTask 79 | name: maven 80 | workspaces: 81 | - name: source 82 | workspace: Source 83 | - name: maven-settings 84 | workspace: Source 85 | - name: s2i-build 86 | params: 87 | - name: SCRIPT 88 | value: oc start-build hola --from-dir=. --follow 89 | - name: VERSION 90 | value: latest 91 | runAfter: 92 | - maven 93 | taskRef: 94 | kind: ClusterTask 95 | name: openshift-client 96 | workspaces: 97 | - name: manifest-dir 98 | workspace: Source 99 | workspaces: 100 | - name: Source 101 | -------------------------------------------------------------------------------- /ansible/pipeline-pvc.yml: -------------------------------------------------------------------------------- 1 | kind: PersistentVolumeClaim 2 | apiVersion: v1 3 | metadata: 4 | name: pipeline-pvc 5 | namespace: helloworld-msa 6 | finalizers: 7 | - kubernetes.io/pvc-protection 8 | spec: 9 | accessModes: 10 | - ReadWriteMany 11 | resources: 12 | requests: 13 | storage: 1Gi 14 | storageClassName: managed-nfs-storage 15 | volumeMode: Filesystem 16 | -------------------------------------------------------------------------------- /ansible/setup.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Verify if variables are set 3 | fail: 4 | msg: "[Target directory] and/or [OpenShift host] is not defined. Please edit vars.yml" 5 | when: (workdir is undefined) or (openshift is undefined) 6 | 7 | - name: Login in OpenShift as administrator 8 | shell: "oc login --insecure-skip-tls-verify=true -u {{ admin_username }} -p {{ admin_password }} {{ openshift }}" 9 | 10 | - name: Adjust SCC to use AnyUID 11 | shell: "oc apply -f https://raw.githubusercontent.com/redhat-helloworld-msa/helloworld-msa/master/anyuid.yaml" 12 | 13 | - name: Create Workdir 14 | file: 15 | path: "{{ workdir }}" 16 | state: directory 17 | 18 | - name: Checkout source code from Github 19 | git: 20 | repo: "https://github.com/redhat-helloworld-msa/{{ item.name }}" 21 | dest: "{{ workdir }}/{{ item.name }}" 22 | update: yes 23 | with_items: "{{ msa_projects }}" 24 | when: clone_modules 25 | 26 | - name: Compile Java Projects 27 | shell: "mvn -f {{ workdir }}/{{ item.name }}/pom.xml package" 28 | with_items: "{{ msa_projects }}" 29 | when: "item.project == 'java'" 30 | tags: 31 | - build 32 | 33 | - name: NPM install NodeJS Projects 34 | shell: "npm --prefix {{ workdir }}/{{ item.name }} install {{ workdir }}/{{ item.name }}" 35 | with_items: "{{ msa_projects }}" 36 | when: "item.project == 'node'" 37 | tags: 38 | - build 39 | 40 | - name: Install PVC for pipelines 41 | shell: "oc apply -f pipeline-pvc.yml" 42 | when: deploy_tekton 43 | tags: 44 | - cicd 45 | 46 | - name: Install Pipeline for projet Hola 47 | shell: "oc apply -f pipeline-hola.yml" 48 | when: deploy_tekton 49 | tags: 50 | - cicd 51 | -------------------------------------------------------------------------------- /ansible/sso.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Create SSO project 3 | shell: "oc new-project sso || oc project sso" 4 | register: command_result 5 | failed_when: "'exists' not in command_result.stderr and command_result.rc != 0" 6 | changed_when: "'exists' not in command_result.stderr" 7 | tags: 8 | - openshift 9 | - sso 10 | 11 | - name: Checkout SSO from Github 12 | git: 13 | repo: "https://github.com/redhat-helloworld-msa/sso" 14 | dest: "{{ workdir }}/sso" 15 | tags: 16 | - openshift 17 | - sso 18 | 19 | - name: Create Keycloak new-build 20 | shell: "oc new-build --binary --name=keycloak -l app=keycloak" 21 | register: command_result 22 | failed_when: "'exists' not in command_result.stderr and command_result.rc != 0" 23 | changed_when: "'exists' not in command_result.stderr" 24 | tags: 25 | - openshift 26 | - sso 27 | 28 | - name: Build and Deploy Keycloak images from the sources 29 | shell: "oc start-build keycloak --from-dir={{ workdir }}/sso --follow" 30 | tags: 31 | - openshift 32 | - sso 33 | 34 | - name: Create Keycloak application from previously created images 35 | shell: "oc new-app keycloak -l app=keycloak" 36 | register: command_result 37 | failed_when: "'exists' not in command_result.stderr and command_result.rc != 0" 38 | changed_when: "'exists' not in command_result.stderr" 39 | tags: 40 | - openshift 41 | - sso 42 | 43 | - name: Define Keycloak client project and domain 44 | shell: "oc set env deploy keycloak OS_SUBDOMAIN={{ domain }} OS_PROJECT={{ project_name }}" 45 | register: command_result 46 | failed_when: "'exists' not in command_result.stderr and command_result.rc != 0" 47 | changed_when: "'exists' not in command_result.stderr" 48 | tags: 49 | - openshift 50 | - sso 51 | 52 | - name: Expose Keycloak application 53 | shell: "oc expose service keycloak --port=8080 --hostname=keycloak-sso.{{ domain }}" 54 | register: command_result 55 | failed_when: "'exists' not in command_result.stderr and command_result.rc != 0" 56 | changed_when: "'exists' not in command_result.stderr" 57 | 58 | - name: Create Keycloak Readiness Probe 59 | shell: "oc set probe deploy keycloak --readiness --get-url=http://:8080/auth" 60 | register: command_result 61 | 62 | - name: Use OpenShift MSA project 63 | shell: "oc project {{ project_name }}" 64 | 65 | - name: Tell microservices where to find the Keycloak server 66 | shell: "oc set env deploy {{ item.name }} KEYCLOAK_AUTH_SERVER_URL=http://keycloak-sso.{{ domain }}/auth ENABLE_SSO=true" 67 | register: command_result 68 | with_items: "{{ msa_projects }}" 69 | # Avoid projects without sso support 70 | when: "item.sso_support != False" 71 | -------------------------------------------------------------------------------- /ansible/vars.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Define the Absolute path where you want to checkout the sourcecode 3 | workdir: "./helloworld-msa-src" 4 | # UNCOMENT Define the OpenShift host:port address 5 | # openshift: api.cluster-XXXX.dynamic.redhatworkshops.io:6443 6 | # UNCOMENT Customize the domain of the project 7 | # domain: apps.cluster-XXXXX.dynamic.redhatworkshops.io 8 | # Administrative credentials 9 | admin_username: admin 10 | admin_password: XXXXX 11 | # Define the name of the OpenShift project 12 | project_name: helloworld-msa 13 | 14 | # Optional parts 15 | # Some users might have the MSA modules cloned locally already. For those cases, make this 'false' and 16 | # we'll not attempt to clone it again 17 | clone_modules: true 18 | 19 | # Define if we should deploy CI/CD capabilities with Tekton 20 | deploy_tekton: true 21 | #Define if we should deploy Keycloak for SSO 22 | deploy_keycloak: true 23 | #Define if we should deploy Api Management with 3scale 24 | deploy_3scale: false 25 | 26 | # Project definition - You don't need to change anything here 27 | msa_projects: 28 | - name: hola 29 | project: java 30 | probe: http://:8080/api/health 31 | sso_support: true 32 | - name: frontend 33 | project: node 34 | probe: http://:8080/ 35 | sso_support: true 36 | - name: bonjour 37 | project: node 38 | probe: http://:8080/api/health 39 | sso_support: true 40 | - name: api-gateway 41 | project: java 42 | probe: http://:8080/health 43 | sso_support: false 44 | - name: ola 45 | project: java 46 | probe: http://:8080/api/health 47 | sso_support: true 48 | - name: aloha 49 | project: java 50 | probe: http://:8080/api/health 51 | sso_support: true 52 | -------------------------------------------------------------------------------- /anyuid.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: security.openshift.io/v1 2 | kind: SecurityContextConstraints 3 | metadata: 4 | name: anyuid 5 | allowHostDirVolumePlugin: false 6 | allowHostIPC: false 7 | allowHostNetwork: false 8 | allowHostPID: false 9 | allowHostPorts: false 10 | allowPrivilegedContainer: false 11 | allowedCapabilities: null 12 | allowedFlexVolumes: null 13 | defaultAddCapabilities: null 14 | fsGroup: 15 | type: RunAsAny 16 | groups: 17 | - system:cluster-admins 18 | - system:authenticated 19 | priority: 10 20 | readOnlyRootFilesystem: false 21 | requiredDropCapabilities: 22 | - MKNOD 23 | runAsUser: 24 | type: RunAsAny 25 | seLinuxContext: 26 | type: MustRunAs 27 | supplementalGroups: 28 | type: RunAsAny 29 | users: [] 30 | volumes: 31 | - configMap 32 | - downwardAPI 33 | - emptyDir 34 | - persistentVolumeClaim 35 | - projected 36 | - secret 37 | -------------------------------------------------------------------------------- /api-gateway.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | ### Deploy api-gateway (Spring Boot) 17 | 18 | The API-Gateway is a microservices architectural pattern. For more information about this pattern, visit: http://microservices.io/patterns/apigateway.html 19 | 20 | 21 | #### (Option 1) Deploy project via oc CLI 22 | 23 | ##### Basic project creation 24 | 25 | ---- 26 | $ git clone https://github.com/redhat-helloworld-msa/api-gateway 27 | $ cd api-gateway/ 28 | $ oc new-build --binary --name=api-gateway -l app=api-gateway 29 | $ mvn package; oc start-build api-gateway --from-dir=. --follow 30 | $ oc new-app api-gateway -l app=api-gateway,hystrix.enabled=true 31 | $ oc expose service api-gateway 32 | ---- 33 | 34 | ##### Enable Jolokia and Readiness probe 35 | 36 | ---- 37 | $ oc set env dc/api-gateway AB_ENABLED=jolokia; oc patch dc/api-gateway -p '{"spec":{"template":{"spec":{"containers":[{"name":"api-gateway","ports":[{"containerPort": 8778,"name":"jolokia"}]}]}}}}' 38 | $ oc set probe dc/api-gateway --readiness --get-url=http://:8080/health 39 | ---- 40 | 41 | #### (Option 2) Deploy project via Fabric8 Maven Plugin 42 | 43 | ---- 44 | $ mvn package fabric8:deploy 45 | ---- 46 | 47 | 48 | #### Test the endpoint 49 | 50 | ---- 51 | curl http://api-gateway-helloworld-msa.`minishift ip`.nip.io/api/gateway 52 | ---- 53 | -------------------------------------------------------------------------------- /api-management.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | ### Use API Management to take control of your microservices 17 | 18 | APIcast (https://github.com/3scale/apicast) is an Open Source API Gateway whose main focus areas are high performance and extensibility. It is part of the Redhat 3scale API Management solution, and is used by hundreds of companies around the world to expose their APIs in a secure and controlled way. 19 | 20 | #### Prerequistes 21 | 22 | Install and enable SSO before using this module. SSO is used to issue the JWT tokens during the OpenID Connect (http://openid.net/connect/) over OAuth 2.0 standard code flow to enable the secure connection to the gateway. 23 | 24 | #### Create a custom API Management build 25 | 26 | ---- 27 | $ git clone https://github.com/redhat-helloworld-msa/api-management 28 | $ cd api-management/ 29 | $ oc new-build --binary --name api-management -e BACKEND_URL=http://127.0.0.1:8081 30 | ---- 31 | 32 | ##### Specify the OpenShift domain 33 | 34 | ---- 35 | $ oc set env bc/api-management OS_SUBDOMAIN= 36 | 37 | #Using CDK3 38 | $ oc set env bc/api-management OS_SUBDOMAIN=$(minishift ip).nip.io 39 | 40 | #Example: OS_SUBDOMAIN=192.168.64.11.nip.io 41 | $ oc set env bc/api-management OS_SUBDOMAIN=192.168.64.11.nip.io 42 | ---- 43 | 44 | #### Create a custom API Management instance 45 | 46 | ---- 47 | $ oc start-build api-management --from-dir=. --follow 48 | $ oc new-app api-management 49 | $ oc expose svc/api-management --name api-bonjour 50 | $ oc expose svc/api-management --name api-hola 51 | $ oc expose svc/api-management --name api-ola 52 | $ oc expose svc/api-management --name api-aloha 53 | ---- 54 | 55 | ##### (Optional) Enable Readiness probe 56 | 57 | ---- 58 | $ oc set probe dc/api-management --readiness --get-url=http://:8081/status/ready 59 | ---- 60 | 61 | #### Tell frontend to enable API Management 62 | 63 | ---- 64 | $ oc set env dc/frontend ENABLE_THREESCALE=true 65 | ---- 66 | 67 | 68 | #### Test the API Management Integration 69 | 70 | After enabling the API Management use case, you will see a new Tab (or two if you haven't previously enabled SSO) containing the new scenario. 71 | 72 | * Click in the API Management tab and you will see a new panel with the information of your deployed services. 73 | * Click the Refresh results link, if you are not logged in, you will see the services failing with an "Unauthorized" error. 74 | * Log in using the link in the top right corner using the user/user credentials. 75 | * After the page refresh click again in the API Management tab. 76 | * Click the Refresh Results link to call the managed API endpoints. You will see the same results as calling them from the browser tab. 77 | * Click the link again 6 more times in less than a minute. 78 | 79 | Did you notice that now the `bonjour` service failed with a HTTP 429 Too Many Requests error? The 3scale APIcast allows you to gate (secure or protect) your endopoint without the need to change or add new endpoint in your code. You can proxy your service and add policies, like enabling CORS, doing URL Rewrite or edge rate limiting with a simple configuration. -------------------------------------------------------------------------------- /bonjour.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | ### Deploy bonjour (NodeJS) microservice 17 | 18 | Choose one of the following options/approaches to deploy this microservice. 19 | 20 | #### Deploy project via oc CLI 21 | 22 | ##### Basic project creation 23 | 24 | ---- 25 | $ git clone https://github.com/redhat-helloworld-msa/bonjour 26 | $ cd bonjour/ 27 | $ oc new-build --binary --name=bonjour -l app=bonjour 28 | $ npm install; oc start-build bonjour --from-dir=. --follow 29 | $ oc new-app bonjour -l app=bonjour 30 | $ oc expose service bonjour 31 | ---- 32 | 33 | ##### Enable Readiness probe 34 | 35 | ---- 36 | $ oc set probe dc/bonjour --readiness --get-url=http://:8080/api/health 37 | ---- 38 | 39 | #### Test the service endpoint 40 | 41 | ---- 42 | curl http://bonjour-helloworld-msa.`minishift ip`.nip.io/api/bonjour 43 | ---- 44 | 45 | -------------------------------------------------------------------------------- /cicd.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | ## Use case: CI/CD Pipeline 17 | 18 | 19 | ### Deploy Jenkins 20 | 21 | Give Jenkins an admin privilege 22 | 23 | ---- 24 | $ oc login -u admin -p admin 25 | $ oc adm policy add-cluster-role-to-user cluster-admin system:serviceaccount:ci:jenkins -n ci 26 | ---- 27 | 28 | 29 | Install the Jenkins/OpenShift Pipeline BuildConfig in another project 30 | 31 | ---- 32 | $ oc login -u developer -p developer 33 | $ oc new-project ci 34 | $ oc create -f https://raw.githubusercontent.com/redhat-helloworld-msa/aloha/master/pipeline.yml 35 | $ oc project helloworld-msa 36 | ---- 37 | 38 | 39 | Once approved, the fixed project will be applied to the `"production"`. 40 | 41 | - First introduce `an error` in the production. 42 | 43 | ---- 44 | $ cd aloha/ 45 | $ vim src/main/java/com/redhat/developers/msa/aloha/AlohaVerticle.java 46 | 47 | # replace return String.format("Aloha mai %s", hostname); 48 | # by return String.format("Aloca mai %s", hostname); 49 | ---- 50 | 51 | - Deploy the erroneous version in the production area. 52 | 53 | ---- 54 | $ mvn clean package; oc start-build aloha --from-dir=. --follow 55 | ---- 56 | 57 | Now Browse to the `ci` project and select `Builds` -> `Pipelines` in the lateral menu. 58 | Click on the gray button called `Start Pipeline`. 59 | 60 | image::images/pipeline.png[] 61 | 62 | 63 | The projects `helloworld-msa-dev` and `helloworld-msa-qa` will be created automatically according to the link:https://github.com/redhat-helloworld-msa/aloha/blob/master/Jenkinsfile[defined Pipeline]. 64 | 65 | You will need to manually approve the deployment to production. 66 | 67 | -------------------------------------------------------------------------------- /config.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | ## Use case: Configuring your application 17 | 18 | link:https://github.com/redhat-helloworld-msa/hola[hola] microservice uses link:http://deltaspike.apache.org/documentation/configuration.html[DeltaSpike Configuration] to obtain the phrase that is displayed. 19 | 20 | DeltaSpike allows the configuration to come from different *ConfigSources* (System properties, Environment variables, JNDI value, Properties file values). The microservices needs a configuration value called "hello" to display the provided value. If no value is informed, the default value (Hola de %s) is used. 21 | 22 | We will use 2 different approaches to configure "hola" microservice: 23 | 24 | - Environment variables 25 | - link:https://docs.openshift.com/enterprise/3.2/dev_guide/configmaps.html[Openshift ConfigMaps] 26 | 27 | 28 | 29 | ### Environment variables 30 | 31 | Update the DeploymentConfig: 32 | 33 | ---- 34 | $ oc set env dc/hola hello="Hola de Env var" 35 | 36 | # To unset the env var 37 | $ oc set env dc/hola hello- 38 | ---- 39 | 40 | ### ConfigMaps 41 | 42 | As you've seen, the definition of environment variables causes the DeploymentConfig to recreate the pods with that value set. OpenShift 3.2 allows the use of ConfigMaps 43 | 44 | #### Create a ConfigMap from an existing file: 45 | 46 | ---- 47 | $ cd hola/ 48 | $ oc create configmap translation --from-file=translation.properties 49 | $ oc get configmap translation -o yaml 50 | ---- 51 | 52 | #### Mount a volume from ConfigMap 53 | 54 | Here we are creating a mounted volume in all pods that reads the file. 55 | 56 | ---- 57 | $ oc patch dc/hola -p '{"spec":{"template":{"spec":{"containers":[{"name":"hola","volumeMounts":[{"name":"config-volume","mountPath":"/etc/config"}]}],"volumes":[{"name":"config-volume","configMap":{"name":"translation"}}]}}}}' 58 | ---- 59 | 60 | #### Update the microservice to read the file 61 | 62 | The POD needs a Java System Property to inform the location of the file. 63 | 64 | ---- 65 | $ oc set env dc/hola JAVA_OPTIONS="-Dconf=/etc/config/translation.properties" 66 | ---- 67 | 68 | After the deployment, check that the config is present 69 | 70 | ---- 71 | $ oc get pods -l app=hola 72 | $ oc rsh hola-?-????? 73 | sh-4.2$ cat /etc/config/translation.properties 74 | sh-4.2$ exit 75 | ---- 76 | 77 | Update the ConfigMap and wait the POD to get updated. 78 | 79 | ---- 80 | $ oc edit configmap translation 81 | ---- 82 | 83 | NOTE: The synchronization between the ConfigMap and the mounted volume takes some time to be performed 84 | 85 | -------------------------------------------------------------------------------- /create-project.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | ## Create a project 17 | 18 | In Openshift, click in the `"New Project"` button. Give it the name **"helloworld-msa"** 19 | 20 | IMPORTANT: You must use the exact project name since it will affect the generate endpoint's URLs 21 | 22 | Or run: 23 | ---- 24 | $ oc login :8443 -u developer -p developer 25 | $ oc new-project helloworld-msa 26 | ---- 27 | 28 | //// 29 | 30 | ### Create all the services from a simple file. (No builder images) 31 | 32 | WARNING: This doesn't install the builder images. Any change on the source, the pod should be built again using the instructions from each service. 33 | 34 | NOTE: First you will need to fetch all pre-built docker images. The following commands will do that. It should take some minutes to complete since it will download aproximatelly 2.5 GB. 35 | 36 | ---- 37 | $ cd / 38 | $ eval "$(vagrant service-manager env docker)" 39 | $ docker pull docker.io/redhatmsa/aloha; docker pull docker.io/redhatmsa/api-gateway; docker pull docker.io/redhatmsa/bonjour; docker pull docker.io/redhatmsa/frontend; docker pull docker.io/redhatmsa/hello; docker pull docker.io/redhatmsa/hola; docker pull docker.io/redhatmsa/namaste; docker pull docker.io/redhatmsa/ola; docker pull docker.io/fabric8/hystrix-dashboard:1.0.15; docker pull docker.io/fabric8/turbine-server:1.0.15 40 | ---- 41 | 42 | Once that all images are available in the CDK internal registry, you can create the Openshift resources using *oc* command. 43 | 44 | ---- 45 | $ oc login 10.1.2.2:8443 -u openshift-dev -p devel 46 | $ oc new-project helloworld-msa 47 | $ oc create -f https://raw.githubusercontent.com/redhat-helloworld-msa/helloworld-msa/master/helloworld-msa.json 48 | $ oc policy add-role-to-user admin system:serviceaccount:helloworld-msa:turbine 49 | ---- 50 | 51 | TIP: If any pods become "yellow"/"pending". Scale down it to 0 replicas and then scale it up again. 52 | 53 | If you want to install each service individually, follow the instructions bellow. 54 | 55 | //// -------------------------------------------------------------------------------- /deployments.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | == Use case: Deployment Patterns 17 | 18 | === Blue/Green deployment 19 | 20 | Blue/Green deployment is a technique where two different environments/versions (Blue and Green) of the same application are running in parallel but only one of them is receiving requests from the router at a time. 21 | 22 | To release a new version, the router is updated to switch between the "Blue" environment and point to the "Green" environment. 23 | 24 | image::images/greendeployment.png[] 25 | 26 | We can use 2 different approaches to perform Blue/Gren deployment: 27 | 28 | - Changing the Routes 29 | - Changing the Services 30 | 31 | ==== Blue/Green deployment using Routes 32 | 33 | This strategy is based on link:https://github.com/openshift/origin/tree/master/examples/deployment#blue-green-deployment[Openshift deployment examples] and it uses the `API-Gateway` project, but it could be used with any other project: 34 | 35 | - Modify the service. 36 | ---- 37 | $ cd /api-gateway 38 | 39 | $ vim src/main/java/com/redhat/developers/msa/api_gateway/CamelRestEndpoints.java 40 | 41 | # replace .transform().body(List.class, list -> list) 42 | # by .transform().body(List.class, list -> list.stream().map(res -> "UPDATED - " + res).collect(java.util.stream.Collectors.toList())) 43 | ---- 44 | 45 | - Create a `"new"` version of the application using a **different name**.. 46 | ---- 47 | $ oc new-build --binary --name=api-gateway-blue -l app=api-gateway-blue 48 | $ mvn package && oc start-build api-gateway-blue --from-dir=. --follow 49 | $ oc new-app api-gateway-blue -l app=api-gateway-blue,hystrix.enabled=true 50 | ---- 51 | 52 | - Enable Readiness probe 53 | ---- 54 | $ oc set probe dc/api-gateway-blue --readiness --get-url=http://:8080/health 55 | ---- 56 | 57 | - Switch the route to the `"new"` application. 58 | ---- 59 | $ oc patch route/api-gateway -p '{"spec": {"to": {"name": "api-gateway-blue" }}}' 60 | 61 | # To return to the "old" application 62 | $ oc patch route/api-gateway -p '{"spec": {"to": {"name": "api-gateway" }}}' 63 | ---- 64 | 65 | - (Optional) Remove the "old" version. 66 | ---- 67 | $ oc delete is,bc,dc,svc api-gateway 68 | $ oc delete builds -l build=api-gateway 69 | ---- 70 | 71 | ==== Blue/Green deployment using Services 72 | 73 | This approach is more suitable for Services with internal access only. It will modify the existing Kubernetes Service to point to the new DeploymentConfig 74 | 75 | - Modify the service. 76 | ---- 77 | $ cd /bonjour 78 | 79 | $ vim lib/api.js 80 | 81 | # go to line 32 82 | # replace const sayBonjour = () => `Bonjour de ${os.hostname()}`; 83 | # by const sayBonjour = () => `Version 2 - Bonjour de ${os.hostname()}`; 84 | ---- 85 | 86 | - Create a `"new"` version of the application using a **different name**. 87 | ---- 88 | $ oc new-build --binary --name=bonjour-new 89 | $ npm install && oc start-build bonjour-new --from-dir=. --follow 90 | $ oc new-app bonjour-new 91 | ---- 92 | 93 | - Enable Readiness probe 94 | ---- 95 | $ oc set probe dc/bonjour-new --readiness --get-url=http://:8080/api/health 96 | ---- 97 | 98 | - Switch the Service to the `"new"` application. 99 | ---- 100 | $ oc patch svc/bonjour -p '{"spec":{"selector":{"app":"bonjour-new","deploymentconfig":"bonjour-new"}}}' 101 | 102 | # To return to the "old" application 103 | $ oc patch svc/bonjour -p '{"spec":{"selector":{"app":"bonjour","deploymentconfig":"bonjour"}}}' 104 | ---- 105 | 106 | === Canary deployments 107 | 108 | Canary deployments are a way of sending out a new version of your app into production that plays the role of a “canary” to get an idea of how it will perform (integrate with other apps, CPU, memory, disk usage, etc). Canary releases let you test the waters before pulling the trigger on a full release. 109 | 110 | image::images/canarydeployment.png[] 111 | 112 | This strategy is based on link:https://github.com/openshift/origin/tree/master/examples/deployment#rolling-deployments-with-canary-checks[Openshift deployment examples] and it uses the `Bonjour` project, but it could be used with any other project: 113 | 114 | - Modify the service. 115 | ---- 116 | $ cd /bonjour 117 | 118 | $ vim lib/api.js 119 | 120 | # go to line 32 121 | # replace const sayBonjour = () => `Bonjour de ${os.hostname()}`; 122 | # by const sayBonjour = () => `Version 2 - Bonjour de ${os.hostname()}`; 123 | ---- 124 | 125 | - Create a `"new"` version of the application using a **different name**.. 126 | ---- 127 | $ oc new-build --binary --name=bonjour-new 128 | $ npm install && oc start-build bonjour-new --from-dir=. --follow 129 | $ oc new-app bonjour-new 130 | ---- 131 | 132 | - Enable Readiness probe 133 | ---- 134 | $ oc set probe dc/bonjour-new --readiness --get-url=http://:8080/api/health 135 | ---- 136 | 137 | - Apply a common label (svc=canary-bonjour) for both versions 138 | ---- 139 | $ oc patch dc/bonjour -p '{"spec":{"template":{"metadata":{"labels":{"svc":"canary-bonjour"}}}}}' 140 | $ oc patch dc/bonjour-new -p '{"spec":{"template":{"metadata":{"labels":{"svc":"canary-bonjour"}}}}}' 141 | ---- 142 | 143 | - Update the Service to point to the new label 144 | ---- 145 | $ oc patch svc/bonjour -p '{"spec":{"selector":{"svc":"canary-bonjour","app": null, "deploymentconfig": null}, "sessionAffinity":"ClientIP"}}' 146 | ---- 147 | 148 | - Simulate multiple clients 149 | ---- 150 | $ oc scale dc/bonjour --replicas=3 151 | 152 | # Simulate 10 new clients and note that 25% of the requests are made on bonjour-new. 153 | $ for i in {1..10}; do curl http://bonjour-helloworld-msa.`minishift ip`.nip.io/api/bonjour ; echo ""; done; 154 | 155 | # Simulate the same client 156 | $ curl -b cookies.txt -c cookies.txt http://bonjour-helloworld-msa.$(minishift ip).nip.io/api/bonjour 157 | 158 | # To change the credentials, delete the cookies file 159 | $ rm cookies.txt 160 | ---- 161 | 162 | - To return to the original state 163 | ---- 164 | $ oc scale dc/bonjour --replicas=1 165 | $ oc delete all -l app=bonjour-new 166 | $ oc patch svc/bonjour -p '{"spec":{"selector":{"svc":null ,"app": "bonjour", "deploymentconfig": "bonjour"}, "sessionAffinity":"None"}}' 167 | ---- -------------------------------------------------------------------------------- /frontend.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | ### Deploy frontend (NodeJS/HTML5/JS) 17 | 18 | image::images/frontend.png[] 19 | 20 | Choose one of the following options/approaches to deploy the UI. 21 | 22 | #### Deploy project via oc CLI 23 | 24 | ##### Basic project creation 25 | 26 | ---- 27 | $ git clone https://github.com/redhat-helloworld-msa/frontend 28 | $ cd frontend/ 29 | $ oc new-build --binary --name=frontend -l app=frontend 30 | $ npm install; oc start-build frontend --from-dir=. --follow 31 | $ oc new-app frontend -l app=frontend 32 | $ oc expose service frontend 33 | ---- 34 | 35 | 36 | ##### Specify the OpenShift domain 37 | 38 | ---- 39 | $ oc set env dc/frontend OS_SUBDOMAIN= 40 | 41 | # Using CDK 42 | $ oc set env dc/frontend OS_SUBDOMAIN=`minishift ip`.nip.io 43 | 44 | # Example: OS_SUBDOMAIN=192.168.64.11.nip.io 45 | $ oc set env dc/frontend OS_SUBDOMAIN=192.168.64.11.nip.io 46 | ---- 47 | 48 | ##### (Optional) Enable Readiness probe 49 | 50 | ---- 51 | $ oc set probe dc/frontend --readiness --get-url=http://:8080/ 52 | ---- 53 | 54 | 55 | #### Test the service endpoint 56 | 57 | Access: http://frontend-helloworld-msa./ 58 | 59 | 60 | -------------------------------------------------------------------------------- /generate-html.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | asciidoctor readme.adoc 4 | open readme.html -------------------------------------------------------------------------------- /hello.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | ## Deploy the hello (JAX-RS/EAP) microservice 17 | 18 | Choose one of the following options/approaches to deploy this microservice. 19 | 20 | ### Option 1: Deploy using Fabric8 plugin 21 | 22 | Execute: 23 | 24 | ---- 25 | $ git clone https://github.com/redhat-helloworld-msa/hello 26 | $ cd hello/ 27 | $ mvn clean package docker:build fabric8:json fabric8:apply -Popenshift 28 | ---- 29 | 30 | ### Option 2: Deploy project via oc CLI 31 | 32 | #### Basic project creation 33 | 34 | ---- 35 | $ git clone https://github.com/redhat-helloworld-msa/hello 36 | $ cd hello/ 37 | $ oc new-build --binary --name=hello -l app=hello 38 | $ mvn package -Popenshift; oc start-build hello --from-dir=. --follow 39 | $ oc new-app hello -l app=hello,hystrix.enabled=true 40 | $ oc expose service hello 41 | ---- 42 | 43 | #### (Optional) Enable Jolokia and Readiness probe 44 | 45 | ---- 46 | $ oc patch dc/hello -p '{"spec":{"template":{"spec":{"containers":[{"name":"hello","ports":[{"containerPort": 8778,"name":"jolokia"}]}]}}}}' 47 | $ oc patch dc/hello -p '{"spec":{"template":{"spec":{"containers":[{"name":"hello","readinessProbe":{"httpGet":{"path":"/api/health","port":8080}}}]}}}}' 48 | ---- 49 | 50 | //// 51 | 52 | ### Option 3: Deploy project using EAP 7.0 (Beta) builder template/imagestream 53 | 54 | ---- 55 | $ oc login 10.1.2.2:8443 (login with openshift-dev/devel credentials) 56 | $ oc create -n helloworld-msa -f https://raw.githubusercontent.com/jboss-openshift/application-templates/ose-v1.3.0-1/jboss-image-streams.json 57 | ---- 58 | 59 | #### Option 3.1 - Using oc CLI 60 | 61 | Execute: 62 | 63 | ---- 64 | $ oc new-app --name hello jboss-eap70-openshift:1.3-Beta~https://github.com/redhat-helloworld-msa/hello -l app=hello,hystrix.enabled=true 65 | $ oc expose service hello 66 | $ oc logs -f bc/hello 67 | ---- 68 | 69 | #### Option 3.2 - Using Openshift console 70 | 71 | - Select `jboss-eap70-openshift:1.3-Beta` xpaas builder image 72 | - Name: `hello` 73 | - Git URL: https://github.com/redhat-helloworld-msa/hello 74 | - Click on `"Show advanced build and deployment options"` 75 | - Add the label **hystrix.enabled** with the value **true** 76 | - Click on `"Create"`. And them click on `"Continue to overview"` 77 | - Wait for the build to complete. (You can click `"View log"` to follow the build logs) 78 | 79 | //// 80 | 81 | ### Test the service endpoint 82 | 83 | Access: http://hello-helloworld-msa.rhel-cdk.10.1.2.2.xip.io/api/hello -------------------------------------------------------------------------------- /hola.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | ### Deploy hola (JAX-RS/Microprofile/Thorntail) microservice 17 | 18 | #### (Option 1) Deploy project via oc CLI 19 | 20 | ##### Basic project creation 21 | 22 | ---- 23 | $ git clone https://github.com/redhat-helloworld-msa/hola 24 | $ cd hola/ 25 | $ oc new-build --binary --name=hola -l app=hola 26 | $ mvn package; oc start-build hola --from-dir=. --follow 27 | $ oc new-app hola -l app=hola,hystrix.enabled=true 28 | $ oc expose service hola 29 | ---- 30 | 31 | ##### Enable Readiness probe 32 | 33 | ---- 34 | $ oc set probe dc/hola --readiness --get-url=http://:8080/api/health 35 | ---- 36 | 37 | #### (Option 2) Deploy project via Fabric8 Maven Plugin 38 | 39 | ---- 40 | $ mvn package fabric8:deploy 41 | ---- 42 | 43 | #### Test the service endpoint 44 | 45 | ---- 46 | curl http://hola-helloworld-msa.`minishift ip`.nip.io/api/hola 47 | ---- 48 | 49 | -------------------------------------------------------------------------------- /images/abtesting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redhat-helloworld-msa/helloworld-msa/bfa4e64cb6be57d0c630c1ed7439303bb898df38/images/abtesting.png -------------------------------------------------------------------------------- /images/bluedeployment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redhat-helloworld-msa/helloworld-msa/bfa4e64cb6be57d0c630c1ed7439303bb898df38/images/bluedeployment.png -------------------------------------------------------------------------------- /images/canarydeployment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redhat-helloworld-msa/helloworld-msa/bfa4e64cb6be57d0c630c1ed7439303bb898df38/images/canarydeployment.png -------------------------------------------------------------------------------- /images/frontend.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redhat-helloworld-msa/helloworld-msa/bfa4e64cb6be57d0c630c1ed7439303bb898df38/images/frontend.png -------------------------------------------------------------------------------- /images/greendeployment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redhat-helloworld-msa/helloworld-msa/bfa4e64cb6be57d0c630c1ed7439303bb898df38/images/greendeployment.png -------------------------------------------------------------------------------- /images/jaeger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redhat-helloworld-msa/helloworld-msa/bfa4e64cb6be57d0c630c1ed7439303bb898df38/images/jaeger.png -------------------------------------------------------------------------------- /images/keycloak.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redhat-helloworld-msa/helloworld-msa/bfa4e64cb6be57d0c630c1ed7439303bb898df38/images/keycloak.png -------------------------------------------------------------------------------- /images/kubeflix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redhat-helloworld-msa/helloworld-msa/bfa4e64cb6be57d0c630c1ed7439303bb898df38/images/kubeflix.png -------------------------------------------------------------------------------- /images/pipeline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redhat-helloworld-msa/helloworld-msa/bfa4e64cb6be57d0c630c1ed7439303bb898df38/images/pipeline.png -------------------------------------------------------------------------------- /images/rhdevelopers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redhat-helloworld-msa/helloworld-msa/bfa4e64cb6be57d0c630c1ed7439303bb898df38/images/rhdevelopers.png -------------------------------------------------------------------------------- /jaeger.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | ### Deploy Jaeger 17 | 18 | http://uber.github.io/jaeger/[Jaeger] is a fully compatible http://www.opentracing.io[OpenTracing] distributed tracing system. 19 | It helps gather timing data needed to troubleshoot latency problems in microservice architectures. 20 | 21 | The https://github.com/uber/jaeger[jaeger project] provides all the required resources to start the Jaeger components to trace your microservices. 22 | 23 | image::images/jaeger.png[] 24 | 25 | The figure shows a trace detail view for one invocation of the service chaining. 26 | We can see the invocation start time, total duration, number of services being invoked and also 27 | a total number of spans (an operation in the system). 28 | 29 | The showed timeline view allows us to understand 30 | relationships between invocations (serial vs parallel) and examine durations of these operations. 31 | A span also carries contextual logs and tags which can be queried. Each line represents one span so 32 | we can drill down to and see what happened at an operation level in the monitored system. 33 | 34 | #### Deploy using Openshift Opertor 35 | 36 | See: 37 | 38 | 39 | -------------------------------------------------------------------------------- /kubeflix.adoc.deprecated: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | ### Deploy Kubeflix 17 | 18 | https://github.com/fabric8io/kubeflix[Kubeflix] provides http://kubernetes.io/[Kubernetes] integration with https://netflix.github.io/[Netflix] open source components such as https://github.com/Netflix/Hystrix[Hystrix], https://github.com/Netflix/Turbine[Turbine] and https://github.com/Netflix/Ribbon[Ribbon]. 19 | 20 | Specifically it provides: 21 | 22 | * Kubernetes Instance Discovery for Turbine and Ribbon 23 | * Kubernetes configuration and images for Turbine Server and Hystrix Dashboard 24 | 25 | image::images/kubeflix.png[] 26 | 27 | #### Deploy using oc CLI 28 | 29 | Execute: 30 | 31 | ---- 32 | $ oc process -f http://central.maven.org/maven2/io/fabric8/kubeflix/packages/kubeflix/1.0.17/kubeflix-1.0.17-kubernetes.yml | oc create -f - 33 | $ oc expose service hystrix-dashboard --port=8080 34 | $ oc policy add-role-to-user admin system:serviceaccount:helloworld-msa:turbine 35 | ---- 36 | 37 | #### Enable the Hystrix Dashboard in the Frontend 38 | 39 | Execute: 40 | ---- 41 | $ oc set env dc/frontend ENABLE_HYSTRIX=true 42 | ---- 43 | 44 | #### Test the hystrix-dashboard 45 | 46 | Access: http://hystrix-dashboard-helloworld-msa./ 47 | 48 | -------------------------------------------------------------------------------- /maintenance.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | ## Maintenance (Only for redhatmsa admins) 17 | 18 | ### Deploy the microservices images to Docker Hub 19 | 20 | To deploy the microservices images you have to run the following commands from inside the vagrant box (vagrant ssh): 21 | 22 | ---- 23 | # vagrant ssh 24 | 25 | 26 | # due to a new docker.io registry, you will need to specify the v1 version 27 | 28 | # vi ~/.docker/config.json 29 | # replace "docker.io" 30 | # by "https://index.docker.io/v1/" 31 | 32 | $ oc login -u admin -p admin localhost --insecure-skip-tls-verify=true 33 | $ oc project default 34 | 35 | #### use the email and password of redhatmsa #### 36 | $ docker login #login with user redhatmsa 37 | 38 | $ registry=`oc get service docker-registry --template '{{.spec.portalIP}}'`; declare -a arr=("bonjour" "frontend"); for i in "${arr[@]}"; do image=`docker images $registry:5000/helloworld-msa/$i|awk 'NR==2'`; echo "Taging $image"; id=$(echo $image|awk '{print $3}'); docker tag -f $id docker.io/redhatmsa/$i; echo "Pushing $id from $image"; docker push -f docker.io/redhatmsa/$i; done; declare -a arr2=("hello" "hola" "aloha" "ola" "namaste" "api-gateway"); for i in "${arr2[@]}"; do image=`docker images redhatmsa/$i|awk 'NR==2'`; echo "Taging $image"; id=$(echo $image|awk '{print $3}'); docker tag -f $id docker.io/redhatmsa/$i:latest; echo "Pushing $id from $image"; docker push -f docker.io/redhatmsa/$i:latest; done 39 | ---- 40 | 41 | -------------------------------------------------------------------------------- /namaste.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | ## Deploy namaste (Dropwizard) microservice 17 | 18 | Choose one of the following options/approaches to deploy this microservice. 19 | 20 | ### Option 1: Deploy using Fabric8 plugin 21 | 22 | Execute: 23 | 24 | ---- 25 | $ git clone https://github.com/redhat-helloworld-msa/namaste 26 | $ cd namaste/ 27 | $ mvn clean package docker:build fabric8:json fabric8:apply 28 | ---- 29 | 30 | ### Option 2: Deploy project via oc CLI 31 | 32 | #### Basic project creation 33 | 34 | ---- 35 | $ git clone https://github.com/redhat-helloworld-msa/namaste 36 | $ cd namaste/ 37 | $ oc new-build --binary --name=namaste -l app=namaste 38 | $ mvn package; oc start-build namaste --from-dir=. --follow 39 | $ oc new-app namaste -l app=namaste,hystrix.enabled=true 40 | $ oc expose service namaste 41 | ---- 42 | 43 | #### (Optional) Enable Jolokia and Readiness probe 44 | 45 | ---- 46 | $ oc patch dc/namaste -p '{"spec":{"template":{"spec":{"containers":[{"name":"namaste","ports":[{"containerPort": 8778,"name":"jolokia"}]}]}}}}' 47 | $ oc patch dc/namaste -p '{"spec":{"template":{"spec":{"containers":[{"name":"namaste","readinessProbe":{"httpGet":{"path":"/api/health","port":8080}}}]}}}}' 48 | ---- 49 | 50 | ### Test the service endpoint 51 | 52 | Access: http://namaste-helloworld-msa.rhel-cdk.10.1.2.2.xip.io/api/namaste 53 | -------------------------------------------------------------------------------- /ola.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | ### Deploy ola (Spring Boot) microservice 17 | 18 | #### (Option 1) Deploy project via oc CLI 19 | 20 | ##### Basic project creation 21 | 22 | ---- 23 | $ git clone https://github.com/redhat-helloworld-msa/ola 24 | $ cd ola/ 25 | $ oc new-build --binary --name=ola -l app=ola 26 | $ mvn package; oc start-build ola --from-dir=. --follow 27 | $ oc new-app ola -l app=ola,hystrix.enabled=true 28 | $ oc expose service ola 29 | ---- 30 | 31 | ##### Enable Jolokia and Readiness probe 32 | 33 | ---- 34 | $ oc set env dc/ola AB_ENABLED=jolokia; oc patch dc/ola -p '{"spec":{"template":{"spec":{"containers":[{"name":"ola","ports":[{"containerPort": 8778,"name":"jolokia"}]}]}}}}' 35 | $ oc set probe dc/ola --readiness --get-url=http://:8080/api/health 36 | ---- 37 | 38 | #### (Option 2) Deploy project via Fabric8 Maven Plugin 39 | 40 | ---- 41 | $ mvn package fabric8:deploy 42 | ---- 43 | 44 | 45 | #### Test the service endpoint 46 | 47 | ---- 48 | curl http://ola-helloworld-msa.`minishift ip`.nip.io/api/ola 49 | ---- 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /readme.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | # Helloworld-MSA (Microservices architecture) 17 | http://developers.redhat.com 18 | :toc: macro 19 | :toc-title: Table of Contents 20 | :toclevels: 3 21 | :icons: font 22 | :data-uri: 23 | :source-highlighter: coderay 24 | 25 | This content is brought to you by http://developers.redhat.com - Register today! 26 | 27 | image::images/rhdevelopers.png[] 28 | 29 | Latest HTML: 30 | http://bit.ly/msa-tutorial 31 | 32 | This is the frontend screenshot that you will see after the deployment of all microservices: 33 | 34 | image::images/frontend.png[] 35 | 36 | toc::[] 37 | 38 | include::setup.adoc[] 39 | 40 | ## Install Microservices 41 | 42 | ### (Option 1) Install all microservices using Ansible 43 | 44 | include::ansible.adoc[] 45 | 46 | ### (Option 2) Install each microservice individually 47 | 48 | include::create-project.adoc[] 49 | 50 | include::hola.adoc[] 51 | 52 | include::aloha.adoc[] 53 | 54 | include::ola.adoc[] 55 | 56 | include::bonjour.adoc[] 57 | 58 | include::api-gateway.adoc[] 59 | 60 | include::frontend.adoc[] 61 | 62 | #include::kubeflix.adoc[] 63 | 64 | include::jaeger.adoc[] 65 | 66 | include::sso.adoc[] 67 | 68 | include::api-management.adoc[] 69 | 70 | include::config.adoc[] 71 | 72 | include::deployments.adoc[] 73 | 74 | include::cicd.adoc[] 75 | 76 | include::troubleshooting.adoc[] 77 | 78 | -------------------------------------------------------------------------------- /setup.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | ## Prepare Environment 17 | 18 | If you don't have an OpenShift instance running, we strongly suggest that you use minishift 19 | 20 | 21 | ### (Option 1) Use minishift (OpenShift 3.11) 22 | 23 | Download Minishift from link:https://github.com/minishift/minishift/releases[minishift]. 24 | 25 | Execute: 26 | 27 | ---- 28 | $ minishift profile set msa-tutorial 29 | $ minishift config set memory 8GB 30 | $ minishift config set cpus 3 31 | $ minishift config set image-caching true 32 | $ minishift config set openshift-version v3.11.0 33 | $ minishift addons enable anyuid 34 | $ minishift addons enable admin-user 35 | $ minishift start 36 | $ eval $(minishift oc-env) 37 | ---- 38 | 39 | #### Access Openshift console 40 | 41 | Open Openshift console: https://:8443/console/ + 42 | (Accept the certificate and proceed) 43 | 44 | Log in Openshift + 45 | Use **developer/developer** as your credentials 46 | 47 | -------------------------------------------------------------------------------- /sso.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | ### Use a SSO server to secure microservices 17 | 18 | http://www.keycloak.org/[Keycloak] is an open source Identity and Access Management solution aimed at modern applications and services. It makes it easy to secure applications and services with little to no code. 19 | 20 | Users authenticate with Keycloak rather than individual applications. This means that your applications don't have to deal with login forms, authenticating users, and storing users. Once logged-in to Keycloak, users don't have to login again to access a different application. 21 | 22 | This also applied to logout. Keycloak provides single-sign out, which means users only have to logout once to be logged-out of all applications that use Keycloak. 23 | 24 | image::images/keycloak.png[] 25 | 26 | #### Create a project for the SSO 27 | 28 | ---- 29 | $ oc new-project sso 30 | ---- 31 | 32 | #### Deploy a custom Keycloak instance 33 | 34 | ---- 35 | $ git clone https://github.com/redhat-helloworld-msa/sso 36 | $ cd sso/ 37 | $ oc new-build --binary --name keycloak 38 | $ oc start-build keycloak --from-dir=. --follow 39 | $ oc new-app keycloak 40 | $ oc expose svc/keycloak 41 | ---- 42 | 43 | ##### (Optional) Enable Readiness probe 44 | 45 | ---- 46 | $ oc set probe dc/keycloak --readiness --get-url=http://:8080/auth 47 | ---- 48 | 49 | ##### Specify the OpenShift domain 50 | 51 | ---- 52 | $ oc set env dc/keycloak OS_SUBDOMAIN= 53 | 54 | #Using CDK3 55 | $ oc set env dc/keycloak OS_SUBDOMAIN=app.$(minishift ip).nip.io 56 | 57 | #Example: OS_SUBDOMAIN=app.192.168.64.11.nip.io 58 | $ oc set env dc/keycloak OS_SUBDOMAIN=app.192.168.64.11.nip.io 59 | ---- 60 | 61 | #### Tell microservices where to find the Keycloak server 62 | 63 | ---- 64 | $ oc project helloworld-msa 65 | 66 | # Using CDK3 67 | $ oc set env dc KEYCLOAK_AUTH_SERVER_URL=http://keycloak-sso.`minishift ip`.nip.io/auth -l app 68 | 69 | # Example: OS_SUBDOMAIN=192.168.64.11.nip.io 70 | $ oc set env dc KEYCLOAK_AUTH_SERVER_URL=http://keycloak-sso.192.168.64.11.nip.io/auth -l app 71 | 72 | $ oc set env dc/frontend ENABLE_SSO=true 73 | ---- 74 | -------------------------------------------------------------------------------- /troubleshooting.adoc: -------------------------------------------------------------------------------- 1 | // JBoss, Home of Professional Open Source 2 | // Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual 3 | // contributors by the @authors tag. See the copyright.txt in the 4 | // distribution for a full listing of individual contributors. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | == Troubleshooting 17 | 18 | === Running in the cloud 19 | 20 | You can easily customize the frontend to access the a new domain using the following command: 21 | 22 | ---- 23 | $ oc set env dc/frontend OS_SUBDOMAIN=app.redhatmsa.com 24 | 25 | # If you deployed SSO/keycloak 26 | $ oc set env dc/keycloak --namespace=sso OS_SUBDOMAIN=app.redhatmsa.com 27 | ---- 28 | --------------------------------------------------------------------------------