# Lab 1: First Microservice 本範例使用IBM開源程式碼將佈署於OpenShift Container Platform * 登入方法: https://hackmd.io/@mGh414xAR8-m-StRhI7Gww/ry8tnH9rP * 常見問題: https://hackmd.io/@j_cw20OeTZ-9cHj3CCAW6Q/HkvO7c8uP 1. PHP 前端應用程式: https://github.com/IBM/php-s2i-openshift 2. Java 後端患者資料應用程式: https://github.com/IBM/example-health-jee-openshift 3. MySQL 資料庫: 已預先於OpenShift建立,透過Cluster IP連線即可 --- ### 前置作業 - 帳號 - Github - 命令列工具 - git - mvn --- ### Step * 建立前端患者資料顯示頁面 Lab1-1 建立 PHP 前端應用程式 (2分) * 建立後端患者資料應用程式 Lab1-2 編譯 Java 應用程式 (1分) Lab1-3 上傳已編譯應用程式 (1分) Lab1-4 建立 Secret (1分) Lab1-5 在 OpenShift Web UI 建立 Java 應用程式 (2分) Lab1-6 前端應用程式與 Java API 整合 (1分) --- ### 建立前端患者資料顯示頁面 #### Lab1-1 建立 PHP 前端應用程式 (2分) * 透過Web UI建立PHP前端應用程式 Developer +Add From Catelog: PHP ![](https://i.imgur.com/7bibdfa.png) ![](https://i.imgur.com/1osDQ3C.png) ![](https://i.imgur.com/4dIvsYf.png) * Builder Image Version: 7.2 ![](https://i.imgur.com/Sb7tlZA.png) * Git Repo URL: https://github.com/IBM/php-s2i-openshift Show Advanced Git Options Context Dir: src ![](https://i.imgur.com/bSDXyUX.png) * Name: php ![](https://i.imgur.com/kzBsGna.png) * 產生公開路由 ![](https://i.imgur.com/9BtZQkT.png) * 啟動成功 ![](https://i.imgur.com/6t0GI3C.png) * 測試是否成功 (此時尚未建立JAVA後端患者資料應用程式故以PHP前端應用程式內的測試資料顯示) ![](https://i.imgur.com/zH3vBjm.png) ![](https://i.imgur.com/ll8FPUV.png) ### 建立後端患者資料應用程式 #### Lab1-2 編譯 Java 應用程式 (1分) * git fork https://github.com/IBM/example-health-jee-openshift ![](https://i.imgur.com/bgtxdbn.png) * 複製到local端 ``` C:\Users\YOURUSER\Desktop\NCCU> git clone https://github.com/你的Github帳號/example-health-jee-openshift ``` * 切換到專案位置example-health-jee-opshift/example-health-api ``` C:\Users\YOURUSER\Desktop\NCCU> cd example-health-jee-openshift/example-health-api ``` * 編譯並打包java ``` C:\Users\YOURUSER\Desktop\NCCU\example-health-jee-openshift\example-health-api> mvn clean package ``` #### Lab1-3 上傳已編譯應用程式 (1分) * 把打包出來的war檔上傳到 https://github.com/你的Github帳號/example-health-jee-opshift/example-health-api/liberty ![](https://i.imgur.com/mS6DD8w.png) ![](https://i.imgur.com/JrVrf88.png) ![](https://i.imgur.com/ZcQjZG0.png) * 修改Dockerfile ![](https://i.imgur.com/d1FNybE.png) * 修改target ![](https://i.imgur.com/hrii2Mb.png) * 改為liberty ![](https://i.imgur.com/87XIgDX.png) * Commit Change ![](https://i.imgur.com/jqYBoka.png) #### Lab1-4 建立 Secret (1分) * 建立資料庫帳密Secret ![](https://i.imgur.com/ZU7PsR1.png) * Secret Name: db-secrets Key: env_mysql_url Value: jdbc:mysql://172.21.116.116:3306/sampledb * Key: env_mysql_user Value: admin * Key: env_mysql_pwd Value: admin ![](https://i.imgur.com/KRtLedB.png) ![](https://i.imgur.com/oJ8GSn1.png) ![](https://i.imgur.com/vPph5ou.png) #### Lab1-5 在 OpenShift Web UI 建立 Java 應用程式 (2分) * 透過Web UI建立Java應用程式 Developer +Add From Dockerfile ![](https://i.imgur.com/eOAiXy1.png) * Git Repo URL: https://github.com/YOURGITACCOUNT/example-health-jee-openshift Show Advanced Git Options Context Dir: example-health-api ![](https://i.imgur.com/LvArok5.png) * Container Port: 9080 ![](https://i.imgur.com/p1XLPBA.png) * Name: java-api ![](https://i.imgur.com/mO9jYKz.png) * 產生公開路由 ![](https://i.imgur.com/3Qe0uLY.png) * 把Secret注入到Deployment ![](https://i.imgur.com/b4VkKQL.png) ![](https://i.imgur.com/dU8nlmV.png) * 啟動成功 ![](https://i.imgur.com/Vf0dDF5.png) * 測試Java API是否啟動成功 Java API 的URL/openapi/ui/ ![](https://i.imgur.com/y9gSU79.png) ![](https://i.imgur.com/aPLg36P.png) * 測試Java API是否連結MySQL成功 Java API 的URL/resources/v1/getInfo/patients ![](https://i.imgur.com/MUjqrKg.png) ![](https://i.imgur.com/nadvjDh.png) ![](https://i.imgur.com/YShDAoI.png) #### Lab1-6 前端應用程式與 Java API 整合 (1分) * 設定 Java API url Key: apiBaseUrl Value: Java API 的URL ![](https://i.imgur.com/KnrIafI.png) ![](https://i.imgur.com/bc3JvqP.png) * 存檔並重新建立 ![](https://i.imgur.com/sMViaZ9.png) * 測試前端應用程式是否能從Java API取得資料 ![](https://i.imgur.com/4GpbUDQ.png)