|
| 1 | +Sample illustration of OCI DevOps deployment pipeline with *STAGE LEVEL PARAMETERS* |
| 2 | +------------ |
| 3 | + |
| 4 | +Objective |
| 5 | +--- |
| 6 | +- Create an OCI Deployment pipeline with a default OKE deployment stage. |
| 7 | +- Provide default parameters for the stage. |
| 8 | +- Do executions and demonstrate how can the parameters can override using stage-level parameters. |
| 9 | + |
| 10 | +Specific instructions to download only this sample. |
| 11 | +--- |
| 12 | + |
| 13 | +``` |
| 14 | + $ git init oci-deployment-stagelevelparams |
| 15 | + $ cd oci-deployment-stagelevelparams |
| 16 | + $ git remote add origin https://github.com/oracle-devrel/oci-devops-examples |
| 17 | + $ git config core. sparsecheckout true |
| 18 | + $ echo "oci-deployment-examples/oci-deployment-stagelevelparams/*">>.git/info/sparse-checkout |
| 19 | + $ git pull --depth=1 origin main |
| 20 | +
|
| 21 | +``` |
| 22 | + |
| 23 | +⚠️ Stage level parameter option is now available `ONLY` for `OCI deployment pipeline` and `NOT` available for deployment when invoked from `OCI Buildpipeline` using the `Invoke deployment` stage. |
| 24 | + |
| 25 | +Procedure |
| 26 | +--- |
| 27 | +- The procedure requires an active OKE (Oracle Container Engine for Kubernetes). |
| 28 | + |
| 29 | +- If you do not have an OKE cluster, please create one (It can be private or public hosted nodes /API endpoints) - https://docs.oracle.com/en-us/iaas/Content/ContEng/Tasks/contengcreatingclusterusingoke_topic-Using_the_Console_to_create_a_Quick_Cluster_with_Default_Settings.htm#create-quick-cluster |
| 30 | + |
| 31 | +- Access the OKE Cluster and create two namespaces as `nginx16` and `nginx14`. |
| 32 | +- Create an OCI dynamic group with the below rules. |
| 33 | + |
| 34 | +```java |
| 35 | +ALL {resource.type = 'devopsdeploypipeline', resource.compartment.id = 'COMPARTMENT OCID'} |
| 36 | +``` |
| 37 | + |
| 38 | +- Create an OCI policy with the below statements. |
| 39 | + |
| 40 | +```java |
| 41 | +Allow dynamic-group <NAME of the DG> to manage ons-topics in compartment <NAME Of the COMPARTMENT> |
| 42 | +Allow dynamic-group <NAME of the DG> to manage cluster-family in compartment <NAME Of the COMPARTMENT> |
| 43 | +``` |
| 44 | + |
| 45 | +- Create an OCI Notification topic - https://docs.oracle.com/en-us/iaas/Content/Notification/Tasks/create-topic.htm#top |
| 46 | +- Create a DevOps project and associate it with the notification. - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_project.htm#create_a_project |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +- Ensure enable to logs for the DevOps project. |
| 52 | + |
| 53 | +- Create a DevOps environment of type `Oracle Kubernetes Engine`. |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +- Select the appropriate OKE Cluster and save. |
| 58 | + |
| 59 | +- Create a deployment artifact of type `Kubernetes manifest`. |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | +- Select the source type as `inline` and paste the content from [file here.](deployment. yaml) |
| 64 | + |
| 65 | +- Ensure to select the option `Allow parameterization` and add. |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | +- We are using a sample Nginx deployment file for this procedure. |
| 70 | + |
| 71 | +- Create a `deployment pipeline` - https://docs.oracle.com/en-us/iaas/Content/devops/using/deployment_pipelines.htm |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +- We will be adding `two OKE deployment stages` within the deployment pipeline to illustrate the procedure. |
| 76 | + |
| 77 | +- Use `+` and add first deployment stage of type `OKE Rolling`. |
| 78 | +- Name the stage as `Nginx16` and select the `environment and DevOps artifact created. |
| 79 | +- Use namespace as `nginx16` for the deployment. |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | +- Use `+` add another stage of type `OKE Rolling`. |
| 85 | + |
| 86 | +- Name the stage as `Nginx14` and select the `environment and DevOps artifact created |
| 87 | + |
| 88 | +- Use the namespace as `nginx16` for the deployment. |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +- Set the below parameters for the pipeline (these are global parameters for the pipeline) |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +```java |
| 97 | +- port: 80 |
| 98 | +- version: 1.14.2 |
| 99 | +``` |
| 100 | + |
| 101 | +- Use `Run pipeline` and run the pipeline for both stages. |
| 102 | +- Wait for all the stages to complete. |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | +- Once all the steps are completed, connect to the OKE cluster (preferably using cloud shell and kubectl) and run the below commands and validate the version of the image. |
| 107 | + |
| 108 | +```java |
| 109 | +kubectl describe deployment.apps/nginx-deployment -n nginx16|grep Image |
| 110 | +kubectl describe deployment.apps/nginx-deployment -n nginx14|grep Image |
| 111 | +``` |
| 112 | + |
| 113 | +- It should show the version as the default version values from `deployment parameters |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | +- Let us do a `value override` with another deployment, where we will provide different versions for one of the stages. |
| 118 | + |
| 119 | +- Click on `Run pipeline` > Select `stages` from option `Stage parameters override` |
| 120 | +- Select stage `Nginx16` and provide `Name` as `version` and |
| 121 | + `Value` as `1.16.1`. |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | +- Re-run the commands using kubectl to validate the changes. |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | +- As you may verify from the above that the override is effective, let us do one last test wherein we will try to parse a param which is not defined in the global pipeline parameters. |
| 131 | + |
| 132 | +- Delete the parameter `port` from the `pipeline parameters` |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | +- Re-run the deployment where we will be giving different values for stages as ports. |
| 137 | + |
| 138 | + |
| 139 | + |
| 140 | +- Wait for all the steps to complete and validate the changes by connecting to the OKE cluster. |
| 141 | + |
| 142 | +```java |
| 143 | +kubectl describe deployment.apps/nginx-deployment -n nginx16|grep Port |
| 144 | +kubectl describe deployment.apps/nginx-deployment -n nginx14|grep Port |
| 145 | +``` |
| 146 | + |
| 147 | + |
| 148 | + |
| 149 | +- Ensure to delete OKE resources and devops project related resources once completed . You can use `Cascade deletion` option with in `Devops project` to clean all the devops related resources. |
| 150 | + |
| 151 | +Read more |
| 152 | +---- |
| 153 | + |
| 154 | +- OCI DevOps - https://docs.oracle.com/en-us/iaas/Content/devops/using/home.htm. |
| 155 | +- OCI Reference architectures - https://docs.oracle.com/solutions/ |
| 156 | +- OCI DevOps samples - https://github.com/oracle-devrel/oci-devops-examples |
| 157 | + |
| 158 | +Contributors |
| 159 | +=========== |
| 160 | + |
| 161 | +- Author: Rahul M R. |
| 162 | +- Collaborators : NA |
| 163 | +- Last release: January 2023 |
| 164 | + |
| 165 | +### Back to examples. |
| 166 | +---- |
| 167 | +- 🍿 [Back to OCI Devops Deployment sample](./../README.md) |
| 168 | +- 🏝️ [Back to OCI Devops sample](./../../README.md) |
0 commit comments