|
| 1 | + |
| 2 | +## Lab 8: Building microservices on ATP |
| 3 | + |
| 4 | + |
| 5 | +## Introduction |
| 6 | + |
| 7 | +Containers allow us to package apps along with all their dependencies and provide a light-weight run time environment that provides isolation similar to a virtual machine, but without the added overhead of a full-fledged operating system. |
| 8 | + |
| 9 | +The topic of containers and microservices is a subject on its own but suffice to say that breaking up large,complex software into more manageable pieces that run isolated from each other has many advantages. It's easier to deploy, diagnose and provides better availability since failure of any microservice limits downtime to a portion of the application. |
| 10 | + |
| 11 | +It's important to have a similar strategy in the backend for the database tier. But the issue is if you run multiple databases for each application then you end up having to maintain a large fleet of databases and the maintenance costs can go through the roof. Add to that having to manage security and availability for all of them. |
| 12 | + |
| 13 | +This is where the Oracle’s autonomous database cloud service comes in. It is based on a pluggable architecture similar to application containers where one container database holds multiple pluggable databases. Each of these pluggable databases or PDBs are completely isolated from each other, can be deployed quickly and can be managed as a whole so that you incur the cost of managing a single database while deploying multiple micro services onto these PDBs. |
| 14 | + |
| 15 | +The Autonomous cloud service takes it a step further. It is self managing, self securing and highly available. There is no customer involvement in backing it up, patching it or even tuning it for most part. You simply provision, connect and run your apps. Oracle even provides a 99.995 SLA. That is a maximum of 2 minutes, 11.5 seconds of downtime per month. |
| 16 | + |
| 17 | + |
| 18 | +## Objectives |
| 19 | + |
| 20 | +- To build a docker container running node.js microservice |
| 21 | +- Deploy it on an ATP Database service running in the Oracle cloud |
| 22 | + |
| 23 | +## Required Artifacts |
| 24 | + |
| 25 | +- The following lab requires an Oracle Public Cloud account. You may use your own cloud account, a cloud account that you obtained through a trial, or a training account whose details were given to you by an Oracle instructor. |
| 26 | + |
| 27 | +- Lab 5 completed and working |
| 28 | + |
| 29 | +- Create a folder and download this repository |
| 30 | +``` |
| 31 | +$ git clone https://github.com/CloudTestDrive/ATPDocker/ |
| 32 | +
|
| 33 | +``` |
| 34 | + |
| 35 | +Note: Note there are two Docker files in the repository. That’s because we have two different applications–ATPnodeapp and aOne. Both of these are node.js applications which mimic as microservices in our case. |
| 36 | + |
| 37 | +ATPnodeapp simply makes a connection to the ATP database and does not require any schema setup. aOne, on the other hand is a sample marketplace application and requires schema and seed data to be deployed in the backend. If you plan to use that app, you will need to first run the create_schema.sql scripts on the database. |
| 38 | + |
| 39 | +## Steps |
| 40 | +### **STEP 0: Install Docker on Oracle Linux** |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +``` |
| 45 | +# cd /etc/yum.repos.d/ |
| 46 | +# wget http://yum.oracle.com/public-yum-ol7.repo |
| 47 | +# vi public-yum-ol7.repo |
| 48 | +
|
| 49 | +[ol7_UEKR4] |
| 50 | +name=Latest Unbreakable Enterprise Kernel Release 4 for Oracle Linux $releasever ($basearch) |
| 51 | +baseurl=http://yum.oracle.com/repo/OracleLinux/OL7/UEKR4/$basearch/ |
| 52 | +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle |
| 53 | +gpgcheck=1 |
| 54 | +enabled=1 |
| 55 | +
|
| 56 | +[ol7_addons] |
| 57 | +name=Oracle Linux $releasever Add ons ($basearch) |
| 58 | +baseurl=http://yum.oracle.com/repo/OracleLinux/OL7/addons/$basearch/ |
| 59 | +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle |
| 60 | +gpgcheck=1 |
| 61 | +enabled=1 |
| 62 | +
|
| 63 | +# sudo systemctl start docker |
| 64 | +# sudo systemctl enable docker |
| 65 | +# sudo systemctl status docker |
| 66 | +``` |
| 67 | + |
| 68 | +### **STEP 1: Provision an ATP instance and copy secure credential file to application folder** |
| 69 | + |
| 70 | +Provision ATP instance and download secure connectivity credentials file. |
| 71 | + |
| 72 | +Refer to labs <a href="https://github.com/oracle/learning-library/blob/master/workshops/autonomous-transaction-processing/LabGuide100ProvisionAnATPDatabase.md" target="_blank">LabGuide1.md</a> and <a href="https://github.com/oracle/learning-library/blob/master/workshops/autonomous-transaction-processing/LabGuide200SecureConnectivityAndDataAccess.md" target="_blank">LabGuide2.md</a> to provision and download the secure connectivity credentials file. |
| 73 | + |
| 74 | +- NOTE: If you wish to deploy aOne app, you would need to connect to your database using SQL Developer and run the [create_schema](https://github.com/oracle/learning-library/tree/master/autonomous-database/workshops/atp-s/scripts/800/create_schema.sql) script in the default admin schema or create a suitable user schema for the application. |
| 75 | + |
| 76 | + |
| 77 | +``` |
| 78 | +cd /home/opc/ATPDocker/CTD_OOW |
| 79 | +
|
| 80 | +rm -f * |
| 81 | +
|
| 82 | +unzip YOUR_WALLET.zip -d /path_to_app_folder/ATPDocker/CTD_OOW/ |
| 83 | +
|
| 84 | +nano sqlnet.ora |
| 85 | +
|
| 86 | +WALLET_LOCATION = (SOURCE = (METHOD = file) (METHOD_DATA = (DIRECTORY=$TNS_ADMIN))) |
| 87 | +SSL_SERVER_DN_MATCH=yes |
| 88 | +
|
| 89 | +sudo chown 777 /home/opc/ATPDocker/CTD_OOW/ |
| 90 | +
|
| 91 | +export TNS_ADMIN=/home/opc/ATPDocker/CTD_OOW/ |
| 92 | +
|
| 93 | +``` |
| 94 | + |
| 95 | +### **STEP 2: Open OCI PORT and Add Firewall exception** |
| 96 | + |
| 97 | +In order to expose our container to the outside we need to open the port we will use on both OCI's VCN and the firewall. We're gonna use port 3050 so we will open that one. |
| 98 | + |
| 99 | +``` |
| 100 | +firewall-cmd --zone=public --add-port=3050/tcp --permanent |
| 101 | +
|
| 102 | +firewall-cmd --reload |
| 103 | +``` |
| 104 | + |
| 105 | +### **STEP 3: Build your docker image** |
| 106 | + |
| 107 | +Go to aone folder to change the DB credentials |
| 108 | + |
| 109 | +``` |
| 110 | +cd /path_to_app_folder/ATPDocker/aone/scripts/ |
| 111 | +
|
| 112 | +vi dbconfig.js |
| 113 | +``` |
| 114 | +Here you just need to modify it using your credentials. |
| 115 | + |
| 116 | +You need to launch your docker image and change the following |
| 117 | +- dbuser: admin |
| 118 | +- password: WElcome_123# |
| 119 | +- connect string: yourdbname_high |
| 120 | + |
| 121 | +Now we can finally build our application. |
| 122 | + |
| 123 | + |
| 124 | +Assuming you have docker correctly installed you can now build your docker image. |
| 125 | + |
| 126 | + |
| 127 | +``` |
| 128 | +cd /path_to_app_folder/ATPDocker/ |
| 129 | +
|
| 130 | +$ docker build -t aone . |
| 131 | +``` |
| 132 | + |
| 133 | + |
| 134 | +The docker creates multiple image files as it builds each layer. Your final image would show at the top of the list and will have the tag you chose. |
| 135 | + |
| 136 | +``` |
| 137 | +$ docker images -a |
| 138 | +``` |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | +### **STEP 4: Run server.js app** |
| 143 | + |
| 144 | +Within the docker container navigate to aone folder and run server.js script |
| 145 | + |
| 146 | +``` |
| 147 | +cd /opt/oracle/lib/ATPDocker/ |
| 148 | +
|
| 149 | +docker run -i -p 3050:3050 -t nodeapp |
| 150 | +``` |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | +To check the app on the browser, you have bridged port 3050 on the container to your Public IP. |
| 156 | + |
| 157 | +Open browser on your Public IP and go to http://public-ip:3050 |
| 158 | + |
| 159 | + |
| 160 | +You just built and provisioned an entire application stack consisting of a microservice and an enterprise grade, self managing database. You can push your docker image to a public/private docker repository and it can be pushed to any container orchestration service either on-prem or with any cloud provider. Your database is autonomous –it provisions quickly, backs up, patches and tunes itself as needed. |
| 161 | + |
| 162 | + |
| 163 | +- You are now ready to move to the next lab. |
| 164 | + |
0 commit comments