diff --git a/mtdrworkshop/addAndSourcePropertiesInBashrc.sh b/mtdrworkshop/addAndSourcePropertiesInBashrc.sh deleted file mode 100644 index 9739a0a..0000000 --- a/mtdrworkshop/addAndSourcePropertiesInBashrc.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -## MyToDoReact version 1.0. -## -## Copyright (c) 2021 Oracle, Inc. -## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ - -echo "export MTDRWORKSHOP_LOCATION=~/mtdrworkshop/" >> ~/.bashrc -echo "source ~/mtdrworkshop/mtdrworkshop.properties" >> ~/.bashrc -source ~/.bashrc diff --git a/mtdrworkshop/addOCIRInfo.sh b/mtdrworkshop/addOCIRInfo.sh deleted file mode 100644 index 57d521c..0000000 --- a/mtdrworkshop/addOCIRInfo.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -## MyToDoReact version 1.0. -## -## Copyright (c) 2021 Oracle, Inc. -## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ - -if [[ $1 == "" ]] -then - echo MTDRWORKSHOP_OCIR_NAMESPACE not provided - echo Required arguments are MTDRWORKSHOP_OCIR_NAMESPACE and MTDRWORKSHOP_REPOS_NAME. - echo Usage example : ./addOCIRInfo.sh axkcsk2aiatb mtdrworkshop.user1/mtdrworkshop - exit -fi - -if [[ $2 == "" ]] -then - echo MTDRWORKSHOP_REPOS_NAME not provided - echo Required arguments are MTDRWORKSHOP_OCIR_NAMESPACE and MTDRWORKSHOP_REPOS_NAME. - echo Usage example : ./addOCIRInfo.sh axkcsk2aiatb mtdrworkshop.user1/mtdrworkshop - exit -fi - -export WORKINGDIR=workingdir -echo WORKINGDIR = $WORKINGDIR - -export MTDRWORKSHOP_OCIR_NAMESPACE=$1 -echo $MTDRWORKSHOP_OCIR_NAMESPACE | tr -d '"' > $WORKINGDIR/mtdrworkshopocirnamespace.txt -echo MTDRWORKSHOP_OCIR_NAMESPACE... $MTDRWORKSHOP_OCIR_NAMESPACE - -export MTDRWORKSHOP_REPOS_NAME=$2 -echo $MTDRWORKSHOP_REPOS_NAME | tr -d '"' > $WORKINGDIR/mtdrworkshopreposname.txt -echo MTDRWORKSHOP_REPOS_NAME... $MTDRWORKSHOP_REPOS_NAME diff --git a/mtdrworkshop/backend/Readme.md b/mtdrworkshop/backend/Readme.md deleted file mode 100644 index 43a7af1..0000000 --- a/mtdrworkshop/backend/Readme.md +++ /dev/null @@ -1,210 +0,0 @@ -# Backend - -## Introduction - -In this lab, you will deploy the pre-built Helidon Java backend Docker image to OKE, then configure the API Gateway. - -Estimated time: ~25-minutes. - -### Objectives - -* Set values for environment variables -* Build and deploy the Docker image of the application -* Deploy the image on the Oracle Kubernetes Engine (OKE) -* Describe the steps for Undeploying -* Configure the API Gateway -* Test the backend application - -### Prerequisites - -This lab requires the completion of lab 1 and the provision of the OCI components. - -### Understanding the Java/backend application - -As with most React applications (https://reactjs.org/), this application uses remote APIs to handle data persistence. The backend implements 5 REST APIs including: -- Retrieving the current list of todo items -- Adding a new todo item -- Finding a todo item by its id -- Updating an existing todo item -- Deleting a todo item. - -The APIs are documented using Swagger @ http://130.61.67.158:8780/swagger-ui/#/ - -The backend is implemented using the following Java classes (under ./backend/src/...): -- Main.java: starts and configure the main entry points. -- ToDoItem.java: maps a Todo Item instance to/from JSON document -- ToDoItemStorage.java: stores the Todo item in a persistent store i.e., the Oracle Autonomous database -- ToDoListAppService.java: implements the Helidon service and exposes the REST APIs - - ![](images/Backend-APIs.png " ") - - -## **STEP 1**: Set values for workshop environment variables - -1. Set the root directory of the workshop - ``` - export MTDRWORKSHOP_LOCATION=~/mtdrworkshop - ``` -2. Run source addAndSourcePropertiesInBashrc.sh - -The following command will set the values of environment variables in mtdrworkshop.properties and source ~/.bashrc - - ``` - cd $MTDRWORKSHOP_LOCATION; source addAndSourcePropertiesInBashrc.sh - - ``` - -## **STEP 2**: Build and push the Docker images to the OCI Registry - -1. Ensure that the "DOCKER_REGISTRY" variable is set - - Example: `.ocir.io///` - If the variable is not set or is an empty string, the push will fail (but the docker image will be built). - -2. Make sure to be in backend/target/classes/wallet directory then execute - ``` - unzip ~/mtdrworkshop/setup-dev-environment/wallet.zip - ``` - -3. Pick mtdrb_tp service alias (see the list of aliases in - ./backend/target/classes/wallet/tnsnames.ora) - - ![](images/tnsnames-ora.png " ") - -4. Edit ./backend/target/classes/application.yaml to set the database service and user password - ![](images/application-yaml.png " ") - -5. Copy the edited ./backend/target/classes/application.yaml to ./backend/src/main/resources/application.yaml - -6. Edit ./backend/src/main/java/com/oracle/todoapp/Main.java - - Locate the following code fragment - ![](images/CORS-Main.png " ") - - Replace `eu-frankfurt-1` in `"https://objectstorage.eu-frankfurt-1.oraclecloud.com"` by your region - - - Save the file - -7. Run `build.sh` script to build and push the - microservices images into the repository - - ``` - cd $MTDRWORKSHOP_LOCATION/backend; ./build.sh - ``` - In a couple of minutes, you should have successfully built and pushed the images into the OCIR repository. - -8. Check your container registry from the root compartment - - Go to the Console, click the hamburger menu in the top-left corner and open - **Developer Services > Container Registry**. - - ![](images/Registry-root-compart.png " ") - -9. Mark Access as Public (if Private) - (**Actions** > **Change to Public**): - - ![](images/Public-access.png " ") - -## **STEP 3**: Deploy on Kubernetes and Check the Status - -1. Run the `deploy.sh` script - - ``` - cd $MTDRWORKSHOP_LOCATION/backend; ./deploy.sh - ``` - ---> service/todolistapp-helidon-se-service created ---> deployment.apps/todolistapp-helidon-se-deployment created - -2. Check the status using the following commands -$ kubectl get services - -The following command returns the Kubernetes service of MyToDo application with a load balancer exposed through an external API - ``` - kubectl get services - ``` - -![](images/K8-service-Ext-IP.png " ") - -3. $ kubectl get pods - ``` - kubectl get pods - ``` - -![](images/k8-pods.png " ") - -5. Continuously tailing the log of one of the pods - - $ kubectl logs -f - Example kubectl lgs -f todolistapp-helidon-se-deployment-7fd6dcb778-c9dbv - - Returns: - http://130.61.66.27/todolist - -## **STEP 4**: UnDeploy (optional) - - If you make changes to the image, you need to delete the service and the pods by running undeploy.sh then redo Steps 2 & 3. - - 1. Run the `undeploy.sh` script - ``` - cd $MTDRWORKSHOP_LOCATION/backend; ./undeploy.sh - ``` - 2. Rebuild the image + Deploy + (Re)Configure the API Gateway - - -## **STEP 5**: Configure the API Gateway - -The API Gateway protects any RESTful service running on Container Engine for Kubernetes, Compute, or other endpoints through policy enforcement, metrics and logging. -Rather than exposing the Helidon service directly, we will use the API Gateway to define cross-origin resource sharing (CORS). - -1. From the hamburger menu navigate **Developer Services** > **API Management > Create Gateway** - ![](images/API-Gateway-menu.png " ") - -2. Configure the basic info: name, compartment, VCN and Subnet - - VCN: pick on of the vitual circuit network - - Subnet pick the public subnet - The click "Create" - ![](images/Basic-gateway.png " ") - -3. Click on Todolist gateway - ![](images/Gateway.png " ") - -4. Click on Deployments - ![](images/Deployment-menu.png " ") - -5. Create a todolist deployment - ![](images/Deployment.png " ") - - -6. Configure Cross-origin resource sharing (CORS) policies. - - CORS is a security mechanism that will prevent running application loaded from origin A from using resources from another origin B. - - Allowed Origins: is the list of all servers (origins) that are allowed to access the API deployment typically your Kubernetes cluster IP. - - Allowed methods: GET, PUT, DELETE, POST, OPTIONS are all needed. - ![](images/Origins-Methods.png " ") - -7. Configure the Headers - ![](images/Headers.png " ") - -8. Configure the routes: we will define two routes: - - /todolist for the first two APIs: GET, POST and OPTIONS - ![](images/Route-1.png " ") - - - /todolist/{id} for the remaining three APIs: (GET, PUT and DELETE) - ![](images/Route-2.png " ") - - -## **STEP 6**: Testing the backend application through the API Gateway - -1. Navigate to the newly create Gateway Deployment Detail an copy the endpoint - ![](images/Gateway-endpoint.png " ") - -2. Testing through the API Gateway endpoint - postfix the gateway endpoint with "/todolist" as shown in the image below - ![](images/Backend-Testing.png " ") - - It should display the Todo Item(s) in the TodoItem table. At least the row you have created in Part I. - -Congratulations, you have completed lab 2; you may now [proceed to the next lab](#next). - -## Acknowledgements - -* **Author** - - Kuassi Mensah, Dir. Product Management, Java Database Access -* **Contributors** - Jean de Lavarene, Sr. Director of Development, JDBC/UCP -* **Last Updated By/Date** - Kuassi Mensah, Database Product Management, April 2021 diff --git a/mtdrworkshop/backend/backend.md b/mtdrworkshop/backend/backend.md index 43a7af1..df79c88 100644 --- a/mtdrworkshop/backend/backend.md +++ b/mtdrworkshop/backend/backend.md @@ -1,210 +1,203 @@ -# Backend +# Deploy the Backend Docker Image to Kubernetes ## Introduction -In this lab, you will deploy the pre-built Helidon Java backend Docker image to OKE, then configure the API Gateway. +In this lab, you will build and deploy the pre-built Helidon Java backend Docker image to OKE, then configure the API Gateway. -Estimated time: ~25-minutes. +Estimated time: 25 minutes -### Objectives +Watch the video below for a quick walk through of the lab. -* Set values for environment variables -* Build and deploy the Docker image of the application -* Deploy the image on the Oracle Kubernetes Engine (OKE) -* Describe the steps for Undeploying -* Configure the API Gateway -* Test the backend application +[](youtube:Th7YCV6e8CE) -### Prerequisites - -This lab requires the completion of lab 1 and the provision of the OCI components. - -### Understanding the Java/backend application +### Understand the Java backend application -As with most React applications (https://reactjs.org/), this application uses remote APIs to handle data persistence. The backend implements 5 REST APIs including: -- Retrieving the current list of todo items -- Adding a new todo item -- Finding a todo item by its id -- Updating an existing todo item -- Deleting a todo item. +As with most React applications (https://reactjs.org/), this application uses remote APIs to handle data persistence. The backend implements five REST APIs including: -The APIs are documented using Swagger @ http://130.61.67.158:8780/swagger-ui/#/ +* Retrieving the current list of todo items +* Adding a new todo item +* Finding a todo item by its ID +* Updating an existing todo item +* Deleting a todo item -The backend is implemented using the following Java classes (under ./backend/src/...): -- Main.java: starts and configure the main entry points. -- ToDoItem.java: maps a Todo Item instance to/from JSON document -- ToDoItemStorage.java: stores the Todo item in a persistent store i.e., the Oracle Autonomous database -- ToDoListAppService.java: implements the Helidon service and exposes the REST APIs +The APIs are documented using Swagger at http://130.61.67.158:8780/swagger-ui/#/. - ![](images/Backend-APIs.png " ") +The backend is implemented using the following Java classes (under ./backend/src/...): +* Main.java: starts and configures the main entry points +* ToDoItem.java: maps a Todo Item instance to and from the JSON document +* ToDoItemStorage.java: stores the Todo item in a persistent store that is the Oracle Autonomous database +* ToDoListAppService.java: implements the Helidon service and exposes the REST APIs +![bcknd apis](images/Backend-APIs.png) -## **STEP 1**: Set values for workshop environment variables - -1. Set the root directory of the workshop - ``` - export MTDRWORKSHOP_LOCATION=~/mtdrworkshop - ``` -2. Run source addAndSourcePropertiesInBashrc.sh - -The following command will set the values of environment variables in mtdrworkshop.properties and source ~/.bashrc - - ``` - cd $MTDRWORKSHOP_LOCATION; source addAndSourcePropertiesInBashrc.sh - - ``` - -## **STEP 2**: Build and push the Docker images to the OCI Registry - -1. Ensure that the "DOCKER_REGISTRY" variable is set +### Objectives - Example: `.ocir.io///` - If the variable is not set or is an empty string, the push will fail (but the docker image will be built). +* Build and deploy the Docker image of the application +* Deploy the image on the Oracle Kubernetes Engine (OKE) +* Describe the steps for Undeploying +* Configure the API Gateway +* Test the backend application -2. Make sure to be in backend/target/classes/wallet directory then execute - ``` - unzip ~/mtdrworkshop/setup-dev-environment/wallet.zip - ``` +### Prerequisites -3. Pick mtdrb_tp service alias (see the list of aliases in - ./backend/target/classes/wallet/tnsnames.ora) +* This lab requires the completion of the **Setup Dev Environment** tutorial and the provisioning of the Orace Cloud Infrastructure (OCI) components. - ![](images/tnsnames-ora.png " ") +## Task 1: Build and Push the Docker Images to the OCI Registry -4. Edit ./backend/target/classes/application.yaml to set the database service and user password - ![](images/application-yaml.png " ") +The OCI Container Regisry is where your Docker images are managed. A container registry should have been created for you in Lab 1 in your compartment. -5. Copy the edited ./backend/target/classes/application.yaml to ./backend/src/main/resources/application.yaml +1. Edit ./backend/src/main/java/com/oracle/todoapp/Main.java -6. Edit ./backend/src/main/java/com/oracle/todoapp/Main.java - Locate the following code fragment - ![](images/CORS-Main.png " ") - - Replace `eu-frankfurt-1` in `"https://objectstorage.eu-frankfurt-1.oraclecloud.com"` by your region + + ![](images/cors-main.png " ") + - Replace `eu-frankfurt-1` in `"https://objectstorage.eu-frankfurt-1.oraclecloud.com"` with your region - Save the file -7. Run `build.sh` script to build and push the - microservices images into the repository +This will allow the appropriate object storage bucket to access your application. + +2. Run `build.sh` script to build and push the helidon-se image into the repository ``` - cd $MTDRWORKSHOP_LOCATION/backend; ./build.sh + + cd $MTDRWORKSHOP_LOCATION/backend + + ./build.sh ``` - In a couple of minutes, you should have successfully built and pushed the images into the OCIR repository. + In a couple of minutes, you should have successfully built and pushed the images into the OCI repository. -8. Check your container registry from the root compartment +3. Check your container registry in your compartment - Go to the Console, click the hamburger menu in the top-left corner and open **Developer Services > Container Registry**. + + ![](images/container-registry.png) - ![](images/Registry-root-compart.png " ") - -9. Mark Access as Public (if Private) - (**Actions** > **Change to Public**): - - ![](images/Public-access.png " ") - -## **STEP 3**: Deploy on Kubernetes and Check the Status +## Task 2: Deploy on Kubernetes and Check the Status 1. Run the `deploy.sh` script ``` - cd $MTDRWORKSHOP_LOCATION/backend; ./deploy.sh + + cd $MTDRWORKSHOP_LOCATION/backend + ./deploy.sh + ``` ---> service/todolistapp-helidon-se-service created ---> deployment.apps/todolistapp-helidon-se-deployment created + If everything runs correctly the script will output something like this. + + ![](images/deploy-output.png) + 2. Check the status using the following commands -$ kubectl get services The following command returns the Kubernetes service of MyToDo application with a load balancer exposed through an external API ``` - kubectl get services + + services + ``` + This will run `kubectl get services` in the background, but the setup script creates aliases for ease of use -![](images/K8-service-Ext-IP.png " ") +![](images/get-services.png) -3. $ kubectl get pods +3. The following command returns all the pods running in your kubernetes cluster: ``` - kubectl get pods + + pods + ``` +This will run `kubectl get pods` in the background, but the setup script creates aliases for ease of use -![](images/k8-pods.png " ") +![](images/get-pods.png) -5. Continuously tailing the log of one of the pods +5. You can tail the log of one of the pods by running: + + ``` + + kubectl -n mtdrworkshop logs -f + + ``` $ kubectl logs -f - Example kubectl lgs -f todolistapp-helidon-se-deployment-7fd6dcb778-c9dbv + Example: `kubectl -n mtdrworkshop logs -f todolistapp-helidon-se-deployment-7fd6dcb778-c9dbv` - Returns: - http://130.61.66.27/todolist +![](images/pod-logs.png) -## **STEP 4**: UnDeploy (optional) + If the logs return `webserver is up!` then you have done everything correctly. +## Task 3: UnDeploy (optional) If you make changes to the image, you need to delete the service and the pods by running undeploy.sh then redo Steps 2 & 3. 1. Run the `undeploy.sh` script ``` - cd $MTDRWORKSHOP_LOCATION/backend; ./undeploy.sh + + cd $MTDRWORKSHOP_LOCATION/backend + ./undeploy.sh + ``` 2. Rebuild the image + Deploy + (Re)Configure the API Gateway - -## **STEP 5**: Configure the API Gateway +## Task 4: Configure the API Gateway The API Gateway protects any RESTful service running on Container Engine for Kubernetes, Compute, or other endpoints through policy enforcement, metrics and logging. Rather than exposing the Helidon service directly, we will use the API Gateway to define cross-origin resource sharing (CORS). -1. From the hamburger menu navigate **Developer Services** > **API Management > Create Gateway** - ![](images/API-Gateway-menu.png " ") +The setup script already creates an API gateway, but you still need to create the deployments in the API gateway. -2. Configure the basic info: name, compartment, VCN and Subnet - - VCN: pick on of the vitual circuit network - - Subnet pick the public subnet - The click "Create" - ![](images/Basic-gateway.png " ") +1. From the hamburger menu navigate **Developer Services** > **API Management > Gateways** + ![](images/api-gateway-navigate.png) -3. Click on Todolist gateway - ![](images/Gateway.png " ") +2. Click on the todolist gateway that has been created for you + ![](images/select-gateway.png) -4. Click on Deployments - ![](images/Deployment-menu.png " ") +3. Create a todolist deployment by clicking create deployment + ![](images/create-deployment.png) -5. Create a todolist deployment - ![](images/Deployment.png " ") +4. Fill out the basic information like so: - -6. Configure Cross-origin resource sharing (CORS) policies. - - CORS is a security mechanism that will prevent running application loaded from origin A from using resources from another origin B. +![](images/basic-information-deployment.png) +5. Configure Cross-origin resource sharing (CORS) policies. + - CORS is a security mechanism that will prevent loading resources from unspecified origins (domain, scheme, or port). - Allowed Origins: is the list of all servers (origins) that are allowed to access the API deployment typically your Kubernetes cluster IP. + - Replace the `.us-phoenix-1` portion with whichever region you replaced with in task 1. + - Replace the 3rd IP address with the external IP address of your Load Balancer - Allowed methods: GET, PUT, DELETE, POST, OPTIONS are all needed. - ![](images/Origins-Methods.png " ") -7. Configure the Headers - ![](images/Headers.png " ") + To configure CORS, scroll down and click add next to CORS and fill in this information under allowed origins. These are the origins that can load resources to your application. + + ![](images/cors-information.png) -8. Configure the routes: we will define two routes: - - /todolist for the first two APIs: GET, POST and OPTIONS - ![](images/Route-1.png " ") +6. Configure the Headers - - /todolist/{id} for the remaining three APIs: (GET, PUT and DELETE) - ![](images/Route-2.png " ") + ![](images/headers.png) +7. Configure the routes: we will define two routes: + - /todolist for the first two APIs: GET, POST and OPTIONS -## **STEP 6**: Testing the backend application through the API Gateway + ![](images/route-1.png) + +- /todolist/{id} for the remaining three APIs: (GET, PUT and DELETE) + +![](images/route-2.png) + + +## Task 5: Testing the Backend Application Through the API Gateway 1. Navigate to the newly create Gateway Deployment Detail an copy the endpoint - ![](images/Gateway-endpoint.png " ") + ![](images/copy-endpoint.png " ") 2. Testing through the API Gateway endpoint postfix the gateway endpoint with "/todolist" as shown in the image below - ![](images/Backend-Testing.png " ") - It should display the Todo Item(s) in the TodoItem table. At least the row you have created in Part I. + ![](images/endpoint-successful.png " ") + + It should display the Todo Item(s) in the TodoItem table that was created during the setup. -Congratulations, you have completed lab 2; you may now [proceed to the next lab](#next). +You may now **proceed to the next lab**. ## Acknowledgements -* **Author** - - Kuassi Mensah, Dir. Product Management, Java Database Access +* **Author** - Kuassi Mensah, Dir. Product Management, Java Database Access, Peter Song Developer Advocate JDBC * **Contributors** - Jean de Lavarene, Sr. Director of Development, JDBC/UCP -* **Last Updated By/Date** - Kuassi Mensah, Database Product Management, April 2021 +* **Last Updated By/Date** - Peter Song Developer Advocate February 2022 diff --git a/mtdrworkshop/backend/build.sh b/mtdrworkshop/backend/build.sh index c56c81e..92b913c 100755 --- a/mtdrworkshop/backend/build.sh +++ b/mtdrworkshop/backend/build.sh @@ -9,7 +9,12 @@ SCRIPT_DIR=$(dirname $0) IMAGE_NAME=todolistapp-helidon-se IMAGE_VERSION=0.1 -if [ -z "DOCKER_REGISTRY" ]; then +if [ -z "$DOCKER_REGISTRY" ]; then + echo "DOCKER_REGISTRY not set. Will get it with state_get" + export DOCKER_REGISTRY=$(state_get DOCKER_REGISTRY) +fi + +if [ -z "$DOCKER_REGISTRY" ]; then echo "Error: DOCKER_REGISTRY env variable needs to be set!" exit 1 fi diff --git a/mtdrworkshop/backend/deploy.sh b/mtdrworkshop/backend/deploy.sh old mode 100644 new mode 100755 index b540fad..9a1b008 --- a/mtdrworkshop/backend/deploy.sh +++ b/mtdrworkshop/backend/deploy.sh @@ -4,11 +4,45 @@ ## Copyright (c) 2021 Oracle, Inc. ## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ SCRIPT_DIR=$(dirname $0) +export DOCKER_REGISTRY=$(state_get DOCKER_REGISTRY) +if [ -z "$TODO_PDB_NAME" ]; then + echo "TODO_PDB_NAME not set. Will get it with state_get" + export TODO_PDB_NAME=$(state_get MTDR_DB_NAME) +fi +if [ -z "$TODO_PDB_NAME" ]; then + echo "Error: TODO_PDB_NAME env variable needs to be set!" + exit 1 +fi +if [ -z "$OCI_REGION" ]; then + echo "OCI_REGION not set. Will get it with state_get" + export OCI_REGION=$(state_get REGION) +fi +if [ -z "$OCI_REGION" ]; then + echo "Error: OCI_REGION env variable needs to be set!" + exit 1 +fi +echo "Creating helidon deployment and service" export CURRENTTIME=$( date '+%F_%H:%M:%S' ) echo CURRENTTIME is $CURRENTTIME ...this will be appended to generated deployment yaml -cp src/main/k8s/app.yaml todolistapp-helidon-se-deployment-$CURRENTTIME.yaml +cp src/main/k8s/todolistapp-helidon-se-deployment.yaml todolistapp-helidon-se-deployment-$CURRENTTIME.yaml #may hit sed incompat issue with mac sed -i "s|%DOCKER_REGISTRY%|${DOCKER_REGISTRY}|g" todolistapp-helidon-se-deployment-$CURRENTTIME.yaml -kubectl apply -f $SCRIPT_DIR/todolistapp-helidon-se-deployment-$CURRENTTIME.yaml +#kubectl apply -f $SCRIPT_DIR/todolistapp-helidon-se-deployment-$CURRENTTIME.yaml + +sed -e "s|%DOCKER_REGISTRY%|${DOCKER_REGISTRY}|g" todolistapp-helidon-se-deployment-${CURRENTTIME}.yaml > /tmp/todolistapp-helidon-se-deployment-${CURRENTTIME}.yaml +mv -- /tmp/todolistapp-helidon-se-deployment-$CURRENTTIME.yaml todolistapp-helidon-se-deployment-$CURRENTTIME.yaml +sed -e "s|%TODO_PDB_NAME%|${TODO_PDB_NAME}|g" todolistapp-helidon-se-deployment-${CURRENTTIME}.yaml > /tmp/todolistapp-helidon-se-deployment-${CURRENTTIME}.yaml +mv -- /tmp/todolistapp-helidon-se-deployment-$CURRENTTIME.yaml todolistapp-helidon-se-deployment-$CURRENTTIME.yaml +sed -e "s|%OCI_REGION%|${OCI_REGION}|g" todolistapp-helidon-se-deployment-${CURRENTTIME}.yaml > /tmp/todolistapp-helidon-se-deployment-$CURRENTTIME.yaml +mv -- /tmp/todolistapp-helidon-se-deployment-$CURRENTTIME.yaml todolistapp-helidon-se-deployment-$CURRENTTIME.yaml + + +if [ -z "$1" ]; then + kubectl apply -f $SCRIPT_DIR/todolistapp-helidon-se-deployment-$CURRENTTIME.yaml -n mtdrworkshop +else + kubectl apply -f <(istioctl kube-inject -f $SCRIPT_DIR/todolistapp-helidon-se-deployment-$CURRENTTIME.yaml) -n mtdrworkshop +fi + +#kubectl apply -f $SCRIPT_DIR/order-service.yaml -n mtdrworkshop #kubectl create -f $SCRIPT_DIR/todolistapp-helidon-se-service.yaml -n todoapplication diff --git a/mtdrworkshop/backend/images/API-Gateway-menu.png b/mtdrworkshop/backend/images/API-Gateway-menu.png deleted file mode 100644 index 66b3aaa..0000000 Binary files a/mtdrworkshop/backend/images/API-Gateway-menu.png and /dev/null differ diff --git a/mtdrworkshop/backend/images/Backend-Testing.png b/mtdrworkshop/backend/images/Backend-Testing.png deleted file mode 100644 index 0a29ee3..0000000 Binary files a/mtdrworkshop/backend/images/Backend-Testing.png and /dev/null differ diff --git a/mtdrworkshop/backend/images/Basic-gateway.png b/mtdrworkshop/backend/images/Basic-gateway.png deleted file mode 100644 index 9eed811..0000000 Binary files a/mtdrworkshop/backend/images/Basic-gateway.png and /dev/null differ diff --git a/mtdrworkshop/backend/images/Basic-info-API_Policies.png b/mtdrworkshop/backend/images/Basic-info-API_Policies.png deleted file mode 100644 index 2711f67..0000000 Binary files a/mtdrworkshop/backend/images/Basic-info-API_Policies.png and /dev/null differ diff --git a/mtdrworkshop/backend/images/Deployment-menu.png b/mtdrworkshop/backend/images/Deployment-menu.png deleted file mode 100644 index c189c3e..0000000 Binary files a/mtdrworkshop/backend/images/Deployment-menu.png and /dev/null differ diff --git a/mtdrworkshop/backend/images/Deplyment.png b/mtdrworkshop/backend/images/Deplyment.png deleted file mode 100644 index 3259404..0000000 Binary files a/mtdrworkshop/backend/images/Deplyment.png and /dev/null differ diff --git a/mtdrworkshop/backend/images/Edit-deplooyment.png b/mtdrworkshop/backend/images/Edit-deplooyment.png deleted file mode 100644 index 3a9ab58..0000000 Binary files a/mtdrworkshop/backend/images/Edit-deplooyment.png and /dev/null differ diff --git a/mtdrworkshop/backend/images/Gateway-endpoint.png b/mtdrworkshop/backend/images/Gateway-endpoint.png deleted file mode 100644 index 6964d52..0000000 Binary files a/mtdrworkshop/backend/images/Gateway-endpoint.png and /dev/null differ diff --git a/mtdrworkshop/backend/images/Gateway.png b/mtdrworkshop/backend/images/Gateway.png deleted file mode 100644 index da189de..0000000 Binary files a/mtdrworkshop/backend/images/Gateway.png and /dev/null differ diff --git a/mtdrworkshop/backend/images/K8-service-Ext-IP.png b/mtdrworkshop/backend/images/K8-service-Ext-IP.png deleted file mode 100644 index 08352be..0000000 Binary files a/mtdrworkshop/backend/images/K8-service-Ext-IP.png and /dev/null differ diff --git a/mtdrworkshop/backend/images/Origins-Methods.png b/mtdrworkshop/backend/images/Origins-Methods.png deleted file mode 100644 index 6d4973c..0000000 Binary files a/mtdrworkshop/backend/images/Origins-Methods.png and /dev/null differ diff --git a/mtdrworkshop/backend/images/Public-access.png b/mtdrworkshop/backend/images/Public-access.png deleted file mode 100644 index 5437fd1..0000000 Binary files a/mtdrworkshop/backend/images/Public-access.png and /dev/null differ diff --git a/mtdrworkshop/backend/images/Registry-root-compart.png b/mtdrworkshop/backend/images/Registry-root-compart.png deleted file mode 100644 index 7896120..0000000 Binary files a/mtdrworkshop/backend/images/Registry-root-compart.png and /dev/null differ diff --git a/mtdrworkshop/backend/images/Route-1.png b/mtdrworkshop/backend/images/Route-1.png index e62591f..49a69c1 100644 Binary files a/mtdrworkshop/backend/images/Route-1.png and b/mtdrworkshop/backend/images/Route-1.png differ diff --git a/mtdrworkshop/backend/images/Route-2.png b/mtdrworkshop/backend/images/Route-2.png index fdb38b4..4b8cee7 100644 Binary files a/mtdrworkshop/backend/images/Route-2.png and b/mtdrworkshop/backend/images/Route-2.png differ diff --git a/mtdrworkshop/backend/images/api-gateway-navigate.png b/mtdrworkshop/backend/images/api-gateway-navigate.png new file mode 100644 index 0000000..8b8e169 Binary files /dev/null and b/mtdrworkshop/backend/images/api-gateway-navigate.png differ diff --git a/mtdrworkshop/backend/images/basic-information-deployment.png b/mtdrworkshop/backend/images/basic-information-deployment.png new file mode 100644 index 0000000..6b530cb Binary files /dev/null and b/mtdrworkshop/backend/images/basic-information-deployment.png differ diff --git a/mtdrworkshop/backend/images/container-registry.png b/mtdrworkshop/backend/images/container-registry.png new file mode 100644 index 0000000..c740bc3 Binary files /dev/null and b/mtdrworkshop/backend/images/container-registry.png differ diff --git a/mtdrworkshop/backend/images/copy-endpoint.png b/mtdrworkshop/backend/images/copy-endpoint.png new file mode 100644 index 0000000..4bdaaf5 Binary files /dev/null and b/mtdrworkshop/backend/images/copy-endpoint.png differ diff --git a/mtdrworkshop/backend/images/cors-information.png b/mtdrworkshop/backend/images/cors-information.png new file mode 100644 index 0000000..229128a Binary files /dev/null and b/mtdrworkshop/backend/images/cors-information.png differ diff --git a/mtdrworkshop/backend/images/create-deployment.png b/mtdrworkshop/backend/images/create-deployment.png new file mode 100644 index 0000000..0a91308 Binary files /dev/null and b/mtdrworkshop/backend/images/create-deployment.png differ diff --git a/mtdrworkshop/backend/images/deploy-output.png b/mtdrworkshop/backend/images/deploy-output.png new file mode 100644 index 0000000..d3e76cb Binary files /dev/null and b/mtdrworkshop/backend/images/deploy-output.png differ diff --git a/mtdrworkshop/backend/images/endpoint-successful.png b/mtdrworkshop/backend/images/endpoint-successful.png new file mode 100644 index 0000000..8c67a7b Binary files /dev/null and b/mtdrworkshop/backend/images/endpoint-successful.png differ diff --git a/mtdrworkshop/backend/images/get-pods.png b/mtdrworkshop/backend/images/get-pods.png new file mode 100644 index 0000000..c94014f Binary files /dev/null and b/mtdrworkshop/backend/images/get-pods.png differ diff --git a/mtdrworkshop/backend/images/get-services.png b/mtdrworkshop/backend/images/get-services.png new file mode 100644 index 0000000..f9f0a4c Binary files /dev/null and b/mtdrworkshop/backend/images/get-services.png differ diff --git a/mtdrworkshop/backend/images/pod-logs.png b/mtdrworkshop/backend/images/pod-logs.png new file mode 100644 index 0000000..5205772 Binary files /dev/null and b/mtdrworkshop/backend/images/pod-logs.png differ diff --git a/mtdrworkshop/backend/images/select-gateway.png b/mtdrworkshop/backend/images/select-gateway.png new file mode 100644 index 0000000..af9bf4a Binary files /dev/null and b/mtdrworkshop/backend/images/select-gateway.png differ diff --git a/mtdrworkshop/backend/pom.xml b/mtdrworkshop/backend/pom.xml index bea7004..a2b65ed 100644 --- a/mtdrworkshop/backend/pom.xml +++ b/mtdrworkshop/backend/pom.xml @@ -99,6 +99,13 @@ + + + com.oracle.oci.sdk + oci-java-sdk-common + 1.32.2 + + io.helidon.webserver helidon-webserver-cors diff --git a/mtdrworkshop/backend/src/main/docker/Dockerfile b/mtdrworkshop/backend/src/main/docker/Dockerfile index d5a5585..d0adcb0 100644 --- a/mtdrworkshop/backend/src/main/docker/Dockerfile +++ b/mtdrworkshop/backend/src/main/docker/Dockerfile @@ -7,7 +7,14 @@ FROM openjdk:11 # and in the IDE, we need to copy the wallet directory under /target/classes/wallet. # This way the JDBC URL can point to jdbc:oracle:thin:@xxx?TNS_ADMIN=target/classes/wallet--> -ADD target/classes/wallet /target/classes/wallet + + +#Thinking we don't need to add the wallet here since we're using a kubernetes secret +##ADD target/classes/wallet /target/classes/wallet + +## add maven dependencies ADD target/libs /target/libs + +##adding the service itself ADD target/todolistapp-helidon-se.jar /target/todolistapp-helidon-se.jar ENTRYPOINT ["java", "-jar", "/target/todolistapp-helidon-se.jar"] diff --git a/mtdrworkshop/backend/src/main/java/com/oracle/todoapp/Main.java b/mtdrworkshop/backend/src/main/java/com/oracle/todoapp/Main.java index 707b200..67da2d8 100644 --- a/mtdrworkshop/backend/src/main/java/com/oracle/todoapp/Main.java +++ b/mtdrworkshop/backend/src/main/java/com/oracle/todoapp/Main.java @@ -35,7 +35,7 @@ public static void main(final String[] args) Config config = Config.create(); WebServer.builder() - .config(config.get("server")) + .config(config.get("server")) //update this server configuration from the config provided .addMediaSupport(JsonpSupport.create()) .routing(createRouting(config)) .build() @@ -63,7 +63,7 @@ private static Routing createRouting(Config config) throws SQLException { CorsSupport corsSupport = CorsSupport.builder() .addCrossOrigin(CrossOriginConfig.builder() .allowOrigins("http://localhost:3000", - "https://objectstorage.eu-frankfurt-1.oraclecloud.com", + "https://objectstorage.us-phoenix-1.oraclecloud.com", "https://petstore.swagger.io") .allowMethods("POST", "PUT", "DELETE") .exposeHeaders("location") diff --git a/mtdrworkshop/backend/src/main/java/com/oracle/todoapp/TodoItem.java b/mtdrworkshop/backend/src/main/java/com/oracle/todoapp/TodoItem.java index f05d8d8..d404cb4 100644 --- a/mtdrworkshop/backend/src/main/java/com/oracle/todoapp/TodoItem.java +++ b/mtdrworkshop/backend/src/main/java/com/oracle/todoapp/TodoItem.java @@ -26,7 +26,6 @@ class TodoItem implements Serializable { private static final long serialVersionUID = 4168008245514009223L; private final static Logger LOGGER = Logger.getLogger(TodoItem.class.getName()); - // This is the mapping with the database rows: int id; String description; diff --git a/mtdrworkshop/backend/src/main/java/com/oracle/todoapp/TodoItemStorage.java b/mtdrworkshop/backend/src/main/java/com/oracle/todoapp/TodoItemStorage.java index 01f39f2..019d6c9 100644 --- a/mtdrworkshop/backend/src/main/java/com/oracle/todoapp/TodoItemStorage.java +++ b/mtdrworkshop/backend/src/main/java/com/oracle/todoapp/TodoItemStorage.java @@ -12,7 +12,6 @@ import java.sql.SQLException; import java.time.OffsetDateTime; - import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletionStage; @@ -22,7 +21,7 @@ import io.helidon.config.Config; import oracle.ucp.jdbc.PoolDataSource; import oracle.ucp.jdbc.PoolDataSourceFactory; - +//import io.helidon.dbclient.jdbc; /* * This class takes care of the storage of the todo items. It uses an Autonomous Database * from the Oracle Cloud (ATP). The following table is used to store the todo items: @@ -39,6 +38,8 @@ */ class TodoItemStorage { + // grabbing the dbpassword from the kubernetes secret, added by peter song + static String pwSecretFromK8s = System.getenv("dbpassword").trim(); private final static Logger LOGGER = Logger.getLogger(TodoItemStorage.class.getName()); private final PoolDataSource pool; @@ -60,14 +61,16 @@ synchronized static TodoItemStorage get(Config config) { private TodoItemStorage(Config config) throws SQLException { LOGGER.log(Level.CONFIG, ()->config.toString()); + // trying this in place of "url and user and dbpasswor" + //String password = config.get("password").asString().get(); String url = config.get("url").asString().get(); String user = config.get("user").asString().get(); - String password = config.get("password").asString().get(); System.out.printf("Using url: %s%n", url); pool = PoolDataSourceFactory.getPoolDataSource(); pool.setURL(url); - pool.setUser(user); - pool.setPassword(password); + //pool.setUser(user); + pool.setUser("TODOUSER"); + pool.setPassword(pwSecretFromK8s); pool.setInactiveConnectionTimeout(60); pool.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource"); pool.setMaxStatements(10); diff --git a/mtdrworkshop/backend/src/main/k8s/app.yaml b/mtdrworkshop/backend/src/main/k8s/app.yaml deleted file mode 100644 index d8470f0..0000000 --- a/mtdrworkshop/backend/src/main/k8s/app.yaml +++ /dev/null @@ -1,43 +0,0 @@ -## MyToDoReact version 1.0. -## -## Copyright (c) 2021 Oracle, Inc. -## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ -apiVersion: v1 -kind: Service -metadata: - name: todolistapp-helidon-se-service -spec: - type: LoadBalancer - ports: - - port: 80 - protocol: TCP - #targetPort: 80 - targetPort: 8080 - selector: - app: todolistapp-helidon-se ---- -kind: Deployment -#apiVersion: extensions/v1beta1 -apiVersion: apps/v1 -metadata: - name: todolistapp-helidon-se-deployment -spec: -#Added on 08/07/2020 - selector: - matchLabels: - app: todolistapp-helidon-se -#End added - replicas: 2 - template: - metadata: - labels: - app: todolistapp-helidon-se - version: v1 - spec: - containers: - - name: todolistapp-helidon-se - image: %DOCKER_REGISTRY%/todolistapp-helidon-se:0.1 - imagePullPolicy: Always - ports: - - containerPort: 8080 ---- diff --git a/mtdrworkshop/backend/src/main/k8s/todolistapp-helidon-se-deployment.yaml b/mtdrworkshop/backend/src/main/k8s/todolistapp-helidon-se-deployment.yaml new file mode 100644 index 0000000..eb32018 --- /dev/null +++ b/mtdrworkshop/backend/src/main/k8s/todolistapp-helidon-se-deployment.yaml @@ -0,0 +1,86 @@ +## MyToDoReact version 1.0. +## +## Copyright (c) 2021 Oracle, Inc. +## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ +apiVersion: v1 +kind: Service +metadata: + name: todolistapp-helidon-se-service +spec: + type: LoadBalancer + ports: + - port: 80 + protocol: TCP + #targetPort: 80 + targetPort: 8080 + selector: + app: todolistapp-helidon-se +--- +kind: Deployment +#apiVersion: extensions/v1beta1 +apiVersion: apps/v1 +metadata: + name: todolistapp-helidon-se-deployment +spec: +#Added on 08/07/2020 + selector: + matchLabels: + app: todolistapp-helidon-se +#End added + replicas: 2 + template: + metadata: + labels: + app: todolistapp-helidon-se + version: v1 + spec: + containers: + - name: todolistapp-helidon-se + image: %DOCKER_REGISTRY%/todolistapp-helidon-se:0.1 + imagePullPolicy: Always + env: + - name: database.user + value: "TODOUSER" + - name: database.url + value: "jdbc:oracle:thin:@%TODO_PDB_NAME%_tp?TNS_ADMIN=/mtdrworkshop/creds" + - name: todo.table.name + value: "todoitem" + - name: OCI_REGION + value: "%OCI_REGION%" + - name: dbpassword + valueFrom: + secretKeyRef: + name: dbuser + key: dbpassword + optional: true + volumeMounts: + - name: creds + mountPath: /mtdrworkshop/creds + ports: + - containerPort: 8080 + ## if you want to use a livenessProbe or readinessProbe, need to add a handler to the code -petersong + # livenessProbe: + # httpGet: + # path: /heath/live + # port: 8080 + # initialDelaySeconds: 220 + # periodSeconds: 3 + # readinessProbe: + # httpGet: + # path: /health/ready + # port: 8080 + # initialDelaySeconds: 40 + # periodSeconds: 3 + restartPolicy: Always + volumes: + - name: creds + secret: + secretName: db-wallet-secret + topologySpreadConstraints: + - maxSkew: 1 + topologyKey: kubernetes.io/hostname + whenUnsatisfiable: DoNotSchedule + labelSelector: + matchLabels: + app: todolistapp-helidon-se +--- \ No newline at end of file diff --git a/mtdrworkshop/backend/src/main/resources/application.yaml b/mtdrworkshop/backend/src/main/resources/application.yaml index b44b9f5..e286843 100644 --- a/mtdrworkshop/backend/src/main/resources/application.yaml +++ b/mtdrworkshop/backend/src/main/resources/application.yaml @@ -1,8 +1,12 @@ + +## +## Copyright (c) 2021 Oracle and/or its affiliates. +## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ server: port: 8080 host: 0.0.0.0 database: - url: "jdbc:oracle:thin:@?TNS_ADMIN=target/classes/wallet" - user: Todouser - password: + url: ${} + user: XXXXXXXX + password: XXXXXXXX \ No newline at end of file diff --git a/mtdrworkshop/backend/target/classes/application.yaml b/mtdrworkshop/backend/target/classes/application.yaml deleted file mode 100644 index b44b9f5..0000000 --- a/mtdrworkshop/backend/target/classes/application.yaml +++ /dev/null @@ -1,8 +0,0 @@ -server: - port: 8080 - host: 0.0.0.0 - -database: - url: "jdbc:oracle:thin:@?TNS_ADMIN=target/classes/wallet" - user: Todouser - password: diff --git a/mtdrworkshop/backend/undeploy.sh b/mtdrworkshop/backend/undeploy.sh old mode 100644 new mode 100755 index 0d37fcd..87f8cce --- a/mtdrworkshop/backend/undeploy.sh +++ b/mtdrworkshop/backend/undeploy.sh @@ -6,5 +6,5 @@ echo delete frontend deployment and service... -kubectl delete deployment todolistapp-helidon-se-deployment -kubectl delete service todolistapp-helidon-se-service +kubectl -n mtdrworkshop delete deployment todolistapp-helidon-se-deployment +kubectl -n mtdrworkshop delete service todolistapp-helidon-se-service diff --git a/mtdrworkshop/createATP.sh b/mtdrworkshop/createATP.sh deleted file mode 100644 index f463df4..0000000 --- a/mtdrworkshop/createATP.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -## MyToDoReact version 1.0. -## -## Copyright (c) 2021 Oracle, Inc. -## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ - -echo ________________________________________ -echo creating MTDRDB ATP ... -echo ________________________________________ - -export WORKINGDIR=workingdir -echo WORKINGDIR = $WORKINGDIR - -export MTDRWORKSHOP_COMPARTMENT_ID=$(cat $WORKINGDIR/mtdrworkshopcompartmentid.txt) -echo console created compartment ... -echo MTDRWORKSHOP_COMPARTMENT_ID... $MTDRWORKSHOP_COMPARTMENT_ID - -echo reading password_from_console -read -s -p "Database Admin Password: " mtdrdb_admin_password -umask 177 -cat >pw < $WORKINGDIR/mtdrworkshopdbid.txt -export MTDRWORKSHOP_MTDRDBDB_ID=$(cat $WORKINGDIR/mtdrworkshopdbid.txt) -rm pw - -echo MTDRWORKSHOP_MTDRDB_ID... $MTDRWORKSHOP_MTDRDBDB_ID diff --git a/mtdrworkshop/createOKECluster.sh b/mtdrworkshop/createOKECluster.sh deleted file mode 100644 index 1e23eae..0000000 --- a/mtdrworkshop/createOKECluster.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash -## MyToDoReact version 1.0. -## -## Copyright (c) 2021 Oracle, Inc. -## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ - -if [[ $1 == "" ]] -then - echo Required argument MTDRWORKSHOP_COMPARTMENT_ID not provided. The compartmentid can be copied from the OCI Console. - echo Usage example : ./createOKECluster.sh ocid1.compartment.oc1..aaaaaaaaxbvaatfz6dyfqbxhmasxfyui4rjek5dnzgcbivfwvsho77myfnqq - echo [optional second argument is for specifying region. The default value is us-ashburn-1] - exit -fi - -echo ________________________________________ -echo creating VCN and OKE cluster ... -echo ________________________________________ - -export WORKINGDIR=workingdir -echo creating working directory $WORKINGDIR to store values... -mkdir $WORKINGDIR - - -export MTDRWORKSHOP_REGION=$2 -if [[ $MTDRWORKSHOP_REGION == "" ]] -then - echo defaulting to region us-ashburn-1 - export MTDRWORKSHOP_REGION=us-ashburn-1 -fi -echo $MTDRWORKSHOP_REGION | tr -d '"' > $WORKINGDIR/mtdrworkshopregion.txt -echo MTDRWORKSHOP_REGION... $MTDRWORKSHOP_REGION - - -export MTDRWORKSHOP_COMPARTMENT_ID=$1 -echo $MTDRWORKSHOP_COMPARTMENT_ID | tr -d '"' > $WORKINGDIR/mtdrworkshopcompartmentid.txt -echo MTDRWORKSHOP_COMPARTMENT_ID... $MTDRWORKSHOP_COMPARTMENT_ID - -echo creating vcn... -oci network vcn create --cidr-block 10.0.0.0/16 --compartment-id $MTDRWORKSHOP_COMPARTMENT_ID --display-name "mtdrworkshopvcn" | jq --raw-output '.data | .["id"] ' > $WORKINGDIR/mtdrworkshopvcnid.txt -export MTDRWORKSHOP_VCN_ID=$(cat $WORKINGDIR/mtdrworkshopvcnid.txt) -echo MTDRWORKSHOP_VCN_ID... $MTDRWORKSHOP_VCN_ID - -echo creating oke cluster... -oci ce cluster create --compartment-id $MTDRWORKSHOP_COMPARTMENT_ID --kubernetes-version v1.16.8 --name mtdrworkshopcluster --vcn-id $MTDRWORKSHOP_VCN_ID - -echo ________________________________________ -echo OKE cluster is being provisioned. You will check for status using verifyOKEAndCreateKubeConfig.sh script later... -echo ________________________________________ diff --git a/mtdrworkshop/destroy.sh b/mtdrworkshop/destroy.sh new file mode 100644 index 0000000..9452de8 --- /dev/null +++ b/mtdrworkshop/destroy.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Copyright (c) 2021 Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +# Make sure this is run via source or . + +if ! (return 0 2>/dev/null); then + echo "ERROR: Usage 'source destroy.sh'" + exit +fi + +$MTDRWORKSHOP_LOCATION/utils/main-destroy.sh + +cd \ No newline at end of file diff --git a/mtdrworkshop/dockerLogin.sh b/mtdrworkshop/dockerLogin.sh deleted file mode 100644 index b5ed5df..0000000 --- a/mtdrworkshop/dockerLogin.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash -## MyToDoReact version 1.0. -## -## Copyright (c) 2021 Oracle, Inc. -## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ - -echo Ensure MTDRWORKSHOP_OCIR_AUTHKEY argument is in quotes. -echo Usage example 1: ./dockerLogin.sh foo@bar.com "8nO[BKNU5iwasdf2xeefU;yl" -echo Usage example 2: ./dockerLogin.sh oracleidentitycloudservice/foo@bar.com "8nO[BKNU5iwasdf2xeefU;yl" - -export WORKINGDIR=workingdir -echo WORKINGDIR = $WORKINGDIR - -if [[ $1 == "" ]] -then - echo MTDRWORKSHOP_OCIR_USER not provided - echo Required arguments are MTDRWORKSHOP_OCIR_USER and MTDRWORKSHOP_OCIR_AUTHKEY. - echo Usage example : ./dockerLogin.sh foo@bar.com "8nO[BKNU5iwasdf2xeefU;yl" - exit -fi -if [[ $2 == "" ]] -then - echo MTDRWORKSHOP_OCIR_AUTHKEY not provided - echo Required arguments are MTDRWORKSHOP_OCIR_USER and MTDRWORKSHOP_OCIR_AUTHKEY. - echo Usage example : ./dockerLogin.sh foo@bar.com "8nO[BKNU5iwasdf2xeefU;yl" - exit -fi - -export MTDRWORKSHOP_OCIR_USER=$1 -echo $MTDRWORKSHOP_OCIR_USER | tr -d '"' > $WORKINGDIR/mtdrworkshopociruser.txt -echo MTDRWORKSHOP_OCIR_USER... $MTDRWORKSHOP_OCIR_USER - -export MTDRWORKSHOP_OCIR_AUTHKEY=$2 -echo $MTDRWORKSHOP_OCIR_AUTHKEY | tr -d '"' > $WORKINGDIR/mtdrworkshopocirauthkey.txt -echo MTDRWORKSHOP_OCIR_AUTHKEY... $MTDRWORKSHOP_OCIR_AUTHKEY - -export MTDRWORKSHOP_REGION=$(cat $WORKINGDIR/mtdrworkshopregion.txt) -echo MTDRWORKSHOP_REGION... $MTDRWORKSHOP_REGION - -export MTDRWORKSHOP_OCIR_NAMESPACE=$(cat $WORKINGDIR/mtdrworkshopocirnamespace.txt) -echo MTDRWORKSHOP_OCIR_NAMESPACE... $MTDRWORKSHOP_OCIR_NAMESPACE - -export MTDRWORKSHOP_REPOS_NAME=$(cat $WORKINGDIR/mtdrworkshopreposname.txt) -echo MTDRWORKSHOP_REPOS_NAME... $MTDRWORKSHOP_REPOS_NAME - - -#export DOCKER_REGISTRY=".ocir.io///" -# example... export DOCKER_REGISTRY=us-ashburn-1.ocir.io/aqsghou34ag/paul.parkinson/myreponame -export DOCKER_REGISTRY=$MTDRWORKSHOP_REGION.ocir.io/$MTDRWORKSHOP_OCIR_NAMESPACE/$MTDRWORKSHOP_REPOS_NAME -echo $DOCKER_REGISTRY | tr -d '"' > $WORKINGDIR/mtdrworkshopdockerregistry.txt -echo DOCKER_REGISTRY... $DOCKER_REGISTRY - -# example... docker login REGION-ID.ocir.io -u / -# example... docker login REGION-ID.ocir.io -u OBJECT-STORAGE-NAMESPACE/USERNAME -echo docker login $MTDRWORKSHOP_REGION.ocir.io -u $MTDRWORKSHOP_OCIR_NAMESPACE/$MTDRWORKSHOP_OCIR_USER -p $MTDRWORKSHOP_OCIR_AUTHKEY -docker login $MTDRWORKSHOP_REGION.ocir.io -u $MTDRWORKSHOP_OCIR_NAMESPACE/$MTDRWORKSHOP_OCIR_USER -p $MTDRWORKSHOP_OCIR_AUTHKEY diff --git a/mtdrworkshop/env.sh b/mtdrworkshop/env.sh new file mode 100644 index 0000000..59e2a1f --- /dev/null +++ b/mtdrworkshop/env.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# Copyright (c) 2021 Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +# Make sure this is run via source or . +if ! (return 0 2>/dev/null); then + echo "ERROR: Usage 'source env.sh'" + exit +fi + +#set mtdrworkshop_location +export MTDRWORKSHOP_LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +cd $MTDRWORKSHOP_LOCATION +echo "MTDRWORKSHOP_LOCATION: $MTDRWORKSHOP_LOCATION" + + +# Java Home +# -d true if file is a directory, so it's testing if this directory exists, if it does +# we are on Mac doing local dev +if test -d ~/graalvm-ce-java11-20.1.0/Contents/Home/bin; then + # We are on Mac doing local dev + export JAVA_HOME=~/graalvm-ce-java11-20.1.0/Contents/Home; +else + # Assume linux + export JAVA_HOME=~/graalvm-ce-java11-20.1.0 +fi +export PATH=$JAVA_HOME/bin:$PATH + +#state directory +if test -d ~/mtdrworkshop-state; then + export MTDRWORKSHOP_STATE_HOME=~/mtdrworkshop-state +else + export MTDRWORKSHOP_STATE_HOME=$MTDRWORKSHOP_LOCATION +fi +echo "MTDRWORKSOP_STATE_HOME: $MTDRWORKSHOP_STATE_HOME" +#Log Directory +export MTDRWORKSHOP_LOG=$MTDRWORKSHOP_STATE_HOME/log +mkdir -p $MTDRWORKSHOP_LOG + +source $MTDRWORKSHOP_LOCATION/utils/state-functions.sh + +# SHORTCUT ALIASES AND UTILS... +alias k='kubectl' +alias kt='kubectl --insecure-skip-tls-verify' +alias pods='kubectl get po --all-namespaces' +alias services='kubectl get services --all-namespaces' +alias gateways='kubectl get gateways --all-namespaces' +alias secrets='kubectl get secrets --all-namespaces' +alias ingresssecret='kubectl get secrets --all-namespaces | grep istio-ingressgateway-certs' +alias virtualservices='kubectl get virtualservices --all-namespaces' +alias deployments='kubectl get deployments --all-namespaces' +alias mtdrworkshop='echo deployments... ; deployments|grep mtdrworkshop ; echo pods... ; pods|grep mtdrworkshop ; echo services... ; services | grep mtdrworkshop ; echo secrets... ; secrets|grep mtdrworkshop ; echo "other shortcut commands... most can take partial podname as argument, such as [logpod front] or [deletepod order]... pods services secrets deployments " ; ls $MTDRWORKSHOP_LOCATION/utils/' + +export PATH=$PATH:$MTDRWORKSHOP_LOCATION/utils/ diff --git a/mtdrworkshop/frontend/Readme.md b/mtdrworkshop/frontend/Readme.md deleted file mode 100644 index bf48c68..0000000 --- a/mtdrworkshop/frontend/Readme.md +++ /dev/null @@ -1,184 +0,0 @@ -# Frontend (ReactJS) - -## Introduction - -In this lab you will deploy a pre-built ReactJS application locally then build it for production an host it on the Oracle Cloud Infrastucture. - -Estimated Lab Time: 15-minutes - -### Objectives - -In this lab, you will: -- Clone the workshop git repository on your laptop -- Set the API Gateway endpoint -- Run the ReactJS frontend code in Dev Mode then Build for Production -- Host the production build on the Oracle Cloud's object storage - -### Understanding the ReactJS application - -The application is simple; it uses Functional Components with State Hooks for managing states. There is a main component called "App" which renders another component called "NewItem" and two tables of todo items: the active ones and the already done ones. The "NewItem" component displays the text field to add a new item. - -The App component includes the "items" state ([]) which contains the list of todo items. When setItems is called with a new array of items the component will re-render. - -The App component also maintains the following states: - -- "isLoading" is true when waiting for the backend to return the list of items.We use this state to display a spinning wheel while loading. - -- "isInserting" is true when waiting for the backend to process a new insert item. The "Add" button will display a spinning wheel during this time. - -- "error" stores the error messages received during the API calls. - -The index.css file contains all the styles for the application. - -### Prerequisites - -1. This lab requires the completion of lab 1 and 2 - -2. You will be using the npm command, make sure it is installed - - ``` - npm --version - ``` - - if not please install Node for your laptop, using the following - link: `https://bit.ly/3evGlEo`. - -3. The lab requires also Go lang. - - "go version" -> `go version go1.15.2 darwin/amd64` - - ``` - go version - ``` -If not installed, please install Go (see https://golang.org/doc/) - -## **STEP 1**: Configure API.js - -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). - -1. clone again the git repository to a directory on your laptop (we only need the front end in this lab) - ``` - git clone https://github.com/oracle/oci-react-samples.git - ``` - -2. cd frontend - -3. Run the following npm commands to install the required packages - - ``` - npm install --save typescript - ``` - ``` - npm install - ``` - - In case of errors, try the following command - ``` - npm audit fix --force - ``` - - Ideally, npm -version should return > 6.14.x AND Node version > 14.16.x - If npm version < 6.14.x then install the latest Node using - https://bit.ly/3evGlEo - -4. Update API_LIST in API.js - - - Make sure to be in frontend/src directory - ``` - cd frontend/src - ``` - - In the Cloud console, navigate to **Developer Services > API Management** - - Click on your Gateway and go to Deployment - - Copy the Endpoint - - Paste the endpoint as the value of API_LIST and append "/todolist" - - Example - const API_LIST = 'https://xxxxxxxxxx.apigateway.eu-frankfurt-1.oci.customer-oci.com/todolist'; - - - Save the modified API.js file - -## **STEP 2**: Run in Dev Mode then Build for Production - -1. In the project directory, run the app in the development mode
- - ``` - npm start - ``` - -2. Open [http://localhost:3000](http://localhost:3000) to view it in the browser. - -3. The page will reload if you make edits.
- You will also see any lint errors in the console. - -4. Cancel the developer mode execution and build the app for production to the `build` folder.
- -- Issue "Ctrl-c" to cancel the developer mode executions - -- Execute npm run build - ``` - npm run build - ``` -It correctly bundles React in production mode (into the build folder) and optimizes the build for the best performance. - - ![](images/Run-build.png " ") - -The build is minified and the filenames include the hashes.
-Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -## **STEP 3**: Hosting on the Oracle Cloud's object storage - -1. Open up the hamburger menu in the top-left corner of the Console and select -**Object Storage > Object Storage**. - - - Create the 'mtdrworkshop' bucket - -2. Install the Staci utility for copying directories to OCI object storage - bucket with folder hierarchies - - - git clone https://github.com/maxjahn/staci.git - - ``` - git clone https://github.com/maxjahn/staci.git - ``` - - - cd staci - - ``` - cd staci - ``` - - - go get -d - - ``` - go get -d - ``` - - - go build - - ``` - go build - ``` - -3. Upload a static build into the bucket, using the staci binary - -``` -./staci/staci -source build -target mtdrworkshop -``` - -- The application is visible in the 'mtdrworkshop' bucket of your tenancy - -- Click on the index.html object and copy the URL of the index object - - ![](images/bucket-index.png " ") - -- You may now run the application from Object store, using the URL of the index that you've copied above. - - ![](images/MyToDo.png " ") - -Congratulations for completing the entire lab!! - -## Acknowledgements - -* **Author** - - Kuassi Mensah, Dir. Product Management, Java Database Access -* **Contributors** - Jean de Lavarene, Sr. Director of Development, JDBC/UCP -* **Last Updated By/Date** - Kuassi Mensah, Database Product Management, April 2021 diff --git a/mtdrworkshop/frontend/frontend.md b/mtdrworkshop/frontend/frontend.md index adc5304..ea7e6c3 100644 --- a/mtdrworkshop/frontend/frontend.md +++ b/mtdrworkshop/frontend/frontend.md @@ -1,106 +1,141 @@ -# Frontend (ReactJS) +# Deploy the Frontend React JS Application ## Introduction -In this lab you will deploy a pre-built ReactJS application locally then build it for production an host it on the Oracle Cloud Infrastucture. +In this lab you will deploy a pre-built ReactJS application locally then build it for production and host it on Oracle Cloud Infrastucture. -Estimated Lab Time: 15-minutes +Estimated time: 15 minutes -### Objectives +Watch the video below for a quick walk through of the lab. + +Mac: + +[](youtube:cEEKcV3-yTQ) + +Windows: + +[](youtube:rHAf4ZW4XP0) -In this lab, you will: -- Clone the workshop git repository on your laptop -- Set the API Gateway endpoint -- Run the ReactJS frontend code in Dev Mode then Build for Production -- Host the production build on the Oracle Cloud's object storage -### Understanding the ReactJS application +### Understand the ReactJS Application -The application is simple; it uses Functional Components with State Hooks for managing states. There is a main component called "App" which renders another component called "NewItem" and two tables of todo items: the active ones and the already done ones. The "NewItem" component displays the text field to add a new item. +The application is simple; it uses "functional components" with "state hooks" for managing states. There is a main part called "App," which renders another part called "NewItem" and two tables of todo items: the active ones and the already done ones. The "NewItem" part displays the text field for adding a new item. -The App component includes the "items" state ([]) which contains the list of todo items. When setItems is called with a new array of items the component will re-render. +The App part includes the items state ([]) which contains the list of todo items. When setItems is called with a new array of items, the part will re-render. -The App component also maintains the following states: +The App part also maintains the following states: -- "isLoading" is true when waiting for the backend to return the list of items.We use this state to display a spinning wheel while loading. +- "isLoading" is true when waiting for the Java tier to return the list of items. We use this state to display a spinning wheel while loading. -- "isInserting" is true when waiting for the backend to process a new insert item. The "Add" button will display a spinning wheel during this time. +- "isInserting" is true when waiting for the Java tier to process a newly inserted item. The **Add** button will display a spinning wheel during this time. - "error" stores the error messages received during the API calls. -The index.css file contains all the styles for the application. +The index.css file has all the styles for the application. +### Objectives + +In this lab, you will: +- Clone the workshop git repository **on your laptop** +- Set the API Gateway endpoint +- Run the ReactJS frontend code in Dev Mode then Build for Production +- Host the production build on the Oracle Cloud's object storage ### Prerequisites -1. This lab requires the completion of lab 1 and 2 +1. This lab requires the completion of **Setup Dev Environment** and **Backend (Java/Helidon)**. This lab also requires admin rights. -2. You will be using the npm command, make sure it is installed +2. Make sure the `npm` command is installed. - ``` - npm --version - ``` + ``` + npm --version + ``` +3. if `npm` is not installed, install `Node` for your laptop, using `https://bit.ly/3oVTrSh`. - if not please install Node for your laptop, using the following - link: `https://bit.ly/3evGlEo`. +4. Make sure `Go lang` is installed. -3. The lab requires also Go lang. + `go version` shows `go version go1.15.2 darwin/amd64`. - "go version" -> `go version go1.15.2 darwin/amd64` + ``` + go version + ``` +5. If `Go lang` is not installed, see https://golang.org/doc/. - ``` - go version - ``` -If not installed, please install Go (see https://golang.org/doc/) +6. Make sure **git** is installed; if not please follow the instructions @ `https://bit.ly/3DXyjiL`. -## **STEP 1**: Configure API.js +## Task 1: Configure API.js +In this task you will edit API.js to point to the correct endpoint that will be allowed to access the APIs used in your application This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). -1. clone again the git repository to a directory on your laptop (we only need the front end in this lab) +1. Clone the git repository to a directory on your laptop (we only need the front end in this lab) ``` - git clone https://github.com/oracle/oci-react-samples/mtdrworkshop.git + + mkdir reacttoo + cd reacttodo + git clone https://github.com/peterrsongg/oci-react-samples.git + ``` -2. cd frontend +2. Navigate to frontend + ``` + + cd oci-react-samples/mtdrworkshop/frontend + + ``` 3. Run the following npm commands to install the required packages ``` - npm install --save typescript + + npm install --save typescript + ``` ``` - npm install + + npm install + ``` - In case of errors, try the following command - ``` - npm audit fix --force - ``` - - Ideally, npm -version should return > 6.14.x AND Node version > 14.16.x +``` + +npm audit fix --force + +``` + Ideally, npm -version should return > 6.14.x AND Node version > 14.16.x If npm version < 6.14.x then install the latest Node using https://bit.ly/3evGlEo 4. Update API_LIST in API.js - - Make sure to be in frontend/src directory + Make sure to be in frontend/src directory ``` - cd frontend/src + + cd frontend/src + ``` - - In the Cloud console, navigate to **Developer Services > API Management** + In the Cloud console, navigate to **Developer Services > API Management >Gateways** + + ![](images/api-gateway-navigate.png) - Click on your Gateway and go to Deployment - - Copy the Endpoint + - Copy the Deployment Endpoint + + ![](images/api-gtw-deploy.png) + - Paste the endpoint as the value of API_LIST and append "/todolist" - Example + Example: const API_LIST = 'https://xxxxxxxxxx.apigateway.eu-frankfurt-1.oci.customer-oci.com/todolist'; - Save the modified API.js file -## **STEP 2**: Run in Dev Mode then Build for Production - +## Task 2: Run in Dev Mode then Build for Production +Here you will run the application locally in development mode, then run in production mode to create the build folder. 1. In the project directory, run the app in the development mode
``` - npm start + + npm start + ``` 2. Open [http://localhost:3000](http://localhost:3000) to view it in the browser. @@ -108,61 +143,86 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo 3. The page will reload if you make edits.
You will also see any lint errors in the console. -4. Cancel the developer mode execution and build the app for production to the `build` folder.
+4. Cancel the developer mode execution and build the app for production to the `build` folder. This will create a folder named `build` for you
- Issue "Ctrl-c" to cancel the developer mode executions - Execute npm run build ``` - npm run build + + npm run build + ``` It correctly bundles React in production mode (into the build folder) and optimizes the build for the best performance. - ![](images/Run-build.png " ") + ![](images/run-build.png " ") The build is minified and the filenames include the hashes.
Your app is ready to be deployed! See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. -## **STEP 3**: Hosting on the Oracle Cloud's object storage +## Task 3: Hosting on the Oracle Cloud's Object Storage +The build folder will be uploaded to object storage so you can access your application from OCI. 1. Open up the hamburger menu in the top-left corner of the Console and select **Object Storage > Object Storage**. - - Create the 'mtdrworkshop' bucket + ![](images/object-store-navigate.png) + Create the 'mtdrworkshop' (or another name if that's taken) bucket + ![](images/create-bucket.png) + + Enter in the bucket details. + ![](images/bucket-details.png) + + Edit visibility to public + + ![](images/edit-visibility.png) 2. Install the Staci utility for copying directories to OCI object storage bucket with folder hierarchies - git clone https://github.com/maxjahn/staci.git ``` - git clone https://github.com/maxjahn/staci.git + + git clone https://github.com/maxjahn/staci.git + ``` - cd staci ``` - cd staci + + cd staci + ``` - go get -d ``` - go get -d + + go get -d + ``` - go build ``` - go build + + go build + ``` +3. If you have never used your laptop for connecting to an Oracle Cloud account, you need to setup an **OCI config file** and create an **API key** + * Follow Step #2 in the following doc https://bit.ly/3vM7v2h for that purpose. -3. Upload a static build into the bucket, using the staci binary +4. Upload a static build into the bucket, using the staci binary. +`-source build` should be the path to `build` from `npm run build` earlier. `-target mtdrworkshop` should be the name of the bucket ``` -./staci/staci -source build -target mtdrworkshop + +./staci/staci -source build -target mtdrworkshop + ``` - The application is visible in the 'mtdrworkshop' bucket of your tenancy @@ -173,12 +233,12 @@ See the section about [deployment](https://facebook.github.io/create-react-app/d - You may now run the application from Object store, using the URL of the index that you've copied above. - ![](images/MyToDo.png " ") - -Congratulations for completing the entire lab!! + ![](images/my-todo.png " ") + +You may now **proceed to the next lab**. ## Acknowledgements -* **Author** - - Kuassi Mensah, Dir. Product Management, Java Database Access +* **Authors** - Kuassi Mensah, Dir. Product Management, Java Database Access; Peter Song, Developer Advocate JDBC * **Contributors** - Jean de Lavarene, Sr. Director of Development, JDBC/UCP -* **Last Updated By/Date** - Kuassi Mensah, Database Product Management, April 2021 +* **Last Updated By/Date** - Peter Song, Developer Advocate JDBC diff --git a/mtdrworkshop/frontend/images/MyToDo.png b/mtdrworkshop/frontend/images/MyToDo.png deleted file mode 100644 index 370e18a..0000000 Binary files a/mtdrworkshop/frontend/images/MyToDo.png and /dev/null differ diff --git a/mtdrworkshop/frontend/images/api-gateway-navigate.png b/mtdrworkshop/frontend/images/api-gateway-navigate.png new file mode 100644 index 0000000..8b8e169 Binary files /dev/null and b/mtdrworkshop/frontend/images/api-gateway-navigate.png differ diff --git a/mtdrworkshop/frontend/images/bucket-details.png b/mtdrworkshop/frontend/images/bucket-details.png new file mode 100644 index 0000000..7cb9002 Binary files /dev/null and b/mtdrworkshop/frontend/images/bucket-details.png differ diff --git a/mtdrworkshop/frontend/images/bucket-index.png b/mtdrworkshop/frontend/images/bucket-index.png index d81979a..581c549 100644 Binary files a/mtdrworkshop/frontend/images/bucket-index.png and b/mtdrworkshop/frontend/images/bucket-index.png differ diff --git a/mtdrworkshop/frontend/images/create-bucket.png b/mtdrworkshop/frontend/images/create-bucket.png new file mode 100644 index 0000000..93f1096 Binary files /dev/null and b/mtdrworkshop/frontend/images/create-bucket.png differ diff --git a/mtdrworkshop/frontend/images/edit-visibility.png b/mtdrworkshop/frontend/images/edit-visibility.png new file mode 100644 index 0000000..ae2e62f Binary files /dev/null and b/mtdrworkshop/frontend/images/edit-visibility.png differ diff --git a/mtdrworkshop/frontend/images/frontendimg1.png b/mtdrworkshop/frontend/images/frontendimg1.png deleted file mode 100644 index 0f07fc5..0000000 Binary files a/mtdrworkshop/frontend/images/frontendimg1.png and /dev/null differ diff --git a/mtdrworkshop/frontend/images/my-todo.png b/mtdrworkshop/frontend/images/my-todo.png new file mode 100644 index 0000000..23677cc Binary files /dev/null and b/mtdrworkshop/frontend/images/my-todo.png differ diff --git a/mtdrworkshop/frontend/images/object-store-navigate.png b/mtdrworkshop/frontend/images/object-store-navigate.png new file mode 100644 index 0000000..187737f Binary files /dev/null and b/mtdrworkshop/frontend/images/object-store-navigate.png differ diff --git a/mtdrworkshop/installFrontendLB.sh b/mtdrworkshop/installFrontendLB.sh deleted file mode 100644 index 219f31a..0000000 --- a/mtdrworkshop/installFrontendLB.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -## MyToDoReact version 1.0. -## -## Copyright (c) 2021 Oracle, Inc. -## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ -echo create frontend LB... -kubectl create -f frontend-helidon/frontend-service.yaml -n mtdrworkshop diff --git a/mtdrworkshop/setCompartmentId.sh b/mtdrworkshop/setCompartmentId.sh deleted file mode 100644 index dcc2b20..0000000 --- a/mtdrworkshop/setCompartmentId.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -## MyToDoReact version 1.0. -## -## Copyright (c) 2021 Oracle, Inc. -## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ - -if [[ $1 == "" ]] -then - echo Required argument MTDRWORKSHOP_COMPARTMENT_ID not provided. The compartmentid can be copied from the OCI Console. - echo Usage example : ./setCompartmentId.sh ocid1.compartment.oc1..aaaaaaaaxbvaatfz6dyfqbxhmasxfyui4rjek5dnzgcbivfwvsho77myfnqq us-ashburn-1 - exit -fi - -if [[ $2 == "" ]] -then - echo Required argument $MTDRWORKSHOP_REGION not provided. The region id can be copied from the OCI Console. - echo Usage example : ./setCompartmentId.sh ocid1.compartment.oc1..aaaaaaaaxbvaatfz6dyfqbxhmasxfyui4rjek5dnzgcbivfwvsho77myfnqq us-ashburn-1 - exit -fi - -echo ________________________________________ -echo setting compartmentid and region ... -echo ________________________________________ - -export WORKINGDIR=workingdir -echo creating working directory $WORKINGDIR to store values... -mkdir $WORKINGDIR - -export MTDRWORKSHOP_REGION=$2 -echo $MTDRWORKSHOP_REGION | tr -d '"' > $WORKINGDIR/mtdrworkshopregion.txt -echo MTDRWORKSHOP_REGION... $MTDRWORKSHOP_REGION - -export MTDRWORKSHOP_COMPARTMENT_ID=$1 -echo $MTDRWORKSHOP_COMPARTMENT_ID | tr -d '"' > $WORKINGDIR/mtdrworkshopcompartmentid.txt -echo MTDRWORKSHOP_COMPARTMENT_ID... $MTDRWORKSHOP_COMPARTMENT_ID diff --git a/mtdrworkshop/setup-dev-environment/Readme.md b/mtdrworkshop/setup-dev-environment/Readme.md deleted file mode 100644 index cb7608c..0000000 --- a/mtdrworkshop/setup-dev-environment/Readme.md +++ /dev/null @@ -1,357 +0,0 @@ -# Setup Dev Environment - -## Introduction - -In this lab, you will configure your development environment and collect information that will be used later throughout this workshop. - -Estimated Lab Time: ~25 minutes - -### Objectives - -* Launch Cloud Shell -* Download the workshop code and scripts from GitHub -* Set up an OCI Compartment and install a two nodes OKE cluster -* Create the ATP database, the user schema and a database table -* Install GraalVM -* Create an OCI Registry and Auth key -* Access OKE from the Cloud Shell - -### Prerequisites - -- This lab requires an [Oracle Cloud account](https://www.oracle.com/cloud/free/). You may use your own cloud account, a cloud account that you obtained through a trial, a Free Tier account, or a LiveLabs account. - -## **STEP 1**: Launch the Cloud Shell and Clone mtdrworkshop GitHup repository - -1. Launch Cloud Shell - - The Cloud Shell is a small virtual machine running a Bash shell which you access through the OCI Console. It comes with a pre-authenticate CLI pre-installed and configured so you can immediately start working in your tenancy without having to spend time on installation and configuration! - - Click the Cloud Shell icon in the top-right corner of the Console. - ![](images/7-open-cloud-shell.png " ") - -2. Clone the GitHub repo and move up the `mtdrworkshop` directory. - - ```` - - git clone https://github.com/oracle/oci-react-samples.git - - ```` - Move up mtdrworkshop directory (most scripts assume it is at the home/root directory) - ```` - - cd ~/oci-react-samples; mv mtdrworkshop .. - ```` - - You should now see `mtdrworkshop` in your root directory - -3. Change to the mtdrworkshop directory: - - ``` - cd ~mtdrworkshop - - ``` - - -4. Set the execution mode for all Shell scripts - - ``` - chmod +x *.sh */*.sh - ``` - -NOTE: THE CLOUD SHELL WILL DISCONNECT AFTER A CERTAIN PERIOD OF INACTIVITY. - -IF YOU ARE DISCONNECTED OR LOGGED OFF AND RETURN TO CLOUD SHELL, MAKE SURE YOU ARE IN THE ~/mtdrworkshop DIRECTORY. - -## **STEP 2**: Create an OCI compartment and an OKE cluster in that compartment - -1. Open up the hamburger menu in the top-left corner of the Console and select **Identity > Compartments**. - - ![](images/15-identity-compartments.png " ") - -2. Click **Create Compartment** with the following parameters then click **Create Compartment**: - - ![](images/16-create-compartment.png " ") - - - Compartment name: `mtdrworkshop` - - Description: `My ToDo React workshop compartment` - - ![](images/17-create-compartment2.png " ") - -3. Once the compartment has been created, click the name of the compartment and - then click **Copy** to copy the OCID. - - ![](images/19-compartment-name-ocid.png " ") - - ![](images/20-compartment-ocid.png " ") - -4. Go back into your cloud shell and verify you are in the `~/mtdrworkshop` directory. - -5. Run `./setCompartmentId.sh ` where your `` and `` values are set as arguments. - - For example: - - `./setCompartmentId.sh ocid1.compartment.oc1..aaaaaaaaxbvaatfz6yourcomparmentidhere5dnzgcbivfwvsho77myfnqq us-ashburn-1` - -6. To create an OKE cluster, return to the OCI console and open up the hamburger button in the top-left corner of the Console and go to **Developer Services > Kubernetes Clusters**. - - ![](images/27-dev-services-oke.png " ") - -7. Make sure you are in the newly created compartment and click **Create Cluster**. - (Please use the default schema in the unlikely situation that the newly created compartment is not quickly visible on the left pickler) - ![](images/28-create-oke.png " ") - -8. Choose **Quick Create** as it will create the new cluster along with the new network resources such as Virtual Cloud Network (VCN), Internet Gateway (IG), NAT Gateway (NAT), Regional Subnet for worker nodes, and a Regional Subnet for load balancers. Click **Launch Workflow**. - - ![](images/29-create-oke-wizard.png " ") - -9. Change the name of the cluster to `mtdrworkshopcluster`, accept all the other defaults, and click **Next** to review the cluster settings. - - -10. Once reviewed click **Create Cluster**, and you will see the resource creation progress. - - ![](images/31-create-oke-wizard3.png " ") - -11. Close the creation window once you can. - - ![](images/32-close-cluster-create.png " ") - -12. Once launched it should usually take around 5-10 minutes for the cluster to be fully provisioned and the Cluster Status should show Active. - - ![](images/33-click-cluster-name.png " ") - - ![](images/34-copy-cluster-id.png " ") - - _There is no need to wait for the cluster to be fully provisioned at this point as we will verify cluster creation and create a kube config in order to access it in a later step._ - - -## **STEP 3**: Create the ATP database, TODOUSER and the TODOITEM table - -1. Open up the hamburger menu in the top-left corner of the Console and select **Autonomous Transaction Processing**. - - ![](images/menu-autonomous.png " ") - -2. Click on **Create Autonomous Database**. - - ![](images/create-autonomous.png " ") - -3. Set **Compartment, Database Name and Display Name**. - - - Set the workload type to "Transaction Processing". - - Accept the default deployment type i.e., "Shared Infrastructure". - - ![](images/ATP-config-1.png " ") - - 4. Set **ADMIN password, Network Access Type and License Type** - - Set the database ADMIN password (12 to 30 characters, at least one uppercase letter, one lowercase letter, and one number) and confirm. - Please note the ADMIN password; it will be required later. - - Set the Network Access type to "Allow secure access from specific IPs an VCNs". - - Set the license type to "Bring Your Own License (BYOL)" (does not matter for this workshop) - - Click on "Create Autonomous Database" - - ![](images/ADB-setup.png " ") - -The database creation will take a few minutes. - -5. Populate mtdrworkshopdbid.txt with the database OCID - - Create the `~/mtdrworkshop/workingdir/mtdrworkshopdbid.txt` file. - ``` - touch ~/mtdrworkshop/workingdir/mtdrworkshopdbid.txt - ``` - - - Copy the OCID of the newly created database from the Cloud console and - add it into `~/mtdrworkshop/workingdir/mtdrworkshopdbid.txt` file. - - ![](images/42-copy-atp-ocids2.png " ") - -6. Generate the Wallet for your ATP Connectivity - - - Still in Cloud Shell, make sure you are in the - `~/mtdrworkshop/setup-dev-environment` directory. - - - Copy the following command and replace $OCID by the - copied OCID. - - ``` - ./generateWallet.sh $OCID - ``` - - Execute generateWallet.sh ocid1.autonomousdatabase.oc1.phx.abyhqlj.... - - You will be requested to enter a password for wallet encryption, this is separate for the ADMIN password but you could reuse the statement. - A wallet.zip file will be created in the current directory. - -7. Create TODOUSER using sql utility in Cloud shell - - - Stay in mtdrwokshop/setup-dev-environment directory and launch - sql with /nolog option - - ![](images/SQLCl-Cloud-Shell.png " ") - - - Point the tool at your wallet.zip file - SQL> set cloudconfig wallet.zip - - SQL> show tns - ![](images/Show-tns.png " ") - - - Connect to mtdrdb_tp service, as database ADMIN user (remember the - password given to ADMIN above) - - SQL> connect ADMIN@mtdrdb_tp - - - Create TODOUSER (replace by a strong password). - - ``` - CREATE USER todouser IDENTIFIED BY DEFAULT TABLESPACE data QUOTA UNLIMITED ON data; - ``` - - Grant some privileges to TODOUSER by executing the following command - ``` - grant create session, create view, create sequence, create procedure, create table, create trigger, create type, create materialized view to todouser; - ``` - - Connect as TODOUSER - SQL> connect todouser@mtdrdb_tp - - - Create TODOITEM table - - Copy the following command in the Worksheet and execute. - ``` - CREATE TABLE todoitem ( - id NUMBER GENERATED ALWAYS AS IDENTITY, - description VARCHAR2(4000), - creation_ts TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, - done NUMBER(1,0), - PRIMARY KEY (id) - ); - ``` - - Insert the first row, manually into TODOITEM table - ``` - insert into todoitem (description) values ('Manual item insert'); - ``` - Then commit the inserted row - ``` - commit; - ``` - -## **STEP 4**: Create an OCI Registry and Auth key - You are now going to create an Oracle Cloud Infrastructure Registry and an Auth key. The Oracle Cloud Infrastructure Registry is an Oracle-managed registry that enables you to simplify your development-to-production workflow by storing, sharing, and managing development artifacts such as Docker images. - -1. Open up the hamburger menu in the top-left corner of the console and go to **Developer Services > Container Registry**. - - ![](images/21-dev-services-registry.png " ") - -2. Take note of the namespace (for example, `axkcsk2aiatb` shown in the image below). - - ![](images/22-create-repo.png " ") - - Click **Create Repository** , specify the following details for your new repository, and click **Create Repository**. - - Repository Name: `/mtdrworkshop` - - Access: `Public` - - Go to Cloud Shell and run `./addOCIRInfo.sh` with the namespace and repository name as arguments - - ``` - ./addOCIRInfo.sh - ``` - For example `./addOCIRInfo.sh axkcsk2aiatb mtdrworkshop.user1/mtdrworkshop`. - -3. You will now create the Auth token by going back to the User Settings page. Click the Profile icon in the top-right corner of the Console and select **User Settings**. - - ![](images/23-user-settings.png " ") - -4. Click on **Auth Tokens** and select **Generate Token**. - - ![](images/24-gen-auth-token.png " ") - -5. In the description type `mtdrworkshoptoken` and click **Generate Token**. - - ![](images/25-gen-auth-token2.png " ") - -6. Copy the token value. - - ![](images/26-save-auth-token.png " ") - -7. Go to Cloud Shell, at the workshop root directory and run the - dockerLogin.sh scripts ... - `./dockerLogin.sh ""` where - - * `` - is the username used to log in (typically your email address). If your username is federated from Oracle Identity Cloud Service, you need to add the `oracleidentitycloudservice/` prefix to your username, for example `oracleidentitycloudservice/firstname.lastname@something.com` - - * `""` - paste the generated token value and enclose the value in quotes. - - For example `dockerLogin.sh user.foo@bar.com "8nO[BKNU5iwasdf2xeefU;yl"`. - -8. Once successfully logged into Container Registry, we can list the existing docker images. Since this is the first time logging into Registry, no images will be shown. - - ``` - docker images - ``` -## **STEP 5**: Install GraalVM in Cloud Shell - - We will be using JDK 11 in Cloud Shell to build the Java/Helidon image -1. Set some environment variables and run the following commands - - ``` - export MTDRWORKSHOP_LOCATION=~/mtdrworkshop - ``` - ``` - export WORKINGDIR=$MTDRWORKSHOP_LOCATION/workingdir - ``` - - Make sure to be in mtdrwokshop/setup-dev-environment directory then execute the following script - ``` - ./installGraalVM.sh - ``` - -## **STEP 6**: Access OKE from the Cloud Shell - -1. Create the mtdrworkshop/workingdir/mtdrworkshopclusterid.txt file - - ``` - touch mtdrworkshop/workingdir/mtdrworkshopclusterid.txt - ``` -2. Navigate to **Developer Services > Kubernetes Clusters** - -3. Copy the mdtrworkshopcluster id and paste into the newly created file - ![](images/mtdrworkshop-cluster-id.png " ") - - -3. Run `./verifyOKEAndCreateKubeConfig.sh` - - ``` - ./verifyOKEAndCreateKubeConfig.sh - ``` - - Notice `/.kube/config` is created for the OKE cluster. - - ![](images/verifyOKEOutput.png " ") - -## **STEP 7**: Configuring Network Security Rules - -1. The network security rules control the inbound (Ingres) and the outbound (Egress) traffic. As we will be configuring the API Gateway in Part II, we will not set tight security rules at the Kubernetes cluster level. - -2. Navigate to **Developer Services > Kubernetes Clusters** - - Click on the **mtdrworkshopcluster**. - -3. Click on VCN Name - - ![](images/VCN-name.png " ") -4. Click on the VCN named starting with oke-svclbsubnet-quick-mtdrworkshpcluster - ![](images/oke-svclbsubnet.png " ") - -5. Click on the existing security list - ![](images/Add-security-lists.png " ") - -6. Add an Ingress Rule - Set the Destination CIDR as indicated (leave other fields as is) then Click `Add Ingress Rules` - - ![](images/Ingress-rule.png " ") - -7. Add an Egress Rule - Set Stateless and Destination CIDR as indicated in the image (leave other fields as-is) then Click `Add Egress Rules` - - ![](images/Egress-rule.png " ") - -Congratulations, you have completed lab 1; you may now [proceed to the next lab](#next). - -## Acknowledgements - -* **Author** - - Kuassi Mensah, Dir. Product Management, Java Database Access -* **Contributors** - Jean de Lavarene, Sr. Director of Development, JDBC/UCP -* **Last Updated By/Date** - Kuassi Mensah, Database Product Management, April 2021 diff --git a/mtdrworkshop/setup-dev-environment/files/MyToDoReactWorksheet.txt b/mtdrworkshop/setup-dev-environment/files/MyToDoReactWorksheet.txt deleted file mode 100644 index da7b962..0000000 --- a/mtdrworkshop/setup-dev-environment/files/MyToDoReactWorksheet.txt +++ /dev/null @@ -1,14 +0,0 @@ -Tenancy OCID: -Object Store Namespace: -Region Identifier: -Username: -User OCID: -PEM passphrase: -API Key Fingerprint: -mtdrworkshop compartment OCID: -OCI Registry: -mtdrworkshoptoken: -mtdrworkshopcluster Cluster Id: -MTDR DB Admin password: -MTDR DB OCID: -Load balancer external IP address and port: :8080 diff --git a/mtdrworkshop/setup-dev-environment/generateWallet.sh b/mtdrworkshop/setup-dev-environment/generateWallet.sh deleted file mode 100644 index 917b78a..0000000 --- a/mtdrworkshop/setup-dev-environment/generateWallet.sh +++ /dev/null @@ -1,18 +0,0 @@ -echo ________________________________________ -echo Wallet generation for MTDRDB ... -echo ________________________________________ - -if [[ $1 == "" ]] -then - echo DB OCID not provided - echo Usage example : ./generateWallet.sh ocid1.autonomousdatabase.oc1.phx.abyhqljtza4ucpamla4huo5o2iopoxk55hia3rfubnwgpmzolya - exit -fi -export DB_OCID=$1 -read -s -p "Wallet Password: " mtdrdb_wallet_password -umask 177 -cat >pw < $WORKINGDIR/mtdrworkshopgraalvmhome.txt diff --git a/mtdrworkshop/setup-dev-environment/setup-dev-environment.md b/mtdrworkshop/setup-dev-environment/setup-dev-environment.md index f134e3f..a5f4c14 100644 --- a/mtdrworkshop/setup-dev-environment/setup-dev-environment.md +++ b/mtdrworkshop/setup-dev-environment/setup-dev-environment.md @@ -1,355 +1,223 @@ -# Setup Dev Environment +# Setup the development environment ## Introduction -In this lab, you will configure your development environment and collect information that will be used later throughout this workshop. +In this lab, you will configure your development environment and collect information that will be used later throughout this workshop. The setup script requires certain environment variables to be set, which is why a script for configuring the environment variables is necessary. After the environment varialbes are set, the setup script uses Terraform, Bash, and SQL to automate the creation of all the resources needed for this lab, such as VCN's, an OKE Cluster, API Gateway, Autonomous database, etc. The script also creates a table and inserts one row into the table, which we will use to make sure the setup was done correctly. -Estimated Lab Time: ~25 minutes +Estimated time: 30 minutes -### Objectives - -* Launch Cloud Shell -* Download the workshop code and scripts from GitHub -* Set up an OCI Compartment and install a two nodes OKE cluster -* Create the ATP database, the user schema and a database table -* Install GraalVM -* Create an OCI Registry and Auth key -* Access OKE from the Cloud Shell - -### Prerequisites - -- This lab requires an [Oracle Cloud account](https://www.oracle.com/cloud/free/). You may use your own cloud account, a cloud account that you obtained through a trial, a Free Tier account, or a LiveLabs account. - -## **STEP 1**: Launch the Cloud Shell and Clone mtdrworkshop GitHup repository - -1. Launch Cloud Shell - - The Cloud Shell is a small virtual machine running a Bash shell which you access through the OCI Console. It comes with a pre-authenticate CLI pre-installed and configured so you can immediately start working in your tenancy without having to spend time on installation and configuration! - - Click the Cloud Shell icon in the top-right corner of the Console. - ![](images/7-open-cloud-shell.png " ") - -2. Clone the GitHub repo and move up the `mtdrworkshop` directory. - - ```` - - git clone https://github.com/oracle/oci-react-samples.git - - ```` - Then - ```` - - cd ~/oci-react-samples; mv mtdrworkshop .. - ```` - - You should now see `mtdrworkshop` in your root directory - -3. Change to the mtdrworkshop directory: - - ``` - cd ~mtdrworkshop - - ``` -4. Set the execution mode for all Shell scripts - - ``` - chmod +x *.sh */*.sh - ``` - -NOTE: THE CLOUD SHELL WILL DISCONNECT AFTER A CERTAIN PERIOD OF INACTIVITY. - -IF YOU ARE DISCONNECTED OR LOGGED OFF AND RETURN TO CLOUD SHELL, MAKE SURE YOU ARE IN THE ~/mtdrworkshop DIRECTORY. - -## **STEP 2**: Create an OCI compartment and an OKE cluster in that compartment - -1. Open up the hamburger menu in the top-left corner of the Console and select **Identity > Compartments**. - - ![](images/15-identity-compartments.png " ") - -2. Click **Create Compartment** with the following parameters then click **Create Compartment**: - - ![](images/16-create-compartment.png " ") +Watch the video below for a quick walk through of the lab. - - Compartment name: `mtdrworkshop` - - Description: `My ToDo React workshop compartment` +[](youtube:l6hEDTdOiEI) - ![](images/17-create-compartment2.png " ") - -3. Once the compartment has been created, click the name of the compartment and - then click **Copy** to copy the OCID. - - ![](images/19-compartment-name-ocid.png " ") - - ![](images/20-compartment-ocid.png " ") - -4. Go back into your cloud shell and verify you are in the `~/mtdrworkshop` directory. - -5. Run `./setCompartmentId.sh ` where your `` and `` values are set as arguments. - - For example: - - `./setCompartmentId.sh ocid1.compartment.oc1..aaaaaaaaxbvaatfz6yourcomparmentidhere5dnzgcbivfwvsho77myfnqq us-ashburn-1` - -6. To create an OKE cluster, return to the OCI console and open up the hamburger button in the top-left corner of the Console and go to **Developer Services > Kubernetes Clusters**. - - ![](images/27-dev-services-oke.png " ") - -7. Make sure you are in the newly created compartment and click **Create Cluster**. - (Please use the default schema in the unlikely situation that the newly created compartment is not quickly visible on the left pickler) - ![](images/28-create-oke.png " ") - -8. Choose **Quick Create** as it will create the new cluster along with the new network resources such as Virtual Cloud Network (VCN), Internet Gateway (IG), NAT Gateway (NAT), Regional Subnet for worker nodes, and a Regional Subnet for load balancers. Click **Launch Workflow**. - - ![](images/29-create-oke-wizard.png " ") - -9. Change the name of the cluster to `mtdrworkshopcluster`, accept all the other defaults, and click **Next** to review the cluster settings. - - -10. Once reviewed click **Create Cluster**, and you will see the resource creation progress. - - ![](images/31-create-oke-wizard3.png " ") - -11. Close the creation window once you can. - - ![](images/32-close-cluster-create.png " ") - -12. Once launched it should usually take around 5-10 minutes for the cluster to be fully provisioned and the Cluster Status should show Active. - - ![](images/33-click-cluster-name.png " ") +### Objectives - ![](images/34-copy-cluster-id.png " ") +* Create group and give the appropriate permissions to run the setup +* Clone the github repository and execute setup script to create the following resources: + * 1 Autonomous database + * 1 API gateway + * 1 Object Storage bucket + * 1 OKE cluster + * 1 OCI Registry + * 1 Virtual Cloud Network - _There is no need to wait for the cluster to be fully provisioned at this point as we will verify cluster creation and create a kube config in order to access it in a later step._ +### Prerequisites +* This lab requires an [Oracle Cloud account](https://www.oracle.com/cloud/free/). You may use your own cloud account, a cloud account that you obtained through a trial, a Free Tier account, or a LiveLabs account. -## **STEP 3**: Create the ATP database, TODOUSER and the TODOITEM table +## Task 1: Create Group and Appropriate Policies +[Policies](https://docs.oracle.com/en-us/iaas/Content/Identity/Concepts/policies.htm) determine what resources users are allowed to access and what level of access they have. You can create a group and add as many users as you like to that group. -1. Open up the hamburger menu in the top-left corner of the Console and select **Autonomous Transaction Processing**. +If you are not the tenancy administrator, there may be additional policies you must have in your group to perform some of the steps for this lab. If you cannot create a group and add specific policies, please ask your tenancy administrator for the correct policies in order to follow along. - ![](images/menu-autonomous.png " ") +**If your group already has the permissions listed in part 6 of this step you may skip to Task 2.** -2. Click on **Create Autonomous Database**. +1. First make sure you are in your home region. - ![](images/create-autonomous.png " ") + ![](images/home-region.png) -3. Set **Compartment, Database Name and Display Name**. - - Set the workload type to "Transaction Processing". - - Accept the default deployment type i.e., "Shared Infrastructure". +2. Click the navigation menu in the top left, click on identity and security and select Groups. - ![](images/ATP-config-1.png " ") + ![](images/groups.png) - 4. Set **ADMIN password, Network Access Type and License Type** - - Set the database ADMIN password (12 to 30 characters, at least one uppercase letter, one lowercase letter, and one number) and confirm. - Please note the ADMIN password; it will be required later. - - Set the Network Access type to "Allow secure access from specific IPs an VCNs". - - Set the license type to "Bring Your Own License (BYOL)" (does not matter for this workshop) - - Click on "Create Autonomous Database" - ![](images/ADB-setup.png " ") +3. Click on Create Group -The database creation will take a few minutes. + ![](images/create-group.png) -5. Populate mtdrworkshopdbid.txt with the database OCID - - Create the `~/mtdrworkshop/workingdir/mtdrworkshopdbid.txt` file. - ``` - touch ~/mtdrworkshop/workingdir/mtdrworkshopdbid.txt - ``` - - Copy the OCID of the newly created database from the Cloud console and - add it into `~/mtdrworkshop/workingdir/mtdrworkshopdbid.txt` file. +4. Enter the details for group name and description. Be mindful of the restrictions for group name (no spaces, etc.) - ![](images/42-copy-atp-ocids2.png " ") + ![](images/group-details.png) -6. Generate the Wallet for your ATP Connectivity + Once you have filled in these details click create. Your group should show up under Groups - - Still in Cloud Shell, make sure you are in the - `~/mtdrworkshop/setup-dev-environment` directory. + ![](images/group-created.png) - - Copy the following command and replace $OCID by the - copied OCID. - ``` - ./generateWallet.sh $OCID - ``` - - Execute generateWallet.sh ocid1.autonomousdatabase.oc1.phx.abyhqlj.... - You will be requested to enter a password for wallet encryption, this is separate for the ADMIN password but you could reuse the statement. - A wallet.zip file will be created in the current directory. +5. Navigate to policies and click Create Policy -7. Create TODOUSER using sql utility in Cloud shell + ![](images/policy-navigation.png) - - Stay in mtdrwokshop/setup-dev-environment directory and launch - sql with /nolog option + ![](images/create-policy.png) +6. You should see a page like this. This is where you will create the policy that will give the group permissions to execute the setup for this workshop. - ![](images/SQLCl-Cloud-Shell.png " ") + ![](images/policy-details.png) +Select **Show manual editor** and copy and paste these policies in the box below +``` + +Allow group myToDoGroup to use cloud-shell in tenancy +Allow group myToDoGroup to manage users in tenancy +Allow group myToDoGroup to manage all-resources in tenancy +Allow group myToDoGroup to manage buckets in tenancy +Allow group myToDoGroup to manage objects in tenancy + +``` +7. Add your user to the group that you have just created by selecting the name of the group you have created and selecting add user to group - - Point the tool at your wallet.zip file - SQL> set cloudconfig wallet.zip + ![](images/add-user-group.png) - SQL> show tns - ![](images/Show-tns.png " ") +## Task 2: Launch the Cloud Shell - - Connect to mtdrdb_tp service, as database ADMIN user (remember the - password given to ADMIN above) - SQL> connect ADMIN@mtdrdb_tp +1. Launch Cloud Shell - - Create TODOUSER (replace by a strong password). + The Cloud Shell is a small virtual machine running a Bash shell which you access through the OCI Console. It comes with a pre-authenticated CLI pre-installed and configured so you can immediately start working in your tenancy without having to spend time on installation and configuration! - ``` - CREATE USER todouser IDENTIFIED BY DEFAULT TABLESPACE data QUOTA UNLIMITED ON data; - ``` - - Grant some privileges to TODOUSER by executing the following command - ``` - grant create session, create view, create sequence, create procedure, create table, create trigger, create type, create materialized view to todouser; - ``` - - Connect as TODOUSER - SQL> connect todouser@mtdrdb_tp + Click the Cloud Shell icon in the top-right corner of the Console. - - Create TODOITEM table - Copy the following command in the Worksheet and execute. - ``` - CREATE TABLE todoitem ( - id NUMBER GENERATED ALWAYS AS IDENTITY, - description VARCHAR2(4000), - creation_ts TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, - done NUMBER(1,0), - PRIMARY KEY (id) - ); - ``` - - Insert the first row, manually into TODOITEM table - ``` - insert into todoitem (description) values ('Manual item insert'); - ``` - Then commit the inserted row - ``` - commit; - ``` + ![](images/7-open-cloud-shell.png) -## **STEP 4**: Create an OCI Registry and Auth key - You are now going to create an Oracle Cloud Infrastructure Registry and an Auth key. The Oracle Cloud Infrastructure Registry is an Oracle-managed registry that enables you to simplify your development-to-production workflow by storing, sharing, and managing development artifacts such as Docker images. +## Task 3: Create a Folder for the Workshop Code -1. Open up the hamburger menu in the top-left corner of the console and go to **Developer Services > Container Registry**. +1. Create a directory. The directory name will also be used to create a compartment of the same name in your tenancy if you do not provide one of your own. The directory name must be between 1 and 13 characters, contain only letters or numbers, and start with a letter. Make sure that a compartment of the same name does not already exist in your tenancy or the setup will fail. - ![](images/21-dev-services-registry.png " ") + ```` + + mkdir reacttodo + + ```` + ```` + + cd reacttodo + + ```` -2. Take note of the namespace (for example, `axkcsk2aiatb` shown in the image below). +## Task 4: Clone the Workshop Code - ![](images/22-create-repo.png " ") +1. Clone the workshop code inside the directory you just created. + ```` + + git clone https://github.com/oracle/oci-react-samples.git + + ```` + You should now see `oci-react-samples` in your root directory - Click **Create Repository** , specify the following details for your new repository, and click **Create Repository**. - - Repository Name: `/mtdrworkshop` - - Access: `Public` +## Task 5: Start the Setup - Go to Cloud Shell and run `./addOCIRInfo.sh` with the namespace and repository name as arguments +The setup script uses terraform, bash scripts, and SQL to automate the creation of the resources needed for this lab. The script will ask for the necessary components to automate resource creation. - ``` - ./addOCIRInfo.sh - ``` - For example `./addOCIRInfo.sh axkcsk2aiatb mtdrworkshop.user1/mtdrworkshop`. -3. You will now create the Auth token by going back to the User Settings page. Click the Profile icon in the top-right corner of the Console and select **User Settings**. +1. Change to the mtdrworkshop directory: - ![](images/23-user-settings.png " ") + ``` + + cd oci-react-samples/mtdrworkshop + + ``` +2. Copy this command to make sure that env.sh gets run everytime you start up cloud shell -4. Click on **Auth Tokens** and select **Generate Token**. + ``` + + echo source $(pwd)/env.sh >> ~/.bashrc + + ``` +3. Run the following sequence of commands to start the setup + ``` + + source env.sh + source setup.sh + + ``` +4. If the previous steps were done correctly, the setup will ask for your OCID. - ![](images/24-gen-auth-token.png " ") + ![](images/terminal-user-ocid.png) -5. In the description type `mtdrworkshoptoken` and click **Generate Token**. + To find your user's OCID navigate to the upper right within the OCI console and click on your username. - ![](images/25-gen-auth-token2.png " ") -6. Copy the token value. - ![](images/26-save-auth-token.png " ") +![](images/navigate-user-ocid.png) -7. Go to Cloud Shell, at the workshop root directory and run the - dockerLogin.sh scripts ... - `./dockerLogin.sh ""` where - * `` - is the username used to log in (typically your email address). If your username is federated from Oracle Identity Cloud Service, you need to add the `oracleidentitycloudservice/` prefix to your username, for example `oracleidentitycloudservice/firstname.lastname@something.com` + Copy your user's OCID by clicking copy - * `""` - paste the generated token value and enclose the value in quotes. + ![](images/copy-user-ocid.png) - For example `dockerLogin.sh user.foo@bar.com "8nO[BKNU5iwasdf2xeefU;yl"`. +5. The setup will then ask for your compartment OCID. If you have a compartment, enter the compartment's OCID. If you do not have a compartment then hit enter and it will create a compartment under the root compartment for you automatically. -8. Once successfully logged into Container Registry, we can list the existing docker images. Since this is the first time logging into Registry, no images will be shown. + ![](images/compartment-ocid-ask.png) - ``` - docker images - ``` -## **STEP 5**: Install GraalVM in Cloud Shell + To use an existing compartment, you must enter the OCID of the compartment yourself. To find the OCID of an existing compartment, click on the Navigation Menu of the cloud console, navigate to **Identity & Security** and click on **Compartments** - We will be using JDK 11 in Cloud Shell to build the Java/Helidon image -1. Set some environment variables and run the following commands + ![](images/compartment-navigate.png) + Click the appropriate compartment and copy the OCID - ``` - export MTDRWORKSHOP_LOCATION=~/mtdrworkshop - ``` - ``` - export WORKINGDIR=$MTDRWORKSHOP_LOCATION/workingdir - ``` - - Make sure to be in mtdrwokshop/setup-dev-environment directory then execute the following script - ``` - ./installGraalVM.sh - ``` + ![](images/compartment-ocid.png) -## **STEP 6**: Access OKE from the Cloud Shell -1. Create the mtdrworkshop/workingdir/mtdrworkshopclusterid.txt file +6. Next the setup will create an authentication token for your tenancy so that docker can log in to the Oracle Cloud Infrastructure Registry. If there is no space for a new Auth Token, the setup will ask you to remove an auth token then hit enter when you are ready. - ``` - touch mtdrworkshop/workingdir/mtdrworkshopclusterid.txt - ``` -2. Navigate to **Developer Services > Kubernetes Clusters** + ![](images/navigate-user-ocid.png) -3. Copy the mdtrworkshopcluster id and paste into the newly created file - ![](images/mtdrworkshop-cluster-id.png " ") + Select Auth Tokens under resources + ![](images/auth-token.png) -3. Run `./verifyOKEAndCreateKubeConfig.sh` + Delete one auth token if you have too many - ``` - ./verifyOKEAndCreateKubeConfig.sh - ``` + ![](images/delete-auth-token.png) - Notice `/.kube/config` is created for the OKE cluster. +7. The setup will ask you to enter the admin password for the database. Database passwords must be 12 to 30 characters and contain at least one uppercase leter, one lowercase leter, and one number. The password cannot contain the double quote (") character or the word "admin". - ![](images/verifyOKEOutput.png " ") +![](images/db-password-prompt.png) + -## **STEP 7**: Configuring Network Security Rules +## Task 6: Monitor the Setup +The setup should take around 20 minutes to complete. During the setup, the cloud shell will output its progress so keep an eye on it to see exactly what it's doing. If there are any errors, you should check the logs located in the $MTDRWORKSHOP-LOG directory. -1. The network security rules control the inbound (Ingres) and the outbound (Egress) traffic. As we will be configuring the API Gateway in Part II, we will not set tight security rules at the Kubernetes cluster level. +1. The setup will update you with the progress of the resource creation. Wait for the setup to complete to move on to the next lab -2. Navigate to **Developer Services > Kubernetes Clusters** - - Click on the **mtdrworkshopcluster**. + ![](images/resource-creation-update.png) -3. Click on VCN Name +You can also monitor the setup using the following command: - ![](images/VCN-name.png " ") -4. Click on the VCN named starting with oke-svclbsubnet-quick-mtdrworkshpcluster - ![](images/oke-svclbsubnet.png " ") +``` + +ps -ef + +``` -5. Click on the existing security list - ![](images/Add-security-lists.png " ") +## Task 7: Complete the Setup -6. Add an Ingress Rule - Set the Destination CIDR as indicated (leave other fields as is) then Click `Add Ingress Rules` +When the setup is done running, you will see a message : **SETUP VERIFIED** - ![](images/Ingress-rule.png " ") +You can view the log files in the $MTDRWORKSHOP_LOG directory. The command below will show you all the log files. You can view the contents of the files if you'd like. -7. Add an Egress Rule - Set Stateless and Destination CIDR as indicated in the image (leave other fields as-is) then Click `Add Egress Rules` +``` + +ls -al $MTDRWORKSHOP_LOG + +``` - ![](images/Egress-rule.png " ") -Congratulations, you have completed lab 1; you may now [proceed to the next lab](#next). +You may now **proceed to the next lab**. ## Acknowledgements -* **Author** - - Kuassi Mensah, Dir. Product Management, Java Database Access -* **Contributors** - Jean de Lavarene, Sr. Director of Development, JDBC/UCP -* **Last Updated By/Date** - Kuassi Mensah, Database Product Management, April 2021 +* **Authors** - - Kuassi Mensah, Dir. Product Management, Java Database Access; Peter Song, Developer Advocate JDBC +* **Contributors** - Jean de Lavarene, Sr. Director of Development JDBC/UCP +* **Last Updated By/Date** - Peter Song, Developer Advocate, Feb 2022 diff --git a/mtdrworkshop/setup.sh b/mtdrworkshop/setup.sh new file mode 100755 index 0000000..b8fbe41 --- /dev/null +++ b/mtdrworkshop/setup.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# Copyright (c) 2021 Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + + +#Make sure this is run via source or . +if ! (return 0 2>/dev/null); then + echo "ERROR: Usage 'source setup.sh'" + exit +fi + +if state_done SETUP; then + echo "The setup has been completed" + return +fi + +SETUP_SCRIPT="$MTDRWORKSHOP_LOCATION/utils/main-setup.sh" +if ps -ef | grep "$SETUP_SCRIPT" | grep -v grep; then + echo "The $SETUP_SCRIPT is already running. If you want to restart it then kill it and then rerun." +else + $SETUP_SCRIPT 2>&1 | tee -ai $MTDRWORKSHOP_LOG/main-setup.log +fi \ No newline at end of file diff --git a/mtdrworkshop/teardown/images/delete-bucket.png b/mtdrworkshop/teardown/images/delete-bucket.png new file mode 100644 index 0000000..b97814a Binary files /dev/null and b/mtdrworkshop/teardown/images/delete-bucket.png differ diff --git a/mtdrworkshop/teardown/images/delete-deployment.png b/mtdrworkshop/teardown/images/delete-deployment.png new file mode 100644 index 0000000..42f743c Binary files /dev/null and b/mtdrworkshop/teardown/images/delete-deployment.png differ diff --git a/mtdrworkshop/teardown/teardown.md b/mtdrworkshop/teardown/teardown.md new file mode 100644 index 0000000..2939e10 --- /dev/null +++ b/mtdrworkshop/teardown/teardown.md @@ -0,0 +1,69 @@ +# Teardown workshop resources + +## Introduction +In this lab, we will tear down the resources created in your tenancy and the directory in the Oracle cloud shell + +Estimated time: 10 minutes + +### Objectives +- Delete object storage bucket created in Lab 3 +- Delete deployment created in Lab 3 +- Run destroy script +- edit ~/.bashrc +### Prerequisites +- Have successfully completed the earlier labs + + +## Task 1: Delete Workshop Resources +The resources in this task weren't created during the setup script, so we must delete them manually before running the destroy script. + +1. Since the mtdrworkshop bucket created in Lab 3 wasn't created by the setup script, the destroy script does not know of it and we need to delete it ourselves + + ![](images/delete-bucket.png) + +2. We can't run the destroy script when there's a deployment in the api gateway. Navigate to Gateway, click on the deployment and click delete. + + ![](images/delete-deployment.png) + +## Task 2: Run the Destroy Script + +1. Run the following command to delete the resources created in your tenancy. It will delete everything except the compartment, and may take several minutes to run. + +``` + +cd $MTDRWORKSHOP_LOCATION +source destroy.sh + +``` +## Task 3: Delete the Directory + +1. Once the destroy script is completed, delete the directory in your cloud shell where you installed the workshop + +``` + +cd $HOME +rm -rf + +``` + +## Task 4: Edit ~/.bashrc + +1. We need to remove the line we added to ~/.bashrc in Lab 1. Run the following command to remove +``` + +vi ~/.bashrc + +``` +2. Once you're inside ~/.bashrc, delete this line + + ```echo source $(pwd)/env.sh >> ~/.bashrc``` + +## Task 5: Delete the Compartment + +1. In the Oracle Cloud Console, navigate to the **compartments** screen in the **Identity** section. Select the compartment that was created for the workshop (if you didn't provide one) and delete it + +## Acknowledgements + +* **Authors** - Kuassi Mensah, Dir. Product Management, Java Database Access; Peter Song, Developer Advocate JDBC +* **Original Authors** - Richard Exley, Consulting Member of Technical Staff, Oracle MAA and Exadata; Peter Song, Developer Advocate, JDBC; +* **Last Updated By/Date** - Peter Song, Developer Advocate JDBC diff --git a/mtdrworkshop/terraform/apigateway.tf b/mtdrworkshop/terraform/apigateway.tf new file mode 100644 index 0000000..38956ad --- /dev/null +++ b/mtdrworkshop/terraform/apigateway.tf @@ -0,0 +1,7 @@ +resource "oci_apigateway_gateway" "todolist"{ + #required + compartment_id = var.ociCompartmentOcid + endpoint_type = "PUBLIC" + subnet_id = oci_core_subnet.svclb_Subnet.id + display_name = "todolist" +} \ No newline at end of file diff --git a/mtdrworkshop/terraform/availability_domain.tf b/mtdrworkshop/terraform/availability_domain.tf new file mode 100644 index 0000000..6c6ca7b --- /dev/null +++ b/mtdrworkshop/terraform/availability_domain.tf @@ -0,0 +1,4 @@ +data "oci_identity_availability_domain" "ad1"{ + compartment_id = var.ociTenancyOcid + ad_number = 1 +} \ No newline at end of file diff --git a/mtdrworkshop/terraform/containerengine.tf b/mtdrworkshop/terraform/containerengine.tf new file mode 100644 index 0000000..741b8b0 --- /dev/null +++ b/mtdrworkshop/terraform/containerengine.tf @@ -0,0 +1,83 @@ +resource "oci_containerengine_cluster" "mtdrworkshop_cluster" { + #Required + compartment_id = var.ociCompartmentOcid + endpoint_config { + #optional + is_public_ip_enabled = "true" + nsg_ids = [ + ] + subnet_id = oci_core_subnet.endpoint.id + } + kubernetes_version = "v1.20.8" + name = "mtdrworkshopcluster" + vcn_id = oci_core_vcn.okevcn.id + #optional + + options{ + service_lb_subnet_ids = [oci_core_subnet.svclb_Subnet.id] + + add_ons { + #Optional + is_kubernetes_dashboard_enabled = "false" + is_tiller_enabled = "false" + } + admission_controller_options { + #Optional + is_pod_security_policy_enabled = "false" + } + kubernetes_network_config{ + #Optional + pods_cidr = "10.244.0.0/16" + services_cidr = "10.96.0.0/16" + } + } +} +resource "oci_containerengine_node_pool" "oke_node_pool" { + #Required + cluster_id = oci_containerengine_cluster.mtdrworkshop_cluster.id + compartment_id = var.ociCompartmentOcid + kubernetes_version = "v1.20.8" + name = "Pool" +# node_shape="VM.Standard2.4" +# node_shape = "VM.Standard.B2.1" + node_shape = "VM.Standard.E2.1" +# node_shape = "VM.Standard2.2" + #subnet_ids = [oci_core_subnet.nodePool_Subnet_1.id] + #Optional + node_config_details { + placement_configs { + availability_domain = data.oci_identity_availability_domain.ad1.name + subnet_id = oci_core_subnet.nodePool_Subnet.id + } +/* placement_configs { + availability_domain = data.oci_identity_availability_domain.ad2.name + subnet_id = oci_core_subnet.nodePool_Subnet.id + } + placement_configs { + availability_domain = data.oci_identity_availability_domain.ad3.name + subnet_id = oci_core_subnet.nodePool_Subnet.id + } +*/ + size = "3" + } + node_source_details { + #Required + image_id = local.oracle_linux_images.0 # Latest + source_type = "IMAGE" + #Optional + #boot_volume_size_in_gbs = "60" + } + //quantity_per_subnet = 1 + //ssh_public_key = var.node_pool_ssh_public_key + //ssh_public_key = var.resUserPublicKey +} +data "oci_containerengine_cluster_option" "mtdrworkshop_cluster_option" { + cluster_option_id = "all" +} +data "oci_containerengine_node_pool_option" "mtdrworkshop_node_pool_option" { + node_pool_option_id = "all" +} +locals { + all_sources = data.oci_containerengine_node_pool_option.mtdrworkshop_node_pool_option.sources + oracle_linux_images = [for source in local.all_sources : source.image_id if length(regexall("Oracle-Linux-[0-9]*.[0-9]*-20[0-9]*",source.source_name)) > 0] +} \ No newline at end of file diff --git a/mtdrworkshop/terraform/core.tf b/mtdrworkshop/terraform/core.tf new file mode 100644 index 0000000..f6753b7 --- /dev/null +++ b/mtdrworkshop/terraform/core.tf @@ -0,0 +1,423 @@ +#networking resources for OKE +resource "oci_core_vcn" "okevcn" { + cidr_block = "10.0.0.0/16" + compartment_id = var.ociCompartmentOcid + display_name = "mtdrworkshop" + dns_label = "mtdrworkshop" +} +resource "oci_core_internet_gateway" "igw" { + compartment_id = var.ociCompartmentOcid + display_name = "ClusterInternetGateway" + vcn_id = oci_core_vcn.okevcn.id +} + +resource "oci_core_nat_gateway" "ngw" { + #Required + compartment_id = var.ociCompartmentOcid + vcn_id = oci_core_vcn.okevcn.id + #optional + block_traffic = "false" + freeform_tags = { + + } + display_name = "ngw" +} +resource "oci_core_service_gateway" "sgw" { + #required + compartment_id = var.ociCompartmentOcid + services { + service_id = data.oci_core_services.services.services.0.id + } + vcn_id = oci_core_vcn.okevcn.id + #optional + display_name = "mtdr_sgw" +} + +resource "oci_core_route_table" "private" { + #required + compartment_id = var.ociCompartmentOcid + vcn_id = oci_core_vcn.okevcn.id + #optional + display_name = "private" + route_rules { + #required + network_entity_id = oci_core_nat_gateway.ngw.id + #optional + description = "Traffic to the internet" + destination = "0.0.0.0/0" + destination_type = "CIDR_BLOCK" + } + route_rules { + #required + network_entity_id = oci_core_service_gateway.sgw.id + #optional + description = "Traffic to OCI Services" + destination = data.oci_core_services.services.services.0.cidr_block + destination_type = "SERVICE_CIDR_BLOCK" + } +} +## default route table +resource "oci_core_default_route_table" "public" { + display_name = "public" + freeform_tags = { + } + manage_default_resource_id = oci_core_vcn.okevcn.default_route_table_id + route_rules { + description = "traffic to/from internet" + destination = "0.0.0.0/0" + destination_type = "CIDR_BLOCK" + network_entity_id = oci_core_internet_gateway.igw.id + } +} +# resource "oci_core_route_table" "public"{ +# #required +# compartment_id = var.ociCompartmentOcid +# vcn_id = oci_core_vcn.okevcn.id +# #optional +# display_name = "public" +# route_rules { +# #required +# network_entity_id = oci_core_service_gateway.igw.id +# #optional +# description = "Traffic to/from internet" +# destination = "0.0.0.0/0" +# destination_type = "CIDR_BLOCK" +# } +# } + +resource "oci_core_subnet" "endpoint" { + #required + cidr_block = "10.0.0.0/28" + compartment_id = var.ociCompartmentOcid + vcn_id = oci_core_vcn.okevcn.id + #optional + security_list_ids = [oci_core_security_list.endpoint.id] + display_name = "subnet1ForNodePool" + prohibit_public_ip_on_vnic = "false" + route_table_id = oci_core_vcn.okevcn.default_route_table_id + dns_label = "endpoint" +} +#ApiEndpoint security list +resource "oci_core_security_list" "endpoint" { + #required + compartment_id = var.ociCompartmentOcid + vcn_id = oci_core_vcn.okevcn.id + #Optional + display_name = "endpoint" + egress_security_rules { + #Required + destination = data.oci_core_services.services.services.0.cidr_block + protocol = "6" #TCP + #optional + destination_type = "SERVICE_CIDR_BLOCK" + description = "Allow Kubernetes Control Plane to communicate with OKE" + stateless = "false" + tcp_options { + max = "443" + min = "443" + } + } + egress_security_rules { + #required + destination = "10.0.10.0/24" + protocol = "6" #TCP + #optional + destination_type = "CIDR_BLOCK" + description = "All traffic to worker nodes" + stateless = "false" + } + egress_security_rules { + #required + destination = "10.0.10.0/24" + protocol = "1" #ICMP + #optional + destination_type = "CIDR_BLOCK" + description = "Path Discovery" + icmp_options { + type = "3" + code = "4" + } + stateless = "false" + } + ingress_security_rules { + #required + source = "0.0.0.0/0" + protocol = "6" #TCP + #optional + source_type = "CIDR_BLOCK" + stateless = "false" + description = "External access to Kubernetes API Endpoint" + tcp_options { + max = "6443" + min = "6443" + } + + } + ingress_security_rules { + #required + source = "10.0.10.0/24" + protocol = "6" + #optional + source_type = "CIDR_BLOCK" + stateless = "false" + description = "Kubernetes worker to Kubernetes API endpoint communication" + tcp_options{ + max = "6443" + min = "6443" + } + } + ingress_security_rules { + #required + source = "10.0.10.0/24" + protocol = "6" + #optional + source_type = "CIDR_BLOCK" + stateless = "false" + description = "Kubernetes woker to control plane communication" + tcp_options { + max = "12250" + min = "12250" + } + } + ingress_security_rules { + #required + source = "10.0.10.0/24" + protocol = "1" #ICMP + #optional + source_type = "CIDR_BLOCK" + stateless = "false" + description = "Path Discovery" + icmp_options { + type = "3" + code = "4" + } + } +} +resource "oci_core_subnet" "nodePool_Subnet" { + #Required + #availability_domain = data.oci_identity_availability_domain.ad1.name + cidr_block = "10.0.10.0/24" + compartment_id = var.ociCompartmentOcid + vcn_id = oci_core_vcn.okevcn.id + # Provider code tries to maintain compatibility with old versions. + security_list_ids = [oci_core_security_list.nodePool.id] + display_name = "SubNet1ForNodePool" + prohibit_public_ip_on_vnic = "true" + route_table_id = oci_core_route_table.private.id + dns_label = "nodepool" +} +#nodepool security list +resource "oci_core_security_list" "nodePool" { + #required + compartment_id = var.ociCompartmentOcid + vcn_id = oci_core_vcn.okevcn.id + #Optional + display_name = "nodepool" + egress_security_rules { + #Required + destination = "10.0.10.0/24" + protocol = "all" + #optional + destination_type = "CIDR_BLOCK" + description = "Allow pods on one worker node to communicate with pods on other worker nodes" + stateless = "false" + } + egress_security_rules { + #required + destination = "10.0.0.0/28" + protocol = "6" #TCP + #optional + destination_type = "CIDR_BLOCK" + description = "Access to Kubernetes API endpoint" + tcp_options { + min = "6443" + max = "6443" + } + stateless = "false" + } + egress_security_rules { + #required + destination = "10.0.0.0/28" + protocol = "6" #TCP + #optional + destination_type = "CIDR_BLOCK" + description = "Kubernetes worker to control plane communication" + tcp_options { + max = "12250" + min = "12250" + } + stateless = "false" + } + egress_security_rules { + #Required + destination = "10.0.0.0/28" + protocol = "1" #ICMP + #optional + destination_type = "CIDR_BLOCK" + description = "Path Discovery" + icmp_options { + type = "3" + code = "4" + } + stateless = "false" + } + egress_security_rules { + #required + destination = data.oci_core_services.services.services.0.cidr_block + protocol = "6" #TCP + #optional + destination_type = "SERVICE_CIDR_BLOCK" + description = "Allow nodes to communicate with OKE to ensure correct start-up and continued functioning" + tcp_options { + max = "443" + min = "443" + } + stateless = "false" + } + egress_security_rules { + #required + destination = "0.0.0.0/0" + protocol = "1" #ICMP + #optional + destination_type = "CIDR_BLOCK" + description = "ICMP Access from Kubernetes Control Plane" + icmp_options { + type = "3" + code = "4" + } + stateless = "false" + } + egress_security_rules { + #required + destination = "0.0.0.0/0" + protocol = "all" #ICMP + #optional + destination_type = "CIDR_BLOCK" + description = "Worker Nodes access to Internet" + stateless = "false" + } + ingress_security_rules { + #required + source = "0.0.0.0/0" + protocol = "6" #TCP + #optional + source_type = "CIDR_BLOCK" + stateless = "false" + description = "External access to Kubernetes API Endpoint" + tcp_options { + max = "6443" + min = "6443" + } + + } + ingress_security_rules { + #required + source = "10.0.10.0/24" + protocol = "all" + #optional + source_type = "CIDR_BLOCK" + stateless = "false" + description = "Allow pods on one worker node to communicate with pods on other worker nodes" + } + ingress_security_rules { + #required + source = "10.0.0.0/28" + protocol = "1"#ICMP + #optional + source_type = "CIDR_BLOCK" + stateless = "false" + description = "Path Discovery" + icmp_options { + type = "3" + code = "4" + } + } + ingress_security_rules { + #required + source = "10.0.0.0/28" + protocol = "6" #TCP + #optional + source_type = "CIDR_BLOCK" + stateless = "false" + description = "TCP access from Kubernetes Control Plane" + } + ingress_security_rules { + #required + source = "0.0.0.0/0" + protocol = "6" #TCP + #optional + source_type = "CIDR_BLOCK" + stateless = "false" + description = "Inbound SSH traffic to worker nodes" + tcp_options { + max = "22" + min = "22" + } + } +} +# resource "oci_core_subnet" "svclb_Subnet" { +# #Required +# #availability_domain = data.oci_identity_availability_domain.ad1.name +# cidr_block = "10.0.20.0/24" +# compartment_id = var.ociCompartmentOcid +# vcn_id = oci_core_vcn.okevcn.id +# # Provider code tries to maintain compatibility with old versions. +# security_list_ids = [oci_core_default_security_list.svcLB.id] +# display_name = "SubNet1ForSvcLB" +# route_table_id = oci_core_vcn.okevcn.default_route_table_id +# dhcp_options_id = oci_core_vcn.okevcn.default_dhcp_options_id +# prohibit_public_ip_on_vnic = "false" +# dns_label = "svclb" +# } + +resource "oci_core_security_list" "svclb_sl" { + #required + compartment_id = var.ociCompartmentOcid + vcn_id = oci_core_vcn.okevcn.id + #Optional + display_name = "scvlb" + egress_security_rules { + #Required + destination = "0.0.0.0/0" + protocol = "6" #TCP + #optional + destination_type = "CIDR_BLOCK" + stateless = "false" + } + ingress_security_rules { + #required + source = "0.0.0.0/0" + protocol = "6" #TCP + #optional + source_type = "CIDR_BLOCK" + stateless = "false" + } +} +resource "oci_core_subnet" "svclb_Subnet" { + #Required + #availability_domain = data.oci_identity_availability_domain.ad1.name + cidr_block = "10.0.20.0/24" + compartment_id = var.ociCompartmentOcid + vcn_id = oci_core_vcn.okevcn.id + display_name = "Subnet1 for svclb" + # Provider code tries to maintain compatibility with old versions. + security_list_ids = [oci_core_security_list.svclb_sl.id] + route_table_id = oci_core_vcn.okevcn.default_route_table_id + dhcp_options_id = oci_core_vcn.okevcn.default_dhcp_options_id + prohibit_public_ip_on_vnic = "false" + dns_label = "svclb" +} + + +#default security list for svcLB +# resource oci_core_default_security_list svcLB { +# display_name = "svcLB" +# manage_default_resource_id = oci_core_vcn.okevcn.default_security_list_id +# } +data "oci_core_services" "services" { + filter { + name = "name" + values = ["All .* Services In Oracle Services Network"] + regex = true + } +} \ No newline at end of file diff --git a/mtdrworkshop/terraform/database.tf b/mtdrworkshop/terraform/database.tf new file mode 100644 index 0000000..eb279c1 --- /dev/null +++ b/mtdrworkshop/terraform/database.tf @@ -0,0 +1,53 @@ +//================= create ATP Instance ======================================= +variable "autonomous_database_db_workload" { default = "OLTP" } +variable "autonomous_database_defined_tags_value" { default = "value" } +variable "autonomous_database_license_model" { default = "BRING_YOUR_OWN_LICENSE" } +variable "autonomous_database_is_dedicated" { default = false } +resource "random_string" "autonomous_database_wallet_password" { + length = 16 + special = true +} +resource "random_password" "database_admin_password" { + length = 12 + upper = true + lower = true + number = true + special = false + min_lower = "1" + min_upper = "1" + min_numeric = "1" +} +resource "oci_database_autonomous_database" "autonomous_database_atp" { + #Required + admin_password = random_password.database_admin_password.result + compartment_id = var.ociCompartmentOcid + cpu_core_count = "1" + data_storage_size_in_tbs = "1" + db_name = var.mtdrDbName + # is_free_tier = true , if there exists sufficient service limit + is_free_tier = false + #Optional #db_workload = "${var.autonomous_database_db_workload}" + db_workload = var.autonomous_database_db_workload + display_name ="MTDRDB" + is_auto_scaling_enabled = "false" + is_preview_version_with_service_terms_accepted = "false" +} +data "oci_database_autonomous_databases" "autonomous_databases_atp" { + #Required + compartment_id = var.ociCompartmentOcid + #Optional + display_name = "MTDRDB" + db_workload = var.autonomous_database_db_workload +} +//======= Name space details ------------------------------------------------------ +data "oci_objectstorage_namespace" "test_namespace" { + #Optional + compartment_id = var.ociCompartmentOcid +} +//========= Outputs =========================== +output "ns_objectstorage_namespace" { + value = [ data.oci_objectstorage_namespace.test_namespace.namespace ] +} +output "autonomous_database_admin_password" { + value = [ "Welcome12345" ] +} \ No newline at end of file diff --git a/mtdrworkshop/terraform/main-var.tf b/mtdrworkshop/terraform/main-var.tf new file mode 100644 index 0000000..b3a3121 --- /dev/null +++ b/mtdrworkshop/terraform/main-var.tf @@ -0,0 +1,8 @@ +//Copyright (c) 2021 Oracle and/or its affiliates. +//Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. +variable "ociTenancyOcid" {} +variable "ociUserOcid" {} +variable "ociCompartmentOcid" {} +variable "ociRegionIdentifier" {} +variable "mtdrDbName" {} +variable "runName" {} \ No newline at end of file diff --git a/mtdrworkshop/terraform/provider.tf b/mtdrworkshop/terraform/provider.tf new file mode 100644 index 0000000..762d2a7 --- /dev/null +++ b/mtdrworkshop/terraform/provider.tf @@ -0,0 +1,11 @@ +terraform { + required_providers{ + oci = { + source = "hashicorp/oci" + version = "4.42.0" + } + } +} +provider "oci"{ + region = var.ociRegionIdentifier +} \ No newline at end of file diff --git a/mtdrworkshop/utils/db-setup.sh b/mtdrworkshop/utils/db-setup.sh new file mode 100755 index 0000000..9d04ec3 --- /dev/null +++ b/mtdrworkshop/utils/db-setup.sh @@ -0,0 +1,149 @@ +#!/bin/bash +# Copyright (c) 2021 Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +# Fail on error +set -e + + +# Create Object Store Bucket (Should be replaced by terraform one day) +while ! state_done OBJECT_STORE_BUCKET; do + echo "creating object storage bucket" + oci os bucket create --compartment-id "$(state_get COMPARTMENT_OCID)" --name "$(state_get RUN_NAME)" + state_set_done OBJECT_STORE_BUCKET + echo "finished creating object storage buckets" +done + + +# Wait for Order DB OCID +while ! state_done MTDR_DB_OCID; do + echo "`date`: Waiting for MTDR_DB_OCID" + sleep 2 +done + + +# Get Wallet +while ! state_done WALLET_GET; do + echo "creating wallet" + cd $MTDRWORKSHOP_LOCATION + mkdir wallet + cd wallet + oci db autonomous-database generate-wallet --autonomous-database-id "$(state_get MTDR_DB_OCID)" --file 'wallet.zip' --password 'Welcome1' --generate-type 'ALL' + unzip wallet.zip + cd $MTDRWORKSHOP_LOCATION + state_set_done WALLET_GET + echo "finished creating wallet" +done + + +# Get DB Connection Wallet and to Object Store +while ! state_done CWALLET_SSO_OBJECT; do + echo "grabbing wallet" + cd $MTDRWORKSHOP_LOCATION/wallet + oci os object put --bucket-name "$(state_get RUN_NAME)" --name "cwallet.sso" --file 'cwallet.sso' + cd $MTDRWORKSHOP_LOCATION + state_set_done CWALLET_SSO_OBJECT + echo "done grabbing wallet" +done + + +# Create Authenticated Link to Wallet +while ! state_done CWALLET_SSO_AUTH_URL; do + echo "creating authenticated link to wallet" + ACCESS_URI=`oci os preauth-request create --object-name 'cwallet.sso' --access-type 'ObjectRead' --bucket-name "$(state_get RUN_NAME)" --name 'mtdrworkshop' --time-expires $(date '+%Y-%m-%d' --date '+7 days') --query 'data."access-uri"' --raw-output` + state_set CWALLET_SSO_AUTH_URL "https://objectstorage.$(state_get REGION).oraclecloud.com${ACCESS_URI}" + echo "done creating authenticated link to wallet" +done + + +# Give DB_PASSWORD priority +while ! state_done DB_PASSWORD; do + echo "Waiting for DB_PASSWORD" + sleep 5 +done + + +# Create Inventory ATP Bindings +while ! state_done DB_WALLET_SECRET; do + echo "creating Inventory ATP Bindings" + cd $MTDRWORKSHOP_LOCATION/wallet + cat - >sqlnet.ora <$TNS_ADMIN/sqlnet.ora <> $MTDRWORKSHOP_LOG/build-backend.log +# done +# state_set_done JAVA_BUILDS +# done + +# while ! state_done JAVA_DEPLOY; do +# echo "pushing images" +# for b in $BUILDS; do +# cd $MTDRWORKSHOP_LOCATION/backend +# time ./deploy.sh &>> $MTDRWORKSHOP_LOG/deploy-backend.log +# done +# state_set_done JAVA_DEPLOY +# done \ No newline at end of file diff --git a/mtdrworkshop/utils/kube_token_cache.sh b/mtdrworkshop/utils/kube_token_cache.sh new file mode 100755 index 0000000..922f1e6 --- /dev/null +++ b/mtdrworkshop/utils/kube_token_cache.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# Copyright (c) 2021 Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +TOKEN_FILE=~/.kube/TOKEN + +if ! test -f "$TOKEN_FILE" || test $(( `date +%s` - `stat -L --format %Y $TOKEN_FILE` )) -gt 240; then + umask 177 + oci ce cluster generate-token --cluster-id "$5" --region "$7" >$TOKEN_FILE +fi + +cat $TOKEN_FILE \ No newline at end of file diff --git a/mtdrworkshop/utils/lb-destroy.sh b/mtdrworkshop/utils/lb-destroy.sh new file mode 100755 index 0000000..09fe142 --- /dev/null +++ b/mtdrworkshop/utils/lb-destroy.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Copyright (c) 2021 Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +# Fail on error +set -e + + +# Delete LBs +echo "Deleting Load Balancers" +LBIDS=`oci lb load-balancer list --compartment-id "$(state_get COMPARTMENT_OCID)" --query "join(' ',data[*].id)" --raw-output` +for lb in $LBIDS; do + oci lb load-balancer delete --load-balancer-id "$lb" --force +done \ No newline at end of file diff --git a/mtdrworkshop/utils/logallpods b/mtdrworkshop/utils/logallpods deleted file mode 100644 index 348a2c8..0000000 --- a/mtdrworkshop/utils/logallpods +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -## MyToDoReact version 1.0. -## -## Copyright (c) 2021 Oracle, Inc. -## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ -export app=$1 -kubectl logs -f -l app=$app -n mtdrworkshop diff --git a/mtdrworkshop/utils/logpod b/mtdrworkshop/utils/logpod deleted file mode 100644 index 20bf7a9..0000000 --- a/mtdrworkshop/utils/logpod +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -## MyToDoReact version 1.0. -## -## Copyright (c) 2021 Oracle, Inc. -## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ -export k8s_pod=$1 -for line in $(kubectl get pods --all-namespaces | \ - grep $k8s_pod | awk '{print $2}'); do - echo "kubectl logs -f $line -n mtdrworkshop" - kubectl logs -f $line -n mtdrworkshop -done diff --git a/mtdrworkshop/utils/logpodistio b/mtdrworkshop/utils/logpodistio deleted file mode 100644 index 9304857..0000000 --- a/mtdrworkshop/utils/logpodistio +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -## MyToDoReact version 1.0. -## -## Copyright (c) 2021 Oracle, Inc. -## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ -export k8s_pod=$1 -# export k8s_container=$2 -for line in $(kubectl get pods --all-namespaces | \ - grep $k8s_pod | awk '{print $2}'); do - echo "kubectl logs -f $line -n mtdrworkshop $k8s_pod" - kubectl logs -f $line -n mtdrworkshop $k8s_pod -done diff --git a/mtdrworkshop/utils/main-destroy.sh b/mtdrworkshop/utils/main-destroy.sh new file mode 100755 index 0000000..efbe1c0 --- /dev/null +++ b/mtdrworkshop/utils/main-destroy.sh @@ -0,0 +1,67 @@ +#!/bin/bash +# Copyright (c) 2021 Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +# Fail on error +set -e + + +# Switch to SSH Key auth for the oci cli (workaround to perm issue awaiting fix) +# source $MTDRWORKSHOP_LOCATION/utils/oci-cli-cs-key-auth.sh + + +# Remove from .bashrc +#sed -i.bak '/grabdish/d' ~/.bashrc + + +# No destroy necessary for Live Labs +if test "$(state_get RUN_TYPE)" == "3"; then + echo "No teardown required for Live Labs" + exit +fi + + +# Run the os-destroy.sh in the background +if ps -ef | grep "$MTDRWORKSHOP_LOCATION/utils/os-destroy.sh" | grep -v grep; then + echo "$MTDRWORKSHOP_LOCATION/utils/os-destroy.sh is already running" +else + echo "Executing os-destroy.sh in the background" + nohup $MTDRWORKSHOP_LOCATION/utils/os-destroy.sh &>> $MTDRWORKSHOP_LOG/os-destroy.log & +fi + + +# Run the repo-destroy.sh in the background +if ps -ef | grep "$MTDRWORKSHOP_LOCATION/utils/repo-destroy.sh" | grep -v grep; then + echo "$MTDRWORKSHOP_LOCATION/utils/repo-destroy.sh is already running" +else + echo "Executing repo-destroy.sh in the background" + nohup $MTDRWORKSHOP_LOCATION/utils/repo-destroy.sh &>> $MTDRWORKSHOP_LOG/repo-destroy.log & +fi + + +# Run the lb-destroy.sh in the background +if ps -ef | grep "$MTDRWORKSHOP_LOCATION/utils/lb-destroy.sh" | grep -v grep; then + echo "$MTDRWORKSHOP_LOCATION/utils/lb-destroy.sh is already running" +else + echo "Executing lb-destroy.sh in the background" + nohup $MTDRWORKSHOP_LOCATION/utils/lb-destroy.sh &>> $MTDRWORKSHOP_LOG/lb-destroy.log & +fi + + +# Terraform Destroy +echo "Running terraform destroy" +cd $MTDRWORKSHOP_LOCATION/terraform +export TF_VAR_ociTenancyOcid="$(state_get TENANCY_OCID)" +export TF_VAR_ociUserOcid="$(state_get USER_OCID)" +export TF_VAR_ociCompartmentOcid="$(state_get COMPARTMENT_OCID)" +export TF_VAR_ociRegionIdentifier="$(state_get REGION)" +export TF_VAR_runName="$(state_get RUN_NAME)" +export TF_VAR_mtdrDbName="$(state_get MTDR_DB_NAME)" +terraform init +terraform destroy -auto-approve + + +# If BYO K8s then delete the mtdrworkshop namespace in k8s +if state_done BYO_K8S; then + kubectl delete ns mtdrworkshop +fi diff --git a/mtdrworkshop/utils/main-setup.sh b/mtdrworkshop/utils/main-setup.sh new file mode 100755 index 0000000..76b8f1d --- /dev/null +++ b/mtdrworkshop/utils/main-setup.sh @@ -0,0 +1,342 @@ +#!/bin/bash +# Copyright (c) 2021 Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +# Fail on error +set -e + +#Check if home is set +if test -z "$MTDRWORKSHOP_LOCATION"; then + echo "ERROR: this script requires MTDRWORKSHOP_LOCATION to be set" + exit +fi + +#Exit if we are already done +if state_done SETUP_VERIFIED; then + echo "SETUP_VERIFIED completed" + exit +fi + +#Identify Run Type +while ! state_done RUN_TYPE; do + if [[ "$HOME" =~ /home/ll[0-9]{1,5}_us ]]; then + echo "We are in green button" + # Green Button (hosted by Live Labs) + state_set RUN_TYPE "3" + state_set RESERVATION_ID `grep -oP '(?<=/home/ll).*?(?=_us)' <<<"$HOME"` + state_set USER_OCID 'NA' #"$OCI_CS_USER_OCID" + state_set USER_NAME "LL$(state_get RESERVATION_ID)-USER" + state_set_done PROVISIONING + state_set_done K8S_PROVISIONING + state_set RUN_NAME "mtdrworkshop$(state_get RESERVATION_ID)" + state_set MTDR_DB_NAME "MTDRDB$(state_get RESERVATION_ID)" + #state_set_done OKE_LIMIT_CHECK + #state_set_done ATP_LIMIT_CHECK + else + state_set RUN_TYPE "1" + # BYO K8s + if test ${BYO_K8S:-UNSET} != 'UNSET'; then + state_set_done BYO_K8S + state_set_done K8S_PROVISIONING + state_set OKE_OCID 'NA' + state_set_done KUBECTL + state_set_done OKE_LIMIT_CHECK + fi + fi +done + + +# Get the User OCID +while ! state_done USER_OCID; do + if test -z "$TEST_USER_OCID"; then + read -p "Please enter your OCI user's OCID: " USER_OCID + else #this gets used in the terraform file + USER_OCID=$TEST_USER_OCID + fi + # Validate + if test ""`oci iam user get --user-id "$OCI_CS_USER_OCID" --query 'data."lifecycle-state"' --raw-output 2>$MTDRWORKSHOP_LOG/user_ocid_err` == 'ACTIVE'; then + state_set USER_OCID "$OCI_CS_USER_OCID" + else + echo "That user OCID could not be validated" + cat $MTDRWORKSHOP_LOG/user_ocid_err + fi +done + +while ! state_done USER_NAME; do + USER_NAME=`oci iam user get --user-id "$(state_get USER_OCID)" --query "data.name" --raw-output` + state_set USER_NAME "$USER_NAME" +done + + +#Get Run Name from directory name +while ! state_done RUN_NAME; do + cd $MTDRWORKSHOP_LOCATION + cd ../.. + # Validate that a folder was creared + if test "$PWD" == ~; then + echo "ERROR: The workshop is not installed in a separate folder." + exit + fi + DN=`basename "$PWD"` + # Validate run name. Must be between 1 and 13 characters, only letters or numbers, starting with letter + if [[ "$DN" =~ ^[a-zA-Z][a-zA-Z0-9]{0,12}$ ]]; then + state_set RUN_NAME `echo "$DN" | awk '{print tolower($0)}'` + state_set MTDR_DB_NAME "$(state_get RUN_NAME)o" + else + echo "Error: Invalid directory name $RN. The directory name must be between 1 and 13 characters," + echo "containing only letters or numbers, starting with a letter. Please restart the workshop with a valid directory name." + exit + fi + cd $MTDRWORKSHOP_LOCATION +done + +# Get the tenancy OCID +while ! state_done TENANCY_OCID; do + state_set TENANCY_OCID "$OCI_TENANCY" # Set in cloud shell env, gets used in terraform script +done + +# Double check and then set the region +while ! state_done REGION; do + if test $(state_get RUN_TYPE) -eq 1; then + HOME_REGION=`oci iam region-subscription list --query 'data[?"is-home-region"]."region-name" | join('\'' '\'', @)' --raw-output` + state_set HOME_REGION "$HOME_REGION" + fi + state_set REGION "$OCI_REGION" # Set in cloud shell env +done + + +#create the compartment +##newest code added later +while ! state_done COMPARTMENT_OCID; do + if test $(state_get RUN_TYPE) -ne 3; then + read -p "if you have your own compartment, enter it here: if not, hit enter" COMPARTMENT_OCID + ##newest condition added + if test "$COMPARTMENT_OCID" != "" && test `oci iam compartment get --compartment-id "$COMPARTMENT_OCID" --query 'data."lifecycle-state"' --raw-output 2>/dev/null` == 'ACTIVE'; then + state_set COMPARTMENT_OCID "$COMPARTMENT_OCID" + else + echo "Resources will be created in a new compartment named $(state_get RUN_NAME)" + COMPARTMENT_OCID=`oci iam compartment create --compartment-id "$(state_get TENANCY_OCID)" --name "$(state_get RUN_NAME)" --description "mtdrworkshop" --query 'data.id' --raw-output` + fi + fi + while ! test `oci iam compartment get --compartment-id "$COMPARTMENT_OCID" --query 'data."lifecycle-state"' --raw-output 2>/dev/null`"" == 'ACTIVE'; do + echo "Waiting for the compartment to become ACTIVE" + sleep 2 + done + state_set COMPARTMENT_OCID "$COMPARTMENT_OCID" +done + +## Run the java-builds.sh in the background +if ! state_get JAVA_BUILDS; then + if ps -ef | grep "$MTDRWORKSHOP_LOCATION/utils/java-builds.sh" | grep -v grep; then + echo "$MTDRWORKSHOP_LOCATION/utils/java-builds.sh is already running" + else + echo "Executing java-builds.sh in the background" + nohup $MTDRWORKSHOP_LOCATION/utils/java-builds.sh &>> $MTDRWORKSHOP_LOG/java-builds.log & + fi +fi + + +## Run the terraform.sh in the background +if ! state_get PROVISIONING; then + if ps -ef | grep "$MTDRWORKSHOP_LOCATION/utils/terraform.sh" | grep -v grep; then + echo "$MTDRWORKSHOP_LOCATION/utils/terraform.sh is already running" + else + echo "Executing terraform.sh in the background" + nohup $MTDRWORKSHOP_LOCATION/utils/terraform.sh &>> $MTDRWORKSHOP_LOG/terraform.log & + fi +fi + +# Get Namespace +while ! state_done NAMESPACE; do + NAMESPACE=`oci os ns get --compartment-id "$(state_get COMPARTMENT_OCID)" --query "data" --raw-output` + state_set NAMESPACE "$NAMESPACE" +done + +# login to docker +while ! state_done DOCKER_REGISTRY; do + if test $(state_get RUN_TYPE) -ne 3; then + ##export OCI_CLI_PROFILE=$(state_get HOME_REGION) ## have to get rid of this for non instance_principal based stuff + if ! TOKEN=`oci iam auth-token create --user-id "$(state_get USER_OCID)" --description 'mtdr docker login' --query 'data.token' --raw-output 2>$MTDRWORKSHOP_LOG/docker_registry_err`; then + if grep UserCapacityExceeded $MTDRWORKSHOP_LOG/docker_registry_err >/dev/null; then + # The key already exists + echo 'ERROR: Failed to create auth token. Please delete an old token from the OCI Console (Profile -> User Settings -> Auth Tokens).' + read -p "Hit return when you are ready to retry?" + continue + else + echo "ERROR: Creating auth token had failed:" + cat $MTDRWORKSHOP_LOG/docker_registry_err + exit + fi + fi + else + read -s -r -p "Please generate an Auth Token and enter the value: " TOKEN + echo + echo "Auth Token entry accepted. Attempting docker login." + fi + + RETRIES=0 + while test $RETRIES -le 30; do + if echo "$TOKEN" | docker login -u "$(state_get NAMESPACE)/$(state_get USER_NAME)" --password-stdin "$(state_get REGION).ocir.io" &>/dev/null; then + echo "Docker login completed" + state_set DOCKER_REGISTRY "$(state_get REGION).ocir.io/$(state_get NAMESPACE)/$(state_get RUN_NAME)" + export OCI_CLI_PROFILE=$(state_get REGION) + break + else + # echo "Docker login failed. Retrying" + RETRIES=$((RETRIES+1)) + sleep 5 + fi + done +done +# run oke-setup.sh in background +if ! state_get OKE_SETUP; then + if ps -ef | grep "$MTDRWORKSHOP_LOCATION/utils/oke-setup.sh" | grep -v grep; then + echo "$MTDRWORKSHOP_LOCATION/utils/oke-setup.sh is already running" + else + echo "Executing oke-setup.sh in the background" + nohup $MTDRWORKSHOP_LOCATION/utils/oke-setup.sh &>>$MTDRWORKSHOP_LOG/oke-setup.log & + fi +fi + +# run db-setup.sh in background +if ! state_get DB_SETUP; then + if ps -ef | grep "$MTDRWORKSHOP_LOCATION/utils/db-setup.sh" | grep -v grep; then + echo "$MTDRWORKSHOP_LOCATION/utils/db-setup.sh is already running" + else + echo "Executing db-setup.sh in the background" + nohup $MTDRWORKSHOP_LOCATION/utils/db-setup.sh &>>$MTDRWORKSHOP_LOG/db-setup.log & + fi +fi + +# Collect DB password +if ! state_done DB_PASSWORD; then + echo + echo 'Database passwords must be 12 to 30 characters and contain at least one uppercase letter,' + echo 'one lowercase letter, and one number. The password cannot contain the double quote (")' + echo 'character or the word "admin".' + echo + + while true; do + if test -z "$TEST_DB_PASSWORD"; then + read -s -r -p "Enter the password to be used for the MTDR database: " PW + else + PW="$TEST_DB_PASSWORD" + fi + if [[ ${#PW} -ge 12 && ${#PW} -le 30 && "$PW" =~ [A-Z] && "$PW" =~ [a-z] && "$PW" =~ [0-9] && "$PW" != *admin* && "$PW" != *'"'* ]]; then + echo + break + else + echo "Invalid Password, please retry" + fi + done + BASE64_DB_PASSWORD=`echo -n "$PW" | base64` +fi + +# Wait for provisioning +if ! state_done PROVISIONING; then + echo "`date`: Waiting for terraform provisioning" + while ! state_done PROVISIONING; do + LOGLINE=`tail -1 $MTDRWORKSHOP_LOG/terraform.log` + echo -ne r"\033[2K\r${LOGLINE:0:120}" + sleep 2 + done + echo +fi + + +# Get MTDR_DB OCID +while ! state_done MTDR_DB_OCID; do + MTDR_DB_OCID=`oci db autonomous-database list --compartment-id "$(cat state/COMPARTMENT_OCID)" --query 'join('"' '"',data[?"display-name"=='"'MTDRDB'"'].id)' --raw-output` + if [[ "$MTDR_DB_OCID" =~ ocid1.autonomousdatabase* ]]; then + state_set MTDR_DB_OCID "$MTDR_DB_OCID" + else + echo "ERROR: Incorrect Order DB OCID: $MTDR_DB_OCID" + exit + fi +done + + +# Wait for kubectl Setup +if ! state_done OKE_NAMESPACE; then + echo "`date`: Waiting for kubectl configuration and mtdrworkshop namespace" + while ! state_done OKE_NAMESPACE; do + LOGLINE=`tail -1 $MTDRWORKSHOP_LOG/state.log` + echo -ne r"\033[2K\r${LOGLINE:0:120}" + sleep 2 + done + echo +fi + +# Collect DB password and create secret +while ! state_done DB_PASSWORD; do + echo "collecting DB password and creating secret" + while true; do + if kubectl create -n mtdrworkshop -f -; then + state_set_done DB_PASSWORD + break + else + echo 'Error: Creating DB Password Secret Failed. Retrying...' + sleep 10 + fi < temp_params + umask 22 + oci db autonomous-database update --autonomous-database-id "$(state_get MTDR_DB_OCID)" --from-json "file://temp_params" >/dev/null + rm temp_params + state_set_done MTDR_DB_PASSWORD_SET +done + + + +# Wait for OKE Setup +while ! state_done OKE_SETUP; do + echo "`date`: Waiting for OKE_SETUP" + sleep 2 +done + + + +ps -ef | grep "$MTDRWORKSHOP_LOCATION/utils" | grep -v grep + +bgs="JAVA_BUILDS OKE_SETUP DB_SETUP PROVISIONING" +while ! state_done SETUP_VERIFIED; do + NOT_DONE=0 + bg_not_done= + for bg in $bgs; do + if state_done $bg; then + echo "$bg has completed" + else + # echo "$bg is running" + NOT_DONE=$((NOT_DONE+1)) + bg_not_done="$bg_not_done $bg" + fi + done + if test "$NOT_DONE" -gt 0; then + # echo "Log files are located in $MTDRWORKSHOP_LOG" + bgs=$bg_not_done + echo -ne r"\033[2K\r$bgs still running " + sleep 10 + else + state_set_done SETUP_VERIFIED + fi +done \ No newline at end of file diff --git a/mtdrworkshop/utils/oke-setup.sh b/mtdrworkshop/utils/oke-setup.sh new file mode 100755 index 0000000..8725d88 --- /dev/null +++ b/mtdrworkshop/utils/oke-setup.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# Copyright (c) 2021 Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +# Fail on error +set -e + + +# Create SSL Certs +while ! state_done SSL; do + mkdir -p $MTDRWORKSHOP_LOCATION/tls + openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout $MTDRWORKSHOP_LOCATION/tls/tls.key -out $MTDRWORKSHOP_LOCATION/tls/tls.crt -subj "/CN=grabdish/O=grabdish" + state_set_done SSL +done + + +# Wait for provisioning +while ! state_done K8S_PROVISIONING; do + echo "`date`: Waiting for k8s provisioning" + sleep 10 +done + + +# Get OKE OCID +while ! state_done OKE_OCID; do + OKE_OCID=`oci ce cluster list --compartment-id "$(state_get COMPARTMENT_OCID)" --query "join(' ',data[?"'"lifecycle-state"'"=='ACTIVE'].id)" --raw-output` + state_set OKE_OCID "$OKE_OCID" + # Wait for OKE to warm up +done + + +# Setup Cluster Access +while ! state_done KUBECTL; do + oci ce cluster create-kubeconfig --cluster-id "$(state_get OKE_OCID)" --file $HOME/.kube/config --region "$(state_get REGION)" --token-version 2.0.0 + + cluster_id="$(state_get OKE_OCID)" + kubectl config set-credentials "user-${cluster_id:(-11)}" --exec-command="kube_token_cache.sh" \ + --exec-arg="ce" \ + --exec-arg="cluster" \ + --exec-arg="generate-token" \ + --exec-arg="--cluster-id" \ + --exec-arg="${cluster_id}" \ + --exec-arg="--region" \ + --exec-arg="$(state_get REGION)" + + state_set_done KUBECTL +done + + +# Wait for OKE nodes to become redy +while ! state_done BYO_K8S; do + READY_NODES=`kubectl get nodes | grep Ready | wc -l` || echo 'Ignoring any Error' + if test "$READY_NODES" -ge 3; then + echo "3 OKE nodes are ready" + break + fi + echo "Waiting for OKE nodes to become ready" + sleep 10 +done + + +# Create OKE Namespace +while ! state_done OKE_NAMESPACE; do + if kubectl create ns mtdrworkshop; then + state_set_done OKE_NAMESPACE + else + echo "Failed to create namespace. Retrying..." + sleep 10 + fi +done + +# Wait for TO DO User (avoid concurrent kubectl) +while ! state_done TODO_USER; do + echo "`date`: Waiting for TODO_USER" + sleep 2 +done + +state_set_done OKE_SETUP diff --git a/mtdrworkshop/utils/os-destroy.sh b/mtdrworkshop/utils/os-destroy.sh new file mode 100755 index 0000000..d53e3fe --- /dev/null +++ b/mtdrworkshop/utils/os-destroy.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# Copyright (c) 2021 Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +# Fail on error +set -e + +# Delete Object Store +echo "Deleting Object Store" +# Per-auth + +# ## delete object storage bucket +# oci os bucket delete --bucket-name "$(state_get RUN_NAME)" + +PARIDS=`oci os preauth-request list --bucket-name "$(state_get RUN_NAME)" --query "join(' ',data[*].id)" --raw-output` +for id in $PARIDS; do + oci os preauth-request delete --par-id "$id" --bucket-name "$(state_get RUN_NAME)" --force +done + +# Object +if state_done WALLET_ZIP_OBJECT; then + oci os object delete --object-name "wallet.zip" --bucket-name "$(state_get RUN_NAME)" --force + state_reset WALLET_ZIP_OBJECT +fi + +# Object +if state_done CWALLET_SSO_OBJECT; then + oci os object delete --object-name "cwallet.sso" --bucket-name "$(state_get RUN_NAME)" --force + state_reset CWALLET_SSO_OBJECT +fi + +# Bucket +if state_done OBJECT_STORE_BUCKET; then + oci os bucket delete --bucket-name "$(state_get RUN_NAME)" --force + state_reset OBJECT_STORE_BUCKET +fi diff --git a/mtdrworkshop/utils/pf b/mtdrworkshop/utils/pf deleted file mode 100644 index d8ea6ea..0000000 --- a/mtdrworkshop/utils/pf +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -## MyToDoReact version 1.0. -## -## Copyright (c) 2021 Oracle, Inc. -## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ -export k8s_pod=$1 -for line in $(kubectl get pods --all-namespaces | grep $k8s_pod | awk '{print $2}'); do - echo "kubectl port-forward $line -n mtdrworkshop 8080:8080 " - kubectl port-forward $line -n mtdrworkshop 8080:8080 -done diff --git a/mtdrworkshop/utils/pfkiali b/mtdrworkshop/utils/pfkiali deleted file mode 100644 index 2adeb59..0000000 --- a/mtdrworkshop/utils/pfkiali +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -## MyToDoReact version 1.0. -## -## Copyright (c) 2021 Oracle, Inc. -## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ -kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=kiali -o jsonpath='{.items[0].metadata.name}') 20001:20001 & diff --git a/mtdrworkshop/utils/podshell b/mtdrworkshop/utils/podshell deleted file mode 100644 index e01f1fd..0000000 --- a/mtdrworkshop/utils/podshell +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -## MyToDoReact version 1.0. -## -## Copyright (c) 2021 Oracle, Inc. -## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ -export k8s_pod=$1 -for line in $(kubectl get pods --all-namespaces | \ - grep $k8s_pod | awk '{print $2}'); do - echo "kubectl exec -ti $line -n mtdrworkshop sh" - kubectl exec -ti $line -n mtdrworkshop sh -done diff --git a/mtdrworkshop/utils/repo-destroy.sh b/mtdrworkshop/utils/repo-destroy.sh new file mode 100755 index 0000000..0fa446c --- /dev/null +++ b/mtdrworkshop/utils/repo-destroy.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# Copyright (c) 2021 Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +# Fail on error +set -e + + +# Delete Images +echo "Deleting Images" +IIDS=`oci artifacts container image list --compartment-id "$(state_get COMPARTMENT_OCID)" --query "join(' ',data.items[*].id)" --raw-output` +for i in $IIDS; do + oci artifacts container image delete --image-id "$i" --force +done + +# Delete Repos +echo "Deleting Repositories" +REPO_IDS=`oci artifacts container repository list --compartment-id "$(state_get COMPARTMENT_OCID)" --query "join(' ', data.items[*].id)" --raw-output` +for r in $REPO_IDS; do + oci artifacts container repository delete --repository-id "$r" --force +done + diff --git a/mtdrworkshop/utils/state-functions.sh b/mtdrworkshop/utils/state-functions.sh new file mode 100755 index 0000000..daf6b30 --- /dev/null +++ b/mtdrworkshop/utils/state-functions.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# Copyright (c) 2021 Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +# Make sure this is run via source or . +if ! (return 0 2>/dev/null); then + echo "ERROR: Usage: 'source state-functions.sh" + exit +fi + +if test -z "$MTDRWORKSHOP_STATE_HOME"; then + echo "ERROR: The mtdrworkshopt state home folder was not set" +else + mkdir -p $MTDRWORKSHOP_STATE_HOME/state +fi + +function state_done() { + test -f $MTDRWORKSHOP_STATE_HOME/state/"$1" +} + +# Set the state to done +function state_set_done() { + touch $MTDRWORKSHOP_STATE_HOME/state/"$1" + echo "`date`: $1" >>$MTDRWORKSHOP_LOG/state.log + echo "$1 completed" +} + +# Set the state to done and it's value +function state_set() { + echo "$2" > $MTDRWORKSHOP_STATE_HOME/state/"$1" + echo "`date`: $1: $2" >>$MTDRWORKSHOP_LOG/state.log + echo "$1: $2" +} + +# Reset the state - not done and no value +function state_reset() { + rm -f $MTDRWORKSHOP_STATE_HOME/state/"$1" +} + +# Get state value +function state_get() { + if ! state_done "$1"; then + return 1 + fi + cat $MTDRWORKSHOP_STATE_HOME/state/"$1" +} + +# Export the functions so that they are available to subshells +export -f state_done +export -f state_set_done +export -f state_set +export -f state_reset +export -f state_get diff --git a/mtdrworkshop/utils/terraform.sh b/mtdrworkshop/utils/terraform.sh new file mode 100755 index 0000000..c131681 --- /dev/null +++ b/mtdrworkshop/utils/terraform.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# Copyright (c) 2021 Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +# Fail on error +set -e + + + +#!/bin/bash + +# Provision Cluster, DBs, etc with terraform (and wait) +if ! state_done PROVISIONING; then + cd $MTDRWORKSHOP_LOCATION/terraform + export TF_VAR_ociTenancyOcid="$(state_get TENANCY_OCID)" + export TF_VAR_ociUserOcid="$(state_get USER_OCID)" + export TF_VAR_ociCompartmentOcid="$(state_get COMPARTMENT_OCID)" + export TF_VAR_ociRegionIdentifier="$(state_get REGION)" + export TF_VAR_runName="$(state_get RUN_NAME)" + export TF_VAR_mtdrDbName="$(state_get MTDR_DB_NAME)" + #export TF_VAR_inventoryDbName="$(state_get INVENTORY_DB_NAME)" + + if state_done K8S_PROVISIONING; then + rm -f containerengine.tf core.tf + fi +## appending the output of cat into the file terraform rc + cat >~/.terraformrc < $WORKINGDIR/mtdrworkshopclusterid.txt -cat $WORKINGDIR/mtdrworkshopclusterid.txt -export MTDRWORKSHOP_CLUSTER_ID=$(cat $WORKINGDIR/mtdrworkshopclusterid.txt) -echo MTDRWORKSHOP_CLUSTER_ID... $MTDRWORKSHOP_CLUSTER_ID - -if [[ $MTDRWORKSHOP_CLUSTER_ID == "" ]] -then - echo "MTDRWORKSHOP_CLUSTER_ID does not exist. OKE may still be provisioning. Try again or check the OCI console for progress." -else - export CURRENTTIME=$( date '+%F_%H:%M:%S' ) - echo backing up existing ~/.kube/config, if any, to ~/.kube/config-$CURRENTTIME - cp ~/.kube/config ~/.kube/config-$CURRENTTIME - echo creating ~/.kube/config ... - oci ce cluster create-kubeconfig --cluster-id $MTDRWORKSHOP_CLUSTER_ID --file $HOME/.kube/config --region $MTDRWORKSHOP_REGION --token-version 2.0.0 -# echo create mtdrworkshop namespace... -# kubectl create ns mtdrworkshop -fi