TP Devops OCI Pro
TP Devops OCI Pro
Dr
Activity Guide
iss
S1106012GC10
RI
AN
E
(ri
Professional
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
Disclaimer
This document contains proprietary information and is protected by copyright and other intellectual property laws. The
document may not be modified or altered in any way. Except where your use constitutes "fair use" under copyright law, you
may not use, share, download, upload, copy, print, display, perform, reproduce, publish, license, post, transmit, or distribute
this document in whole or in part without the express authorization of Oracle.
The information contained in this document is subject to change without notice and is not warranted to be error-free. If you
se
find any errors, please report them to us in writing.
en
Restricted Rights Notice
lic
If this documentation is delivered to the United States Government or anyone using the documentation on behalf of the
bl e
United States Government, the following notice is applicable:
ra
U.S. GOVERNMENT END USERS: Oracle programs (including any operating system, integrated software, any programs
embedded, installed or activated on delivered hardware, and modifications of such programs) and Oracle computer
sfe
documentation or other Oracle data delivered to or accessed by U.S. Government end users are "commercial computer
software" or "commercial computer software documentation" pursuant to the applicable Federal Acquisition Regulation and
an
agency-specific supplemental regulations. As such, the use, reproduction, duplication, release, display, disclosure,
-tr
modification, preparation of derivative works, and/or adaptation of i) Oracle programs (including any operating system,
integrated software, any programs embedded, installed or activated on delivered hardware, and modifications of such
. non
programs), ii) Oracle computer documentation and/or iii) other Oracle data, is subject to the rights and limitations specified in
the license contained in the applicable contract. The terms governing the U.S. Government's use of Oracle cloud services are
ide a
defined by the applicable contract for such services. No other rights are granted to the U.S. Government.
Gu as
Trademark Notice
is ) h
Oracle®, Java, MySQL, and NetSuite are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks
e om
Intel and Intel Inside are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are used under
th
license and are trademarks or registered trademarks of SPARC International, Inc. AMD, Epyc, and the AMD logo are
to gma
trademarks or registered trademarks of Advanced Micro Devices. UNIX is a registered trademark of The Open Group.
This documentation may provide access to or information about content, products, and services from third parties. Oracle
Corporation and its affiliates are not responsible for and expressly disclaim all warranties of any kind with respect to third-
r
.d
party content, products, and services unless otherwise set forth in an applicable agreement between you and Oracle. Oracle
Corporation and its affiliates will not be responsible for any loss, costs, or damages incurred due to your access to or use of
e
an
third-party content, products, or services, except as set forth in an applicable agreement between you and Oracle.
(ri
1111142023
E
AN
RI
iss
Dr
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Table of Contents
se
Get Started...................................................................................................................................................... 10
en
Install the Oracle Cloud Infrastructure Ansible Collection .................................................................... 12
lic
Launch and Terminate a Compute Instance Using Ansible Playbook ............................................... 13
bl e
Purge Instructions......................................................................................................................................... 18
ra
sfe
Configuration Management and Infrastructure as Code: Deploy a Web App to Multiple Compute
Instances ........................................................................................................................................... 19
an
Get Started...................................................................................................................................................... 20
-tr
Set Up the Lab Environment ...................................................................................................................... 22
. non
Configure Ansible Resources and Playbook ............................................................................................ 26
ide a
Execute Ansible Playbook to Install and Configure Apache Hosts ..................................................... 28
Gu as
Purge Instructions......................................................................................................................................... 32
is ) h
Configuration Management and Infrastructure as Code: Create a Reusable VCN Configuration with
e om
Terraform.......................................................................................................................................... 33
us il.c
Get Started...................................................................................................................................................... 34
th
to gma
Purge Instructions......................................................................................................................................... 48
r
.d
Configuration Management and Infrastructure as Code: Replicate an Existing Load Balancer Using
e
an
Get Started...................................................................................................................................................... 50
E
Purge Instructions......................................................................................................................................... 60
Microservice and Container Orchestration: Create Docker Image for a Web Application Using
se
Dockerfile.......................................................................................................................................... 77
en
Get Started...................................................................................................................................................... 78
lic
Access the Dockerfile ................................................................................................................................... 79
bl e
Build the Docker Image ............................................................................................................................... 80
ra
Run Your Docker Image as a Container ................................................................................................... 81
sfe
Access the Web Application Running Within the Container ................................................................ 82
an
Delete the Docker Container....................................................................................................................... 83
-tr
Microservices and Container Orchestration: Manage OCIR and Push and Pull Images Using Docker
. non
CLI ...................................................................................................................................................... 85
Get Started...................................................................................................................................................... 86
ide a
Gu as
Create an Auth Token .................................................................................................................................. 88
is ) h
Get Started...................................................................................................................................................... 98
e
Microservice and Container Orchestration: Deploy a Sample Web Application on an OKE Cluster
Using kubectl .................................................................................................................................... 105
RI
Add the Secret and the Image Path to the Deployment Manifest ...................................................... 110
Deploy the Sample Web Application to OKE Cluster ............................................................................. 112
Verify if the Sample Web Application Is Accessible ............................................................................... 113
Clean Up the Resources Deployed Within OKE Cluster......................................................................... 115
Continuous Integration and Continuous Delivery: Work with Code Repositories in OCI DevOps
Project ............................................................................................................................................... 117
Get Started...................................................................................................................................................... 118
Create a Personal Access Token in GitHub.............................................................................................. 120
Create Keys and Vault Secrets.................................................................................................................... 121
se
Create a DevOps Project .............................................................................................................................. 123
en
Create an External Connection................................................................................................................... 125
lic
Mirror Your GitHub Repository .................................................................................................................. 126
bl e
Create an OCI Code Repository in Your DevOps Project ...................................................................... 128
ra
Clone OCI Code Repository in Your Cloud Shell Session ...................................................................... 129
sfe
Perform Basic Git Operations on the Code Repository ......................................................................... 132
an
Continuous Integration and Continuous Delivery: Create an Artifact Registry and Set Up Artifacts
-tr
and Environments in a DevOps Project ......................................................................................... 135
. non
Get Started...................................................................................................................................................... 136
Create a Repository to Store and Manage Artifacts............................................................................... 138
ide a
Add Container Image Repository Artifact to Store Docker Images .................................................... 139
Gu as
Create a Reference to Kubernetes Manifest ............................................................................................ 141
is ) h
Continuous Integration and Continuous Delivery: Automate Web App Deployment to an OKE
us il.c
th
Monitoring - Notification: Configure Alarms with Notifications and Create Monitoring Queries
........................................................................................................................................................... 161
RI
Logging Services: Manage DevOps Project Log Using OCI Console ........................................... 183
Get Started...................................................................................................................................................... 184
Configure Logs for DevOps Project........................................................................................................... 186
Run the Build ................................................................................................................................................. 188
se
Search Your Logs .......................................................................................................................................... 189
en
Purge Instructions......................................................................................................................................... 193
lic
Event Service: Define Rules that Trigger a Specific Action When a DevOps Event Occurs ..... 195
bl e
Get Started...................................................................................................................................................... 196
ra
Configure a Notification .............................................................................................................................. 198
sfe
Create an Event Rule .................................................................................................................................... 200
an
Validate Event Rule by Running a Build ................................................................................................... 201
-tr
Purge Instructions......................................................................................................................................... 204
. non
Continuous Integration and Continuous Delivery: Deploy a Sample Web Application to an OKE
ide a
Cluster Using Helm Chart Deployment in OCI DevOps ................................................................ 205
Gu as
Get Started...................................................................................................................................................... 206
is ) h
Create OCI Repositories for Container Image and Helm Chart ........................................................... 214
us il.c
Set Up the kubeconfig File and Create a Kubernetes Namespace ................................................ 227
r
.d
Automate Sample Web Application Deployment to OKE Cluster Using Helm Chart ...................... 229
e
DevSecOps: Generate a Key Using OCI Vault Service to Perform Cryptographic Operations 237
AN
se
Sign In to OCIR from the Cloud Shell ........................................................................................................ 253
en
Pull the Docker Image .................................................................................................................................. 255
lic
Tag the Docker Image .................................................................................................................................. 256
bl e
Push the Tagged Docker Image to OCIR .................................................................................................. 257
ra
Verify If the Image Has Been Pushed ....................................................................................................... 258
sfe
View Scan Results ......................................................................................................................................... 259
an
View Vulnerability Reports .......................................................................................................................... 260
-tr
View Container Image Scans ...................................................................................................................... 261
. non
Export a Vulnerability Report ..................................................................................................................... 263
Purge Instructions......................................................................................................................................... 264
ide a
Gu as
DevSecOps: Sign and Verify Container Image in OCIR ................................................................ 267
is ) h
Oracle Cloud Infrastructure DevOps Professional: Hands-on Workshop – Table of Contents vii
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
viii
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
. non
-tr
Overview
Oracle Cloud Infrastructure Ansible Collection provides an easy way to provision and manage
resources in Oracle Cloud using Ansible. Ansible playbooks automate configuration,
se
deployment, and orchestration tasks. Ansible playbooks use a declarative language (YAML)
en
that allows you to describe infrastructure configuration, deployment policy, and the
lic
orchestration of complex process steps. The Ansible basic setup is very easy, and the Oracle
provided example playbooks in Git are a good base to start with your infrastructure
bl e
automation project. Oracle provides Ansible example playbooks for Compute, Block Volumes,
ra
Database, File Storage, IAM, Load Balancer, Private Subnets with VPN, Delete Objects, and so
sfe
on. In this lab, you will learn how easy it is to bring Ansible and Oracle Cloud Infrastructure
an
together.
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
For more information on OCI Ansible Collection, see the OCI Ansible Collection
iss
Documentation.
Dr
se
ocid1.image.oc1.iad.aaaaaaaa33a3lofqhzh5wvpi34fnsqiwdwaytjls5
2pksm7r5kinnp6ew3na
en
lic
− Region-wise image OCID list:
https://docs.oracle.com/en-us/iaas/images/image/3baec0b4-4bac-4cb0-ac1d-
bl e
621846621396/
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
Collection
You will install the OCI Ansible collection from Ansible Galaxy.
Tasks
se
en
1. Sign in to your Oracle Cloud Infrastructure (OCI) account.
lic
2. Open the Cloud Shell from the Developer tools listed in the OCI console header
bl e
ra
sfe
an
-tr
. non
ide a
Note: The OCI CLI running in the Cloud Shell will execute commands against the region
Gu as
selected in the Console's region selection menu when the Cloud Shell was started.
is ) h
3.
e om
oracle.oci.oci_object_storage_namespace_facts
iss
On successful execution, this command will return your object storage namespace.
r
e .d
For example,
an
"changed": false,
E
"namespace": "oracletenancy"
AN
}
RI
developers/launch_compute_instance
Ansible Playbook
You will learn how to use Ansible playbook to automate launching a compute instance and
connect to it using SSH.
se
Tasks
en
lic
bl e
1. Open Code Editor from the Developer tools listed in the OCI console header.
ra
sfe
an
-tr
. non
2. The tool bar is on the left side of the Code Editor window. Click the Explorer (top) icon
ide a
Gu as
from the left side menu within the Code Editor window.
is ) h
e om
us il.c
th
to gma
@
iss
r
.d
Browse to the launch_compute_instance directory to view the various files you have
e
an
• The sample.yaml file is the main Playbook which consists of tasks required to
AN
variables and setting up of other networking resources required for the launch of
Dr
• The teardown.yaml file contains tasks to terminate all the resources created in
this lab. The sample.yaml file imports the teardown.yaml file and executes it
as part of play towards the end.
Where,
• The <IMAGE_OCID> is the OCID of the image originally used to launch the instance.
se
For example,
en
$ export
lic
SAMPLE_IMAGE_OCID=ocid1.image.oc1.iad.aaaaaaaa33a3lofqhzh5wvpi34
bl e
fnsqiwdwaytjls52pksm7r5kinnp6ew3na
ra
sfe
Note: For the <IMAGE_OCID> use the Image OCID that is provided in the example if
an
the region you are working in is us-ashburn-1. If you are working in a different
-tr
region, then use the image OCID from this location.
. non
b. Set Compartment OCID
ide a
$ export SAMPLE_COMPARTMENT_OCID=<COMPARTMENT_OCID>
Gu as
Where,
is ) h
To get the OCID for the compartment where compute instance is to be launched:
r
.d
a) In the Console, open the navigation menu and click Identity & Security.
e
an
d) Search for your <assigned compartment> and click the shortened OCID
iss
string to view the entire value in a pop-up. Click Copy to copy and save the
Dr
OCID.
For example,
$ export
SAMPLE_COMPARTMENT_OCID=ocid1.compartment.oc1..xxxxxxxxycxxxxxx0
347034703470347000000o3hx2exkz5pzi6kt4xxxxxx
$ export SAMPLE_AD_NAME=<SAMPLE_AD_NAME>
Where,
• The <SAMPLE_AD_NAME> is the availability domains in your tenancy you want the
instance to be hosted in.
se
To get the Availability domain names in your tenancy where the compute instance is to be
en
launched:
lic
bl e
a) Open the navigation menu and click Compute. Under Compute, click
Instances.
ra
sfe
b) Click Create instance.
an
-tr
c) Locate the Placement section on the page, and under the Availability
. non
domain, copy the complete name from any one of the availability domains
listed. Refer to the screenshot given below.
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
.d
For example,
(ri
$ export SAMPLE_AD_NAME=yQUJ:US-ASHBURN-AD-1
E
AN
$ echo $SAMPLE_IMAGE_OCID
iss
$ echo $SAMPLE_COMPARTMENT_OCID
$ echo $SAMPLE_AD_NAME
Dr
The output of these commands will return the OCIDs and name set in the previous step.
generation, network configuration, firewall rule setup, instance creation, etc. are all
automated.
$ ansible-playbook sample.yaml
se
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
After a few minutes, the complete infrastructure for an OCI compute instance is created, and
E
AN
the instance is connected using SSH, whose response is shown on the screen.
RI
iss
Dr
se
en
Note: Since the teardown.yaml file is called within the sample.yaml file the termination of
lic
the resources will take place immediately.
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
You can also view the compute instance which was provisioned by the ansible playbook.
@
iss
a. Open the navigation menu. Under Compute, click Instances and select your
r
You will see the compute instance provisioned by the Ansible playbook with the name
(ri
Congratulations! You were able to install the OCI Ansible collection to launch and later
RI
se
$ unset SAMPLE_AD_NAME
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
. non
-tr
Lab 02-1 Practices
an
sfe
ra
Estimated Time: 30 minutes bl e
lic
Deploy a Web App to
en
se
Configuration Management
and Infrastructure as Code:
Overview
se
configuration, deployment policy, and the orchestration of complex process
en
steps. OCI provides a set of example playbooks for you to use.
lic
In this lab, you will learn how to install and configure an Apache webserver using an Ansible
bl e
Playbook. Additionally, you will learn how to spin up the Apache applications and deploy that
ra
to two compute instances.
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
For more information on OCI Ansible Collection, see the OCI Ansible Collection
RI
Documentation.
iss
Assumptions
Dr
• You are signed in to your Oracle Cloud Infrastructure (OCI) account using your
credentials.
• You are familiar with basic Linux commands.
se
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
You will create a VCN with two compute instances in a public subnet and a SSH key pair to
establish secure client/server connections via SSH to running instances in the cloud.
Create a VCN
se
1. Open the navigation menu, click Networking, and then click Virtual Cloud Networks.
en
lic
2. Select your <assigned compartment> from List scope on the left menu.
bl e
3. Click Start VCN Wizard.
ra
sfe
a. Select Create VCN with Internet Connectivity, and then click Start VCN Wizard.
an
-tr
b. Enter the following values in the form:
. non
• VCN Name: IAD-DOP-LAB02-1-VCN-01
• Compartment: Select your <assigned compartment>.
ide a
Gu as
• Configure VCN and Subnets: Leave the CIDR blocks as their defaults.
is ) h
4. Click Next.
us il.c
th
to gma
5. Review the list of resources that the wizard will create for you. Notice that the wizard will
set up security list rules and route table rules to enable basic access for the VCN.
@
iss
7. After the components are created, click View Virtual Cloud Network.
e
an
8. On the left menu under Resources click Security Lists to view the VCN’s security lists.
(ri
E
9. Click the Default Security List for IAD-DOP-LAB02-1-VCN-01 to view its details. By
AN
11. Enter the following values in the form to enable traffic from any source IP address
(represented as 0.0.0.0/0) to destination port 80 only (TCP protocol):
• Stateless: Deselect the box (this is a stateful rule).
• Source Type: Select CIDR.
• Source CIDR: 0.0.0.0/0
se
Create SSH Keys in Cloud Shell
en
You will create an SSH key pair to connect to your environment.
lic
bl e
1. Open Cloud Shell.
ra
sfe
2. Once the Cloud Shell session is initiated, create and then move to .ssh directory.
$ mkdir ~/.ssh (skip this step if the directory already exists)
an
$ cd ~/.ssh
-tr
. non
3. Create a new public and private key pair.
$ ssh-keygen -b 2048 -o -t rsa -f key-lab02-<userID>
ide a
Gu as
Where,
is ) h
e om
key-lab02-<userID> is the key name. Replace <userID> with your user ID. You will
use this key name to connect to the compute instances you create.
us il.c
th
to gma
For example,
$ ssh-keygen -b 2048 -o -t rsa -f key-lab02-user22
@
iss
key from being used by someone who doesn’t know the passphrase.
(ri
5. List the two key files (public and private key) that you just created.
E
AN
$ ls
RI
You will observe two files listed in the output. One is the private key (key-lab02-
iss
user22), and the other is the public key (key-lab02-user22.pub). Your files will
Dr
Note: You must never share the private key with anyone.
6. Run the following command to view the contents of the public key:
$ cat key-lab02-<userID>.pub
$ cat key-lab02-user22.pub
You will see a random string like the one below as the output:
ssh-rsa
XXXXB3NzaC1yc2EAAAADAQABAAABAQCdQ9+4JM9GxCWPIDGFjO1tk4jkumO2zbhA
1ZaePxEGKwSFDEw/De7HU6wRh+Jbutkw9tOzlUr8FgAGNRgyWgaHbj5YX0h+LXWl
se
rIiTtBFpZkMYlMwJUAFTmMwWy12rGYeUD/Ba+KVlEYaMT1XY0DCa+SFyq48uWQwg
Qns8654UycwFzFsXvZvA1i48Mk63vuSTAw15vGLXXXXXX0jegHOhMGrNMRuE4eMK
en
SECP+CDFFgKb2oCzFz8KwywFuDciHAbMZru5qkiFGomeBvClDEU2BfMOV7k69kfi
lic
voxHHlnwxwgJulMeXrMLsE1/osZcy5s2Eon3WmxJqo1wAAAAAA
bl e
user22_E@3c15a0xxxxxx
ra
7. Copy the contents of the public key and save it to your notepad. Later, when pasting the
sfe
key into the compute instance, make sure you remove any extra lines/characters that
an
may have been added while copying.
-tr
. non
Create Compute Instances
1.
ide a
Open the navigation menu and click Compute. Under Compute, click Instances.
Gu as
is ) h
a. Name: IAD-DOP-LAB02-1-VM-01
us il.c
th
1)
e
Select Ampere in Shape series and select VM. Standard.A1.Flex shape name
with 1 OCPU and change Amount of memory(GB) to 2GB memory. Click Select
RI
shape.
iss
Dr
2) Virtual cloud network in <assigned compartment>: Select your existing VCN, that
is, IAD-DOP-LAB02-1-VCN-01.
se
3) Subnet: Choose Select existing subnet option.
en
4) Subnet in <assigned compartment>: Select your existing public subnet, that is,
lic
Public Subnet-IAD-DOP-LAB02-1-VCN-01.
bl e
ra
5) Check the Assign a public IPv4 address option.
sfe
f. Under Add SSH keys: Select Paste public keys and paste the public key key-
an
lab02-user22.pub contents from your notepad that you copied earlier.
-tr
. non
g. In the Boot volume section, leave all options as default.
4. Repeat Steps 1 to 3 again to create a new instance with the name as IAD-DOP-LAB02-1-
e om
VM-02.
us il.c
th
You will set up Ansible clients to install and configure the web server.
Tasks
1. Within Cloud Shell, clone the GitHub repository to access the Ansible Playbook and the
se
host file to install and configure the Apache webserver.
en
$ cd ~
lic
$ git clone https://github.com/ou-developers/devops-lab02-
bl e
ansible.git
ra
2. Navigate to the cloned directory.
sfe
$ cd ~/devops-lab02-ansible
an
-tr
3. Open Code Editor. The tool bar is on the left side of the Code Editor window. Click
. non
the Explorer (top) icon from the left-side menu within the Code Editor window.
ide a
Browse to the cloned Git directory to view the various files you have in the directory
Gu as
including index.html, hosts.yaml, and playbook.yaml for configuring Apache
is ) h
webserver.
e om
4. The hosts.yaml file contains a list of hosts which Ansible will be interacting with. In the
us il.c
th
hosts.yaml file, you will add the Public IP Addresses of the compute instances you
to gma
created earlier.
@
Note: YAML files are sensitive to code indentation. Make sure you follow the indentation
properly.
1) Open the navigation menu and click Compute. Under Compute, click Instances.
2) Copy the Public IP Address from the instance table for both the instances.
• IAD-DOP-LAB02-1-VM-01
• IAD-DOP-LAB02-1-VM-02
se
en
Your hosts.yaml file will look like this:
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
Note: You must insert a colon (:) at the end of each IP.
e om
Apache Hosts
You will review the Ansible Playbook code piece by piece and will execute it to install and
configure the Apache webserver in the two compute instances you created earlier in this lab.
se
Tasks
en
lic
1. Open the Playbook.yaml file in the Code Editor and review the code.
bl e
The code snippet should look like this:
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr
Where,
• name tag at the beginning of the playbook specifies the play name.
• hosts tag specifies the lists of hosts. The hosts tag is mandatory. It tells Ansible on
which hosts to run the listed tasks.
• remote_user tag specifies the user used to log in to the target hosts.
• tasks field contains the names and list of tasks to be performed. Tasks are the
actions to be performed on the hosts.
se
1) Ensure Apache is at the latest version.
en
This task uses the ansible.builtin.yum module which installs, removes,
lic
upgrades, downgrades packages using yum.
bl e
• name tag specifies the rpm to be installed. Here httpd will be installed.
ra
sfe
• state tag specifies the rpm version to be installed. latest denotes that the
latest available httpd version will be installed.
an
-tr
2) Ensure Apache is running.
. non
This task uses the ansible.builtin.service module which controls services
on remote hosts. ide a
Gu as
• name tag specifies the service to be controlled. It’s httpd in this case.
is ) h
• state tag specifies the state in which the service should be. started
e om
file.
r
• owner tag specifies the user ownership for the copied file. Here the owner is
(ri
user apache.
E
AN
• group tag specifies the group ownership for copied file. Here the group
RI
• mode tag specifies the permissions 0644 for the copied file.
Dr
se
• immediate tag applies the configuration immediately if the value is set to
en
true.
lic
bl e
2. To launch a terminal panel in Code Editor, right-click the devops-lab02-ansible
directory and click Open in terminal.
ra
sfe
3. Close the code editor and in the Cloud Shell, execute the Ansible Playbook:
an
$ ansible-playbook -i hosts.yaml playbook.yaml --key-file
-tr
"~/.ssh/key-lab02-<userID>"
. non
Replace <userID> with your user ID.
For example, ide a
Gu as
$ ansible-playbook -i hosts.yaml playbook.yaml --key-file
is ) h
"~/.ssh/key-lab02-user22"
e om
us il.c
th
4. After the playbook execution completes, both compute instances will have Apache installed
to gma
The output should look like this (IP addresses have been censored):
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
se
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
The resources created in this Lab must be retained as they will be used in the
Configuration Management and Infrastructure as Code: Replicate an existing Load
Balancer using terraform configuration scripts and OCI Resource manager (Lab 04-1) Lab.
se
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
. non
Terraform
-tr
se
Configuration Management
and Infrastructure as Code:
Get Started
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Overview
There are multiple ways to create a VCN and subnet in the Oracle Cloud Console. Particularly if
you want to launch several VCNs with the same configuration, it’s beneficial to use Terraform
se
or Resource Manager to streamline and automate that process. Terraform can manage low-
en
level components such as compute, storage, and networking resources, as well as high-level
lic
components such as DNS entries and SaaS features.
bl e
You’ll launch and destroy a VCN and subnet by creating Terraform automation scripts and
ra
issuing commands in Code Editor. Thereafter, you’ll download those Terraform scripts and
sfe
create a stack by uploading them into Oracle Cloud Infrastructure Resource Manager. You’ll
an
then use that service to launch and destroy the same VCN and subnet.
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
For more information on Terraform Provider, see the OCI Terraform Provider
iss
Documentation and for OCI Resource Manager, see the OCI Resource Manager
Dr
Documentation.
• You are signed in to your Oracle Cloud Infrastructure (OCI) account using your
credentials.
• You are familiar with basic Linux commands.
• This lab assumes you’re working in the Ashburn region. The resource naming
se
convention (iad) used in this lab is according to Ashburn.
en
If you’re working in a different region, change the resource names accordingly. For
lic
example, for Phoenix, use phx.
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
riss
e .d
an
(ri
E
AN
RI
iss
Dr
Tasks
1. Click the Cloud Shell icon at the right of the OCI Console header.
se
en
Note: The OCI CLI running in the Cloud Shell will execute commands against the region
lic
selected in the Console's region selection menu when the Cloud Shell was started.
bl e
2. Within Cloud Shell, clone the GitHub repository to access the Terraform scripts to launch
ra
sfe
and destroy a VCN and subnet.
$ cd ~
an
-tr
$ git clone https://github.com/ou-developers/devops-lab03-
. non
terraform.git
4. Open Code Editor. Code Editor allows you to view the files and source codes present in
e om
The tool bar is on the left side of the Code Editor window. Click the Explorer (top) icon
from the left-side menu within the Code Editor window.
@
iss
5. Browse to the cloned Git directory devops-lab03-terraform to view the various files
you have in the directory including vcn.tf, terraform.tfvars, and
r
.d
variables.tf files.
e
an
Review the vcn.tf file that contains code to configure OCI Terraform.
(ri
E
AN
RI
iss
Dr
se
en
lic
bl e
ra
sfe
an
-tr
. non
6. Right-click the devops-lab03-terraform folder from the left menu in Code Editor and
open a new terminal by clicking Open in Terminal.
ide a
Gu as
7. A new terminal opens in the split window as shown:
is ) h
e om
us il.c
th
to gma
@
riss
e .d
an
(ri
E
AN
RI
iss
Dr
8. Initialize this directory for Terraform by running the below given command in the new
terminal window.
$ terraform init
9. Use ls -a and you should see that Terraform has created a hidden directory and file.
Terraform uses providers to interface between the Terraform engine and the supported cloud
platform. The Oracle Cloud Infrastructure (OCI) Terraform provider is a component that
connects Terraform to the OCI services that you want to manage.
You’ll create a Terraform script that will launch a VCN and subnet. You’ll then alter your script
se
and create two additional files that will apply a compartment OCID variable to your Terraform
en
script.
lic
bl e
Tasks
ra
sfe
Edit Your Terraform Script
an
1. Open Code Editor and edit the vcn.tf in the cloned directory devops-lab03-
-tr
terraform file as follows:
. non
a. Uncomment the VCN declaration code block by deleting the # at the start of the
ide a
Gu as
following lines as marked using the arrows.
is ) h
e om
us il.c
th
to gma
@
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr
se
en
lic
bl e
ra
sfe
an
-tr
Note: Replace <your_assigned_compartment_ocid> with your assigned
. non
compartment OCID.
ide a
Gu as
To get your Compartment OCID:
is ) h
2) Find your compartment name, hover the cursor over the OCID, and click
th
Copy. Make sure you save the Compartment OCID in a notepad for later
to gma
use.
@
This snippet declares a resource block of type oci_core_vcn. The label that
iss
$ terraform plan
E
AN
Upon execution of this command, Terraform would create a VCN. Because most of
the parameters were unspecified, Terraform will list their values as “(known after
RI
Note: You can ignore the “-out option to save this plan” warning for this
lab.
Note that terraform plan parses your Terraform configuration and creates an
execution plan for the associated stack, while terraform apply applies the
execution plan to create (or modify) your resources.
the lines highlighted using arrows (Delete the # character at the start of the line.).
Note that we want to set the cidr_blocks parameter, rather than cidr_block
(which is deprecated). The region code IAD is used below, for the US East (Ashburn)
region.
se
en
lic
bl e
ra
sfe
an
-tr
. non
e. After uncommenting the code block, it’ll look like this.
ide a
Gu as
is ) h
e om
us il.c
th
f. Save the changes and run terraform plan again in the Code Editor terminal
to gma
window.
@
$ terraform plan
iss
You should see the display name IAD-DOP-LAB03-1-VCN-01 and CIDR block
r
.d
comments /*..*/ from the given code block in the vcn.tf file as highlighted using
arrows. Replace <your_assigned_compartment_ocid> with your assigned
compartment OCID.
se
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
Note that the line where you set the vcn_id. Here you reference the OCID of the
th
previously declared VCN, using the name given to Terraform: example_vcn. This
to gma
dependency makes Terraform provision the VCN and wait for OCI to return the OCID.
@
$terraform plan
You will notice that terraform has updated plan to create the subnet IAD-DOP-
LAB03-1-SNT-01.
1. Before moving on, there are a few ways to improve the existing code. Notice that the subnet
and VCN both need the compartment OCID. We can factor this out into a variable.
2. In the code editor window, review the variables.tf file in the cloned directory devops-
lab03-terraform.
se
en
lic
bl e
ra
sfe
variable.tf are files where all variables are declared.
an
-tr
Notice the variable compartment_id of type string is declared.
. non
3. Open vcn.tf file in code editor and replace all instances of the compartment OCID with
var.compartment_id as follows: ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
5. If you were to run terraform plan or apply now, Terraform would see a variable and
provide you a prompt to input the compartment OCID. Instead, you’ll provide the variable
value in a dedicated file.
directory devops-lab03-terraform.
Terraform will automatically load values provided in a file with this name. Add the value for
the compartment ID in this file.
se
you saved earlier.
en
lic
bl e
ra
sfe
After editing the code block, it will look like this,
an
-tr
. non
Be sure to save the file. ide a
Gu as
is ) h
$terraform plan
us il.c
th
1. Run terraform apply in the Code Editor terminal window and confirm that you want to
r
$terraform apply
an
(ri
Note: On successful execution of the terraform apply command, you’ll see the
following message:
E
AN
a. Open the navigation menu, click Networking, and then click Virtual Cloud Network.
Dr
You should see your VCN. Click on your VCN IAD-DOP-LAB03-1-VCN-01 to see the
details. You should see its subnet IAD-DOP-LAB03-1-SNT-01 listed.
2. Enter yes to confirm. You should see the VCN terminate. Refresh your browser if needed.
se
Note: On successful execution of terraform apply command, you’ll see the following
en
message:
lic
Destroy complete! Resources: 2 destroyed.
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr
You can better manage the infrastructure provisioned through Terraform by migrating to
Resource Manager instead of running Terraform locally in Cloud Shell or Code Editor. In this
section, we will reuse the Terraform code but replace the CLI with Resource Manager.
Tasks
se
en
1. Create a folder terraform_vcn on your local machine. Download the vcn.tf,
lic
terraform.tfvars, and variables.tf files from Code Editor and move them to the
bl e
terraform_vcn folder to your local machine.
ra
sfe
To download from Code Editor, right-click the file name in the Explorer panel and select
an
Download.
-tr
Create a Stack
. non
1. Click the Navigation Menu in the upper-left corner and navigate to Developer Services.
ide a
Gu as
Under Resource Manager, click Stacks.
is ) h
a.
us il.c
machine.
r
.d
4) Name: IOD-DOP-LAB03-1-STK-01
E
AN
7) Click Next.
Dr
2) Click Create. This will take you to the stack’s details page.
se
en
Run a Plan Job
lic
1. The stack itself is only a bookkeeping resource, no infrastructure is provisioned yet. From
bl e
the stack’s page, click Plan. A form will pop up.
ra
sfe
a. Name the job RM-Plan-01.
an
b. Click Plan again at the bottom to submit a job for Resource Manager to run
-tr
terraform plan. This will take you to the job’s details page.
. non
2. Wait for the job to complete, and then view the logs. They should match what you saw when
you ran Terraform in Code Editor. ide a
Gu as
is ) h
1. Go back to the stack’s details page (use the breadcrumbs), and click Apply. A form will pop
us il.c
th
up.
to gma
b. Under Apply job plan resolution, select the plan job we ran, that is RM-Plan-01
r
(instead of “Automatically approve”). This makes it execute based on the previous plan,
e .d
c. Click Apply to submit a job for Resource Manager to run terraform apply. This will
E
2. Wait for the job to finish. View the logs and confirm that it was successful.
RI
iss
1. Navigate to VCNs in the Console through the navigation menu under Networking and
Virtual Cloud Networks.
2. You should see the VCN listed in the table with the name IAD-DOP-LAB03-1-VCN-01.
Click its name to go to its Details page.
2. Click Destroy. Click Destroy again on the menu that pops up.
se
en
3. Wait for the job to finish. View the logs to see that it was completed successfully.
lic
4. Verify the termination of VCN by navigating back to the OCI Console.
bl e
ra
a. Open the navigation menu, click Networking, and then click Virtual Cloud Network.
sfe
b. Ensure you have selected your assigned compartment.
an
-tr
c. You will see your VCN IAD-DOP-LAB03-1-VCN-01 has been deleted by the
. non
destroyed job.
5. ide a
In the Console, open the navigation menu and click Developer Services. Under Resource
Gu as
Manager, select Stacks.
is ) h
e om
6. For the stack IOD-DOP-LAB03-1-STK-01, click the three dots on the right to open the
Actions menu. Select Delete and then click Delete to confirm.
us il.c
th
to gma
Congratulations! You’ve now created a Terraform configuration for a VCN, created and
destroyed the VCN through Terraform running locally in Cloud Shell/Code Editor, and created
@
48
Dr
iss
RI
AN
E
(ri
an
e
Purge Instructions
.d
riss
@
There is no purge instruction for this lab.
to gma
us il.c
e om
th
is ) h
Gu as
ide a
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Lab 04-1
Gu as
ide a
. non
-tr
an
sfe
ra
bl e
se
Configuration Scripts and
Balancer Using Terraform
Replicate an Existing Load
Configuration Management
and Infrastructure as Code:
Get Started
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Overview
Resource Manager’s resource discovery allows you to generate Terraform based on existing
infrastructure. This allows use cases such as manually provisioning infrastructure during a
se
development cycle, then moving to Terraform for a deployment cycle. It also enables use
en
cases such as migrating environments between regions or replicating environments for
lic
different purposes (for example, development, QA, or production).
bl e
In this lab, you’ll first manually provision a Load Balancer, add backend servers to it, and verify
ra
if the webpage hosted on the backend servers is accessible using Load Balancer’s Public IP
sfe
Address. Then, you’ll use Resource Manager to generate Terraform configuration for the Load
an
Balancer. Finally, you’ll use that Terraform configuration to replicate the Load Balancer.
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
For more information on Terraform Provider, see the OCI Terraform Provider
Dr
Documentation and for OCI Resource Manager, see the OCI Resource Manager
Documentation.
50 Replicate an existing Load Balancer using terraform configuration scripts and OCI Resource manager
Prerequisites
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
• You must have completed the Configuration Management and Infrastructure as Code:
Deploy a web app to multiple compute instances (Lab02-1) lab.
Assumptions
se
• You are signed in to your Oracle Cloud Infrastructure (OCI) account using your
en
credentials.
lic
• You have the following resources available in your assigned compartment:
bl e
− Virtual Cloud Network: IAD-DOP-LAB02-1-VCN-01
ra
− Compute Instances: IAD-DOP-LAB02-1-VM-01 and IAD-DOP-LAB02-1-VM-02
sfe
• You are familiar with basic Linux commands.
an
• This lab assumes you’re working in the Ashburn region. The resource naming
-tr
convention (iad)used in this lab is according to Ashburn.
. non
If you’re working in a different region, change the resource names accordingly. For
example, for Phoenix, use phx.
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
Replicate an existing Load Balancer using terraform configuration scripts and OCI Resource manager 51
Set Up the Lab Environment
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
You will manually create a Load Balancer, add backend servers to it and verify if the webpage
hosted on the backend servers is accessible using Load Balancer’s Public IP Address.
se
1. Open the navigation menu, click Networking, and then click Load Balancers.
en
lic
2. Select your <assigned compartment> from List scope on the left menu.
bl e
3. Click Create Load Balancer. Select Load Balancer as the Load Balancer Type and then
ra
sfe
click Create Load Balancer towards the bottom of the window.
an
4. In the Add Details section:
-tr
. non
a. Load Balancer Name: IAD-DOP-LAB04-1-LB-01
d. Under Bandwidth Shapes: Select Flexible shapes. Choose 10Mbps as both the
us il.c
1)
.d
g. Click Next.
Dr
52 Replicate an existing Load Balancer using terraform configuration scripts and OCI Resource manager
c. Select the servers created in the Configuration Management and Infrastructure as
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Code: Deploy a web app to multiple compute instances (Lab02-1) Lab as backends
and click Add Selected Backends:
• IAD-DOP-LAB02-1-VM-01
• IAD-DOP-LAB02-1-VM-02
se
d. Specify Health Check Policy: Leave the values as default.
en
e. Leave Use SSL option deselected.
lic
bl e
f. Click Next.
ra
6.
sfe
In the Configure Listener section:
an
a. Listener Name: IAD-DOP-LAB04-1-LST-01
-tr
. non
b. Specify the type of traffic your listener handles: Select HTTP
c.
ide a
Specify the port your listener monitors for ingress traffic: 80
Gu as
d.
is ) h
Click Next.
e om
8. Click Submit.
r
.d
9. Once the Load Balancer is in Active state, copy its Public IP Address.
e
an
(ri
Launch a Web browser, paste the copied IP address in the address bar and press Enter.
E
AN
Replicate an existing Load Balancer using terraform configuration scripts and OCI Resource manager 53
Generate Terraform Script with Resource Manager
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
You will create a stack in Resource Manager based on your assigned compartment. You’ll use
this stack to generate a Terraform configuration that describes the compartment's resources
(Load Balancer). Finally, you’ll update the Terraform file to use it to replicate the Load
Balancer.
se
Create a Stack from Existing Infrastructure
en
lic
1. Open the navigation menu and click Developer Services. Under Resource Manager, click
bl e
Stacks.
ra
sfe
2. Select your <assigned compartment> from List scope on the left menu.
an
3. Click Create stack.
-tr
. non
a. Under Choose the origin of the Terraform configuration, select Existing
compartment.
ide a
Gu as
b. In the Stack configuration section:
is ) h
e om
2)
th
c. Make sure that the Use custom Terraform provider option under Custom providers
(ri
is not selected.
E
AN
g. Click Next to progress from Stack information to Configure variables. There will be
no variables to configure.
54 Replicate an existing Load Balancer using terraform configuration scripts and OCI Resource manager
h. Click Next to progress from Configure variables to Review. Confirm that the only
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
i. Click Create.
4. Wait for the stack to finish creating. It will query Load Balancer service in your assigned
compartment.
se
en
Download Terraform Configuration
lic
bl e
1. You are on the Stack details page of your Stack IAD-DOP-LAB04-1-STK-01.
ra
2. Under the Stack information tab, click the download link for the Terraform
sfe
configuration to download the configuration on your local machine.
an
3.
-tr
This will download a .ZIP file containing three files. Extract the .ZIP file.
. non
Note: For Mac users, use the command-line utility. For example,
% unzip filename.zip -d terraform-lb
ide a
Gu as
is ) h
e om
us il.c
th
• load_balancer.tf
@
• provider.tf
iss
• vars.tf
r
.d
5. Open load_balancer.tf. Scroll through the code and identify different resource
e
an
creation blocks.
(ri
compartment_id = var.compartment_ocid
iss
defined_tags = {
Dr
"Oracle-Tags.CreatedBy" = "prateek_devops"
"Oracle-Tags.CreatedOn" = "2022-11-10T09:48:38.235Z"
}
display_name = "IAD-DOP-LAB04-1-LB-01"
freeform_tags = {
}
Replicate an existing Load Balancer using terraform configuration scripts and OCI Resource manager 55
ip_mode = "IPV4"
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
is_private = "false"
network_security_group_ids = [
]
#reserved_ips = <<Optional value not found in discovery>>
shape = "flexible"
shape_details {
se
maximum_bandwidth_in_mbps = "10"
en
minimum_bandwidth_in_mbps = "10"
lic
}
bl e
subnet_ids = [
ra
"ocid1.subnet.oc1.iad.aaaaaaaagzgdcge7ccqmjaiwyxxxxxxw65wmyy7lgr
sfe
3sdfhjysmjmz4xxxxx",
an
]
}
-tr
...
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
riss
e .d
an
(ri
E
AN
RI
iss
Dr
56 Replicate an existing Load Balancer using terraform configuration scripts and OCI Resource manager
Edit Auto-Generated Terraform Script
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Before you can reupload the Terraform configuration generated by resource discovery, there
are a few fields that you need to edit.
Tasks
se
1. In the load_balancer.tf file, find the resource block of type
en
oci_load_balancer_load_balancer.
lic
bl e
2. Locate and edit the value of display_name variable to IAD-DOP-LAB04-1-LB-02. This
ra
is the name for the new load balancer to be provisioned.
sfe
The file should look like this:
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
Replicate an existing Load Balancer using terraform configuration scripts and OCI Resource manager 57
Provision Infrastructure Based on the Auto-Generated
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Terraform Configuration
You will provision the Load Balancer from your Terraform configuration.
se
en
1. Open the navigation menu and click Developer Services. Under Resource Manager, click
lic
Stacks.
bl e
2. Select your <assigned compartment> from List scope on the left menu.
ra
sfe
3. Click Create stack.
an
a. Under Choose the origin of the Terraform configuration, select My configuration.
-tr
. non
b. In the Stack configuration section, select Folder as the source, and upload the
extracted folder containing vars.tf, provider.tf, and load_balancer.tf.
ide a
Gu as
c. Make sure that the Use custom Terraform provider option under Custom providers
is ) h
is not selected.
e om
compartment.
e .d
an
g. Click Next to progress from Stack information to Configure variables. Verify the
(ri
2) region: The region you’re working in. Here we have assumed us-ashburn-1.
iss
h. Click Next to progress from Configure variables to Review. Check the Run apply
Dr
box.
i. Click Create. This will take you to the stack’s details page.
58 Replicate an existing Load Balancer using terraform configuration scripts and OCI Resource manager
4. After the Apply job finishes executing, open the navigation menu, click Networking, and
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
5. You will notice a new load balancer has been provisioned by the name IAD-DOP-LAB04-
1-LB-02.
6. Once the Load Balancer is in Active state, copy its Public IP Address.
se
en
Launch a Web browser, paste the copied IP address in the address bar and hit Enter.
lic
You will see a webpage that looks like this:
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
Congratulations! You created a Load Balancer manually and added backend servers to it. You
to gma
then created a Terraform configuration stack for this load balancer using Resource Manager.
@
Further you reused the Terraform configuration stack to replicate the existing Load Balancer.
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
Replicate an existing Load Balancer using terraform configuration scripts and OCI Resource manager 59
Purge Instructions
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
1. Open the navigation menu and click Developer Services. Under Resource Manager, click
Stacks to go to the list of available stacks.
se
2. Select your <assigned compartment> from List scope on the left menu.
en
lic
3. Click the name of the first stack you created IAD-DOP-LAB04-1-STK-01 to go to its
bl e
details page.
ra
a. Click Destroy.
sfe
an
b. Wait for the destroy job to finish. Then click Stack details in the breadcrumbs menu
-tr
to go back.
. non
c. Click More actions, then click Delete stack. Click Delete to confirm. This will take you
back to the list of available stacks.
ide a
Gu as
is ) h
d. Open the navigation menu, click Networking, and then click Load Balancers. You will
e om
4. Click the name of the second stack you created IAD-DOP-LAB04-1-STK-02 to go to its
th
to gma
details page.
@
a. Click Destroy.
iss
b. Wait for the destroy job to finish. Then click Stack details in the breadcrumbs menu
r
.d
to go back.
e
an
c. Click More actions, then click Delete stack. Click Delete to confirm. This will take you
(ri
d. Open the navigation menu, click Networking, and then click Load Balancers. You will
RI
1. Open the navigation menu and click Compute. Under Compute, click Instances.
2. Select your <assigned compartment> from the List scope on the left menu.
60 Replicate an existing Load Balancer using terraform configuration scripts and OCI Resource manager
3. For each of the instances IAD-DOP-LAB02-1-VM-01 and IAD-DOP-LAB02-1-VM-02,
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
click the three dots on the right to open the Actions menu.
4. Click Terminate and select Permanently delete the attached boot volume.
se
Purge Instructions for Virtual Cloud Network
en
lic
1. Open the navigation menu, click Networking, and then click Virtual Cloud Networks.
bl e
2. Select your <assigned compartment> from List scope on the left menu.
ra
sfe
3. From the list of VCNs, select IAD-DOP-LAB02-1-VCN-01.
an
4. Click Delete.
-tr
. non
a. Keep Search compartments for resources associated with this VCN selected.
d. Click Scan.
us il.c
th
to gma
e. Once the scan completes, click Delete All to terminate the VCN and related
resources.
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
Replicate an existing Load Balancer using terraform configuration scripts and OCI Resource manager 61
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
62
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
Replicate an existing Load Balancer using terraform configuration scripts and OCI Resource manager
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
. non
-tr
Overview
The Oracle Cloud Infrastructure (OCI) Resource Manager is a fully managed service that lets
you provision infrastructure resources on OCI using Terraform. You can bring in your
se
Terraform template definition and easily create and manage your infrastructure resources.
en
This allows you to automate provisioning and management of OCI resources such as
lic
Compute, Networking, Storage, IAM, and so on using infrastructure-as-code.
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
• Destroy job.
E
AN
For more information on OCI Resource Manager, see the OCI Resource Manager
RI
Documentation.
iss
Prerequisites
Dr
Dr
iss
Assumptions
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
sfe
ra
bl e
lic
en
se
65
Create SSH Keys Using Cloud Shell
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Cloud Shell is a small virtual machine running a bash shell which you access from within the
OCI Console. In addition to a preauthenticated OCI CLI (Command Line Interface) set to the
Console tenancy home page region, Cloud Shell comes preinstalled with current versions of
many useful tools and utilities such as Git, Java, Python, kubectl, terraform, Docker engine,
se
and so on.
en
Task
lic
bl e
1. Sign in to your Oracle Cloud Infrastructure (OCI) account.
ra
sfe
2. Open Cloud Shell.
an
3. Once the Cloud Shell session is initiated, move to the .ssh directory.
-tr
$ cd ~/.ssh
. non
4. Create new public and private keys.
ide a
$ ssh-keygen -b 2048 -o -t rsa -f key-lab05-<userID>
Gu as
is ) h
Where,
e om
key-lab05-<userID> is the keyname. Replace <userID> with your user ID. You will
us il.c
For example,
$ ssh-keygen -b 2048 -o -t rsa -f key-lab05-user22
@
iss
Note: A passphrase is an additional layer of security. It protects your private key from
e
an
6. List the two key files (public and private key) that you just created.
E
AN
$ ls
RI
In the output, two files are listed, a private key: key-lab05-user22 and a public
iss
key: key-lab05-user22.pub. You will see these two files with your user ID in place of
Dr
user22.
You must keep the private key safe and never share it with anyone.
$ cat key-lab05-<userID>.pub
For example,
$ cat key-lab05-user22.pub
You will see a random string like the one below as the output:
se
ssh-rsa
en
XXXXB3NzaC1yc2EAAAADAQABAAABAQCdQ9+4JM9GxCWPIDGFjO1tk4jkumO2zbhA1Za
lic
ePxEGKwSFDEw/De7HU6wRh+Jbutkw9tOzlUr8FgAGNRgyWgaHbj5YX0h+LXWlrIiTtB
FpZkMYlMwJUAFTmMwWy12rGYeUD/Ba+KVlEYaMT1XY0DCa+SFyq48uWQwgQns8654Uy
bl e
cwFzFsXvZvA1i48Mk63vuSTAw15vGLXXXXXX0jegHOhMGrNMRuE4eMKSECP+CDFFgKb
ra
2oCzFz8KwywFuDciHAbMZru5qkiFGomeBvClDEU2BfMOV7k69kfivoxHHlnwxwgJulM
sfe
eXrMLsE1/osZcy5s2Eon3WmxJqo1wKYX5M5Z1 mahendra_E@3c15a0xxxxxx
an
8. Copy the contents of the public key and save it to your notepad. Later, when pasting the
-tr
key into the compute instance, make sure you remove any hard returns that may have
. non
been added when copying.
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
A Stack represents the definitions for a collection of OCI resources within a specific
compartment.
You’re going to configure a new stack in your assigned compartment and name it "HA Load
Balanced Simple Web App". As the stack's name suggests, the configuration files define a load
se
balancer, network, and compute resources to deploy the target architecture along with a HTTP
en
server.
lic
bl e
Tasks
ra
sfe
1. Download HA Load Balanced Simple Web App and save to your local machine.
an
2. In the Console, open the navigation menu and click Developer Services. Under Resource
-tr
Manager, select Stacks.
. non
3. Select your <assigned compartment> from List scope on the left menu.
ide a
Gu as
4. Click Create Stack.
is ) h
e om
6. Click Browse and select the orm-lbcs-demo-main.zip file from your local machine to
th
to gma
upload.
@
7. Make sure that the Use custom Terraform provider option under Custom providers is
iss
not selected.
r
.d
• Name: IAD-DOP-LAB05-1-STK-01
(ri
9. Click Next to configure variables for the infrastructure resources that this stack creates
when you run the apply job for this execution plan.
• Select a Flex Load Balancer with Minimum and Maximum Bandwidth: 10Mbps for
both minimum and maximum bandwidth
• Select Compute Shape: VM.Standard.A1.Flex
• Select Availability Domain: 1
• SSH Key Configuration: Select Paste ssh keys and paste the public key key-
se
lab05-<userID>.pub contents copied earlier in your notepad.
en
lic
• Virtual Cloud Network Configuration:
bl e
− Enter your VCN Name: VCN01
− Enter your CIDR Block: 10.0.0.0/16
ra
sfe
− Enter your Subnet Name: Subnet
an
10. Click Next. Verify your configuration variables.
-tr
. non
11. Leave the Run apply deselected and click Create.
Jobs perform actions against the Terraform configuration files associated with a stack. You
can perform three actions: Plan, Apply and Destroy.
Since Terraform command execution is not atomic, it is crucial to prevent any race conditions
or state corruption from occurring due to parallel execution. To prevent this from happening,
se
the Resource Manager ensures only one job can run against a stack at a given time against a
en
single state file.
lic
bl e
You can completely manage the stack's configuration (that is, update, delete, add tags, edit
ra
variables), and download the zip archive containing the latest Terraform configuration from
sfe
the Stack details page.
an
Tasks
-tr
. non
Run a Plan Job
1. ide a
The stack itself is only a bookkeeping resource, no infrastructure is provisioned yet. From
Gu as
the stack’s page, click Plan. A form will pop up.
is ) h
e om
b. Click Plan again at the bottom to submit a job for Resource Manager to run
to gma
terraform plan. This will take you to the job’s details page.
@
2. Wait for the job to complete, and then view the logs. They should match what you saw when
iss
1. Go back to the stack’s details page (use the breadcrumbs) and click Apply. A form will pop
E
up.
AN
b. Under Apply job plan resolution, select the plan job we ran, that is RM-Plan-01
Dr
(instead of “Automatically approve”). This makes it execute based on the previous plan,
instead of running a new one.
c. Click Apply to submit a job for Resource Manager to run terraform apply. This will
take you the job’s details page.
Note: Once the window closes, notice the job's state appears as Accepted - which
indicates that the platform is spinning up resources needed for executing the command,
followed by In Progress and then finally either Succeeded or Failed.
3. Once the apply job succeeds, you can check the provisioned resources have been
se
provisioned by reading the Terraform output contained within the logs.
en
lic
View the Provisioned Resources
bl e
1. You can also view the provisioned resources by navigating to the services page.
ra
sfe
a. Open the navigation menu. Under Compute, click Instances and select your
an
<assigned compartment> from List scope on the left menu.
-tr
You will see the two instances provisioned by the apply job with the names IAD-DOP-
. non
LAB05-1-VM-01 and IAD-DOP-LAB05-1-VM-02.
ide a
Gu as
b. Open the navigation menu. Under Networking, click Virtual Cloud Networks and
is ) h
select your <assigned compartment> from List scope on the left menu.
e om
You will see the VCN IAD-DOP-LAB05-1-VCN-01 provisioned by the apply job. Click
us il.c
c. Open the navigation menu. Under Networking, click Load Balancers and select your
@
You will see the Load Balancer IAD-DOP-LAB05-1-LB-01 provisioned by the apply
r
.d
job. The Health Status of the Load Balancer will need a few minutes to get into OK
e
an
status.
(ri
2. As the Load Balancer changes state to Active, copy it’s Public IP Address and paste it
E
AN
You will reach the sample webpage as shown below. The webpage body displays the
iss
private IP Address of the web server you are connected to. If you refresh the webpage a
Dr
few times, the web server IP changes, indicating that the Load Balancer is balancing the
traffic between the two web servers.
se
3. You can also see the Load Balancer in action using Cloud Shell. Run the following
en
command:
lic
$ for counter in {1..10}; do curl http://<LBPublicIPAddress>/;
bl e
done
ra
sfe
Here, replace <LBPublicIPAddress> with the IP Address you copied in the previous
step, for example,
an
$ for counter in {1..10}; do curl http://129.X.X.47/; done
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
You will notice the curl requests are served alternatively by two backend servers. Observe
@
the different private IPs of Web Server the page is being fetched from.
iss
4. Let’s test the SSH connection to the backend web servers using the private key key-
r
.d
$ cd ~/.ssh
E
AN
instance:
iss
Where,
For example,
$ ssh -i key-lab05-user22 opc@140.x.10.x
se
en
When prompted type ‘yes’ and you should be able to SSH into the “IAD-DOP-LAB05-
lic
1-VM-01” compute instance.
bl e
c. To come out of the SSH session, type exit
ra
$ exit
sfe
an
You can repeat the above steps to test SSH connection for the “IAD-DOP-LAB05-1-VM-02”
-tr
compute instance.
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
You have successfully applied the Resource Manager Stack configuration to provision OCI
resources. Let's now revisit the Stack details page and use the destroy job to tear it all down.
Tasks
se
1. In the Console, open the navigation menu and click Developer Services. Under Resource
en
Manager, select Stacks.
lic
bl e
2. Select your <assigned compartment> from List scope on the left menu.
ra
sfe
3. On the Stacks page, click the stack you created IAD-DOP-LAB05-1-STK-01.
an
4. On the Stack details page, click Destroy to initiate a destroy job.
-tr
. non
5. Provide job name as RM-Destroy-01. Click Destroy.
ide a
Note: Once the window closes, notice the job's state appears as Accepted - which
Gu as
indicates that the platform-deleting resources needed for executing the command,
is ) h
6. Once the delete job succeeds, you can verify the resources provisioned by the apply job
us il.c
th
are deleted.
to gma
7. You can also check the resources are no longer available by navigating to the services
@
page.
iss
a. Open the navigation menu. Under Compute, click Instances and select your
r
.d
b. Open the navigation menu. Under Networking, click Virtual Cloud Networks and
RI
select your <assigned compartment> from List scope on the left menu.
iss
You will see the VCN IAD-DOP-LAB05-1-VCN-01 has been deleted by the destroy
Dr
job.
You will see the Load Balancer IAD-DOP-LAB05-1-LB-01 has been deleted by the
destroy job.
Congratulations! You have successfully provisioned a high availability load balanced sample
se
application using the Resource Manager Stack configuration and executed the destroy job to
en
terminate the OCI resources provisioned by the apply job.
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
1. In the Console, open the navigation menu and click Developer Services. Under Resource
Manager, select Stacks.
se
2. For the stack IAD-DOP-LAB05-1-STK-01, click the three dots on the right to open the
en
Actions menu. Select Delete and then click Delete to confirm.
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
. non
-tr
Lab 06-1 Practices
an
sfe
ra
Using Dockerfile
Overview
There are certain ways for creating, running, and deploying applications in containers using
Docker. A Docker image contains application code, libraries, tools, dependencies, and other files
se
needed to make that application run.
en
In this lab, you will create a Docker image using a Dockerfile, which will further be used to build a
lic
container that can run on the Docker platform.
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
b.
@
Assumptions
iss
Dr
• You are signed in to your Oracle Cloud Infrastructure (OCI) account using your
credentials.
• You have access to the Git repository link that contains the Dockerfile.
• You will replace the <userID> placeholder with your user ID.
Access the Dockerfile needed to generate the Docker image by cloning a Git repository.
Tasks
se
en
2. Within Cloud Shell, clone the GitHub repository to access the sample Dockerfile which is a
lic
simple Nginx HelloWorld application that you will use to build the Docker image.
bl e
ra
$ cd ~
sfe
$ git clone https://github.com/ou-developers/docker-helloworld-demo
an
-tr
3. Navigate to the cloned directory.
. non
$ cd docker-helloworld-demo/
4. ide a
Open Code Editor. Code Editor allows you to view the files and source codes present in the
Gu as
home directory within the Cloud Shell terminal.
is ) h
e om
The tool bar is on the left side of the Code Editor window. Click the Explorer (top) icon from
the left-side menu within the Code Editor window.
us il.c
th
to gma
Browse to the cloned Git directory “docker-helloworld-demo” to view the various files
you have in the directory including application code and Dockerfile for creating the sample
@
Nginx application.
riss
e .d
an
(ri
E
AN
RI
iss
Dr
You’re using Cloud Shell as your development environment which comes preinstalled with
Docker.
Tasks
se
1. Check the Docker version using the following command in Cloud Shell. It will return a string
en
with the Docker version installed.
lic
$ docker -v
bl e
For example, Docker version 19.03.11-ol, build 9bb540d
ra
sfe
2. Check for existing Docker images in the Cloud Shell.
$ docker images
an
-tr
It will return an empty response because there are no docker images at present.
. non
3. Create a docker image for the sample Web Application using the docker build
ide a
command. This command needs Dockerfile as one of its parameters.
Gu as
$ docker build -t oci_sample_webapp_<userID>:<tag> .
is ) h
e om
For example,
$ docker build -t oci_sample_webapp_user22:1.0 .
us il.c
th
to gma
Where,
• -t is the switch used to specify the image name.
@
• A tag is used to give the image a version. In this lab, you will use 1.0 as tag.
(ri
• You are currently in the cloned directory which contains the Dockerfile. Use “.” as the
E
4. Upon successful build of a Docker image, verify the image in the local repository using the
iss
following command:
$ docker images
Dr
You’ll see two entries in the output. One is the base image “nginx”, and the other is the
custom Docker image for the Web Application “oci_sample_webapp_<userID>”.
Your Docker image holds the application that you want Docker to run as a container.
Tasks
1. Use the docker run command to spin a container based on the image created.
se
$ docker run -d --name webapp-<userID> -p 80:80/tcp
en
oci_sample_webapp_<userID>:<tag>
lic
bl e
Where,
ra
• -d flag is used to run container in background and print CONTAINER_ID.
sfe
• --name flag is used to assign a name to the container.
an
• -p flag is used to publish container port 80 to the host machine port 80.
-tr
• Replace <userID> with your user ID.
. non
For example,
ide a
$ docker run -d --name webapp-user22 -p 80:80/tcp
Gu as
oci_sample_webapp_user22:1.0
is ) h
Note: This command returns the CONTAINER_ID of the container started in the
e om
background.
us il.c
th
to gma
2. Check the container that is currently running using the docker ps command.
$ docker ps
@
iss
You will see a container running with the name webapp-<userID> and a corresponding
CONTAINER_ID.
r
e .d
an
(ri
E
AN
RI
iss
Dr
Container
Verify whether you can access the web application that is running in your container. Once you
have verified, stop the running container.
se
Tasks
en
lic
1. Use the curl command to connect to the local host on port 80 to access the web
bl e
application.
$ curl -k http://127.0.0.1:80
ra
sfe
The output must display the webpage code. This confirms that your web application is up
an
and running.
-tr
2. Get the CONTAINER_ID and copy it on a notepad to use it in your next step.
. non
$ docker ps -a
ide a
Gu as
3. Stop the running container.
is ) h
For example,
us il.c
4. Use the curl command to connect to the localhost on port 80 to access the web application.
$ curl -k http://127.0.0.1:80
@
iss
Connection refused
e.d
an
This time output will return the above mentioned error, because the container running the
(ri
Tasks
se
$ docker ps -a
en
lic
The status for the container must show exited which means the container is stopped.
bl e
2. Delete the existing container using the rm flag.
ra
$ docker rm webapp-<userID>
sfe
an
For example,
-tr
$ docker rm webapp-user22
. non
Output: webapp-user22
ide a
Gu as
Note: On successful deletion it’ll return the container name.
is ) h
$ docker ps -a
us il.c
th
Important Note: Do not delete the Docker image created in this lab, because it will be used
@
84
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
. non
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
. non
-tr
Lab 07-1 Practices
an
sfe
ra
Using Docker CLI
Overview
The development to production workflow can be made simpler with the help of an Oracle-
managed registry. For developers, Container Registry makes it simple to store, share, and
se
manage container images (such as Docker images).
en
In this lab, you will create a Container Registry and will also perform some basic operations
lic
such as push and pull a Docker image.
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
c. Sign in to Oracle Cloud Infrastructure Registry (OCIR) from the Cloud Shell.
(ri
E
For more information on Oracle Cloud Infrastructure Registry (OCIR), see the OCI Container
Registry Documentation.
86 Manage OCIR and push and pull images using Docker CLI
Prerequisites
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
• You must complete the following lab to use the same Docker image
“oci_sample_webapp_<userID>” to perform tasks for this practice:
− Microservice and Container Orchestration: Create Docker image for a web
application using Dockerfile (Lab06-1).
se
Assumptions
en
lic
• You are signed in to your Oracle Cloud Infrastructure account using your credentials.
bl e
• You will replace the <userID> placeholder with your user ID.
ra
• You will replace the <tenancy-namespace> and <username> values from the info
sfe
given in the Profile menu.
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
Manage OCIR and push and pull images using Docker CLI 87
Create an Auth Token
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Create an auth token to use with Oracle Cloud Infrastructure Registry (OCIR).
Tasks
1. In the top-right corner of the OCI Console, open the Profile menu, and then click User
se
Settings.
en
lic
2. On the Auth Tokens page, click Generate Token.
bl e
Note: Each user can only have two auth tokens at a time.
ra
sfe
3. Enter IAD-DOP-LAB07-1-AT-01, as a friendly description for the auth token.
an
-tr
4. Click Generate Token. The new auth token is displayed. Here’s a sample of how an auth
. non
token looks like: R5kwpS-xxxxx((]51r]]. It’ll be different in your case.
ide a
Note: Copy the auth token to a notepad because you won't see the auth token again in
Gu as
the Console. You’ll need this auth token later in this and other labs.
is ) h
For example,
e om
R5kwpS-xxxxx((]51r]]
us il.c
th
5.
to gma
Click Close.
@
riss
e.d
an
(ri
E
AN
RI
iss
Dr
88 Manage OCIR and push and pull images using Docker CLI
Create a New Container Repository
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Create an empty repository in a compartment and give it a name that's unique across all
compartments in the tenancy. Having created the new repository, you can push an image to
the repository using the Docker CLI.
Tasks
se
en
1. Check if you can access Oracle Cloud Infrastructure Registry (OCIR):
lic
bl e
a. In the Console, open the navigation menu and click Developer Services. Under
ra
Containers & Artifacts, click Container Registry.
sfe
b. Select your <assigned compartment> from List scope on the left menu.
an
-tr
c. Review the repositories that already exist. This lab assumes that no repositories have
. non
been created yet.
1/oci_sample_webapp_<userID>
th
to gma
Where,
@
• <region-key> is the key for the Oracle Cloud Infrastructure Registry region you're
iss
using. For example, iad is the region key for US EAST (Ashburn) region. See the
r
.d
Manage OCIR and push and pull images using Docker CLI 89
Sign In to OCIR from the Cloud Shell
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Once you have generated the auth token and created a new repository, sign in to Oracle Cloud
Infrastructure Registry (OCIR) from Docker CLI in the cloud shell.
Tasks
se
1. Open Cloud Shell.
en
lic
Note: The OCI CLI running in the Cloud Shell will execute commands against the region
bl e
selected in the Console's region selection menu when the Cloud Shell was started.
ra
2.
sfe
In the Cloud Shell, log in to OCIR by entering:
$ docker login <region-key>.ocir.io
an
-tr
For example,
. non
$ docker login iad.ocir.io
3.
ide a
When prompted, enter your username in the format given below.
Gu as
is ) h
<tenancy-namespace>/<username>.
e om
And for username use the username as shown in the profile menu. For
iss
Note that for some older tenancies, the namespace string might be the same as the
an
If your tenancy is federated with Oracle Identity Cloud Service, use the format <tenancy-
E
AN
namespace>/oracleidentitycloudservice/<username>.
RI
Enter the auth token IAD-DOP-LAB07-1-AT-01 (random string) you copied earlier as the
iss
password.
Dr
For example,
R5kwpS-xxxxx((]51r]]
90 Manage OCIR and push and pull images using Docker CLI
Note: When you enter or paste the password, you’ll not see masked characters. Press
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Enter on your keyboard to continue and you should see the “Login Succeeded”
message on the screen.
se
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
Manage OCIR and push and pull images using Docker CLI 91
Tag the Docker Image
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
A tag identifies the Oracle Cloud Infrastructure Registry (OCIR) region, tenancy, and repository
to which you want to push the image.
se
a web application using Dockerfile (Lab06-1).
en
lic
Tasks
bl e
ra
1. In the Cloud Shell, run the following command to attach a tag to the image that you're
sfe
going to push to OCIR repository:
an
$ docker tag oci_sample_webapp_user22:1.0
<region-key>.ocir.io/<tenancy-namespace>/<repo-name>:<tag>
-tr
. non
Where,
• <region-key> is the key for the Oracle Cloud Infrastructure Registry region you're
ide a
Gu as
using. For example, iad is the region key for US EAST (Ashburn) region. See the
is ) h
the tenancy (as shown on the Tenancy Information page) to which you want to push
the image, for example, oracletenancy.
@
• <repo-name> is the name of the target repository to which you want to push the
iss
• <tag> is an image tag you want to give the image in Oracle Cloud Infrastructure
e
For example,
E
iad.ocir.io/oracletenancy/iad-dop-lab07-1-ocir-
1/oci_sample_webapp_user22:latest
RI
iss
$ docker images
Note: Although two tagged images will be shown (1.0 and latest), both are based on
the same base image with the same IMAGE_ID.
92 Manage OCIR and push and pull images using Docker CLI
Push the Tagged Docker Image to OCIR Repository
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
After assigning a tag to the image, you use the Docker CLI to push it to Oracle Cloud
Infrastructure Registry repository.
Tasks
se
1. In the Cloud Shell, run the following command to push the tagged Docker image to OCIR
en
repository:
lic
$ docker push <region-key>.ocir.io/<tenancy-namespace>/<repo-
bl e
name>:<tag>
ra
For example,
sfe
$ docker push iad.ocir.io/oracletenancy/iad-dop-lab07-1-ocir-
an
1/oci_sample_webapp_user22:latest
-tr
. non
You will see the different layers of the image are pushed in turn and it prints the sha256
digest along with the size of the image on the screen.
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
Manage OCIR and push and pull images using Docker CLI 93
Verify if the Image Has Been Pushed
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Verify if the image has been pushed successfully to the OCIR repository.
Tasks
1. Go back to the OCIR Service page and select your <assigned compartment> from List
se
scope on the left menu.
en
lic
2. You’ll see the private repository iad-dop-lab07-1-ocir-
bl e
1/oci_sample_webapp_<userID> that you created.
ra
sfe
3. Click the name of the repository that contains the image you just pushed from the
dropdown menu under label Repositories and images. You’ll see:
an
• An image with the tag latest.
-tr
. non
• A summary page that shows you the details about the repository, including who
created it and when, its size, and whether it's a public or a private repository.
ide a
Gu as
4. Click the image tag latest from the dropdown menu
is ) h
On the Summary page, you’ll see the image size, when it was pushed and by which user,
e om
image sha256 digest, and the number of times the image has been pulled.
us il.c
th
to gma
@
r iss
e.d
an
(ri
E
AN
RI
iss
Dr
94 Manage OCIR and push and pull images using Docker CLI
Pull the Image from OCIR Repository
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Perform pull operation after deleting the existing images from the local docker repository. You
will pull the same image that was previously pushed to the OCIR repository.
Tasks
se
1. Delete the existing images from the local docker repository.
en
lic
a. In the Cloud Shell, list all the images.
bl e
$ docker images
ra
sfe
b. Run docker rmi command to delete the tagged image and the original image you
an
created earlier.
-tr
$ docker rmi oci_sample_webapp_user22:1.0
. non
Output: Untagged: oci_sample_webapp_user22:1.0
ide a
Gu as
$ docker rmi iad.ocir.io/oracletenancy/iad-dop-lab07-1-ocir-
is ) h
1/oci_sample_webapp_user22:latest
e om
This command will first untag the image and delete the image by deleting all the
us il.c
associated layers.
th
to gma
$ docker images
iss
3. Switch to the OCI Console. From the OCIR page, select the repository and the image tag
r
.d
4. Click the Actions menu on the image summary page and select Copy pull command
(ri
from the drop-down list. The command you copy includes the fully qualified path to the
E
<region-key>.ocir.io/<tenancy-namespace>/<repo-name>:<tag>
iss
5. Execute the copied command in the Cloud Shell to pull the image to the local repository.
Dr
For example,
$ docker pull iad.ocir.io/oracletenancy/iad-dop-lab07-1-ocir-
1/oci_sample_webapp_user22:latest
Manage OCIR and push and pull images using Docker CLI 95
6. Verify the pulled image from OCIR repository.
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
$ docker images
You should see the pulled image listed within the local repository.
se
Important Note: Do not delete any artifacts and resources created in this lab because
en
they will be required in the upcoming labs.
lic
Congratulations! you have successfully pushed and pulled an image from the OCIR repository.
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr
96 Manage OCIR and push and pull images using Docker CLI
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
. non
Lab 08-1 Practices -tr
an
Cluster Access
sfe
ra
bl e
Microservices and
lic
en
se
Orchestration: Set Up OKE
Get Started
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Overview
A Kubernetes cluster is a group of nodes (machines running applications). Each node can be a
physical machine or a virtual machine.
se
You need to set up access to your Kubernetes cluster to deploy your application. The kubectl
en
command-line client is a versatile way to interact with a Kubernetes cluster, including
lic
managing multiple clusters.
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
b.
r
.d
For more information on OCI Container Engine for Kubernetes (OKE), see the OCI Container
e
Engine Documentation.
an
(ri
Assumptions
E
AN
• You are signed in to your Oracle Cloud Infrastructure (OCI) account using your
RI
credentials.
A pre-created OKE cluster <EventID>-OCI-ELS-DEVOPS-OKE is available in the root
iss
•
compartment. <EventID> can be fetched from the Lab tab available in the course
Dr
page.
Example : If your User Name is 99241291-lab.user02, then EventID is 99241291.
The pre-created OKE cluster will be named as 99241291-OU-DEVELOPER-OKE.
• You will replace the <userID> placeholder with your user ID.
To access a cluster using kubectl, you must set up a Kubernetes configuration file
(commonly known as the kubeconfig file) for the cluster. The kubeconfig file provides the
necessary details to access the cluster.
Tasks
se
en
In the Console, open the navigation menu and click Developer Services. Under
lic
1.
Containers and Artifacts, click Kubernetes Clusters (OKE).
bl e
ra
2. Select root compartment from List Scope on the left menu.
sfe
In the table listing Clusters, click the cluster <EventID>-OCI-ELS-DEVOPS-OKE to access
an
using kubectl. The Cluster details page shows information on the cluster.
-tr
. non
Note: <EventID> can be fetched from the Lab tab available in the course page.
ide a
Click Access Cluster to display the Access Your Cluster window.
Gu as
3.
is ) h
4. Click Cloud Shell Access and copy the command to access the kubeconfig for your
e om
Launch Cloud Shell and run the copied command. On successful execution, it will return a
to gma
5.
new config written to kubeconfig file.
@
For example,
iss
ocid1.cluster.oc1.iad.xxxxxaaaziwdigokvlwhuaeslgxi6tdk473xqgodcb
e
Note: This is just a representation of the command. Do not use this command to connect
E
Having set up the kubeconfig file, you can start using kubectl to access the cluster by
creating a sample deployment in OKE cluster.
Tasks
se
Verify that kubectl can connect to the cluster.
en
1.
lic
$ kubectl get nodes
bl e
This will return the IP addresses of three worker nodes set up within this OKE cluster.
ra
Create namespace in your Kubernetes cluster to manage your resources.
sfe
2.
$ kubectl create ns ns-<userID>
an
-tr
Where,
. non
• ns-<userID> - is a unique namespace for your group of resources within a cluster.
• Replace <userID> with your user ID.
ide a
Gu as
For example.
is ) h
$ kubectl cluster-info
image=iad.ocir.io/ocuocictrng5/httpd:latest -n ns-<userID>
an
(ri
Where,
• kubectl create deployment - is used to create a pod with a single running
RI
container.
iss
• image=iad.ocir.io/ocuocictrng5/httpd:latest
• -n ns-<userID> - is the namespace where your Kubernetes objects are created.
5. Expose your deployment using service of type load balancer by using the following
command.
$ kubectl expose deployment deploy-<userID> --type=LoadBalancer
se
--name=svc-<userID> --port=80 --target-port=80 -n ns-<userID>
en
Where,
lic
• deploy-<userID> - is a name for your deployment.
bl e
• --type=LoadBalancer - exposes the service externally using an OCI load
ra
sfe
balancer.
• svc-<userID> - is the name for your service.
an
-tr
• --port=80 --target-port=80 - is used to expose the application running within
. non
the cluster on port 80.
• ns-<userID> - is the namespace where your Kubernetes objects are created.
ide a
Gu as
For example,
is ) h
The output of this command will be a row with the deployment name and ready column
r
.d
set to 1/1. The age column determines the duration of the deployment created.
e
an
The output of this command will be a row with the pod name and ready column set to 1/1.
RI
The output of this command is a row with service name and type set to Load Balancer. It
shows you the details of CLUSTER-IP and EXTERNAL-IP.
se
en
The output of this command should display the replicaset name. The desired and current
lic
columns specify the number of replicas running. Age column determines the duration of
bl e
replica created.
ra
11. Scale up the current replicas by three so that Kubernetes can start new pods to scale up
sfe
your service.
an
$ kubectl scale --replicas=3 deployment/deploy-<userID> -n ns-
-tr
<userID>
. non
On successful execution, this command will return “deployment.apps/deploy-
<userID> scaled”.
ide a
Gu as
is ) h
This shows that the Load Balancer service will now balance the incoming requests among
th
to gma
This command shows you all the pods, services, deployments, and replicaset running in
e
Notice that the pod count has changed to three after the previous scale-up instruction.
E
AN
14. View the pod logs. The kubectl logs command lets you inspect the logs for a particular
RI
pod.
iss
Where,
<podname> - is the complete pod name to be used from the output of kubectl get
all -n ns-<userID> command. For example, pod/deploy-user22-cd95b4455-
f8plr.
se
$ kubectl delete svc svc-<userID> -n ns-<userID>
en
lic
On successful execution, this command will display “service svc-<userID> deleted”.
bl e
17. Run the following command and you’ll not find any resources in your namespace.
ra
$ kubectl get all -n ns-<userID>
sfe
Output: No resources found in ns-<userID> namespace.
an
-tr
18. Because all the resources are deleted, if you go back to your browser and hit refresh on
. non
the IP address you pasted earlier, the page will no longer respond.
ide a
Gu as
is ) h
Important Note: Do not delete the namespace and entry created in the kubeconfig
e om
file in this lab, because they will be required in the upcoming labs.
us il.c
th
Congratulations! You have successfully deployed a sample web application to the OKE cluster.
to gma
@
riss
.d
e
an
(ri
E
AN
RI
iss
Dr
104
Dr
iss
RI
AN
E
(ri
an
e
Purge Instructions
.d
riss
@
to gma
us il.c
There are no purge instructions for this practice.
e om
th
is ) h
Gu as
ide a
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
kubectl
ide a
. non
-tr
en
se
Orchestration: Deploy a
Sample Web Application on
Microservice and Container
Get Started
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Overview
In this practice, you will create a named secret which contains your Oracle Cloud Infrastructure
(OCI) credentials and add them to a deployment manifest. You will then use this manifest to
se
deploy a sample Web application to an OKE cluster and later verify if the application is
en
accessible.
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
b. Add the secret and the image path to the deployment manifest.
(ri
For more information on OCI Container Engine for Kubernetes (OKE), see the OCI Container
Engine Documentation.
You will use the existing Docker image, OCIR repository, Auth token and Kubernetes
namespace from the previous labs to perform tasks for this practice:
• Microservice and Container Orchestration: Create Docker image for a web application
using Dockerfile (Lab06-1)
se
• Microservices and Container Orchestration: Create and work with OCIR repository
en
(Lab07-1)
lic
• Microservices and Container Orchestration: Set up cluster access (Lab08-1)
bl e
Assumptions
ra
sfe
• You are signed into your Oracle Cloud Infrastructure (OCI) account using your
an
credentials.
-tr
• A pre-created OKE cluster <EventID>-OCI-ELS-DEVOPS-OKE is available in the root
. non
compartment. <EventID> can be fetched from the Lab tab available in the course
page.
ide a
Gu as
Example : If your User Name is 99241291-lab.user02, then EventID is 99241291.
is ) h
• You will replace the <userID> placeholder with your user ID.
us il.c
th
to gma
@
riss
e .d
an
(ri
E
AN
RI
iss
Dr
To enable Kubernetes to pull an image from OCIR repository when deploying an application,
you need to create a Kubernetes secret. The secret contains all the login details you would
provide while logging in to OCIR using the docker login command, including your auth
token.
se
Tasks
en
lic
1. Open Cloud Shell.
bl e
ra
2. Run the following command to create a secret:
sfe
$ kubectl create secret docker-registry <name-of-secret>-<userID> -
-docker-server=<region-key>.ocir.io --docker-username=’<tenancy-
an
name>/<oci-username>’ --docker-password=’<oci-auth-token>’ --
-tr
docker-email=’<email-address>’ -n ns-<userID>
. non
Where,
• <name-of-secret>-<userID>: A unique name for the secret, for example, ocir-
ide a
Gu as
secret-user22. Replace <userID> with your user ID.
is ) h
• <region-key>: The <region-key> is the key for the Oracle Cloud Infrastructure
e om
Registry region you're using; for example, iad is the region key for US EAST
(Ashburn) region. See the Availability by Region topic in the Oracle Cloud
us il.c
th
Infrastructure documentation.
to gma
the tenancy (as shown on the Tenancy Information page) to which you want to push
r
• <oci-auth-token>: Use the auth token (random string) created in the earlier lab
an
Note: If you do not have an auth token, create a new one by referring to Microservices and
RI
For example,
3. Run the following command to verify if the secret has been created:
$ kubectl get secrets -n ns-<userID>
For example,
se
$ kubectl get secrets -n ns-user22
en
lic
You will see the secret details displayed with the name, age, and other attributes.
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
riss
e .d
an
(ri
E
AN
RI
iss
Dr
Manifest
After the secret is created, you are required to include name of the secret (<name-of-
secret>-<userID>) and full path of the image (iad-dop-lab07-1-ocir-
1/oci_sample_webapp_<userID>:latest)pushed to OCIR repository in the deployment
se
manifest which is used for deploying the sample web application to an OKE cluster.
en
lic
Note: You pushed the image to OCIR repository in Microservices and Container Orchestration:
bl e
Create and work with OCIR repository (Lab07-1). That’s the image you’ll be using in this task.
ra
Tasks
sfe
an
1. Open Code Editor. Code Editor allows you to edit files and source codes present in the
-tr
cloned Git directory within the Cloud Shell.
. non
The Tool Bar is on the left side of the Code Editor window. Click the Explorer (top) icon
ide a
from the left side menu within the code editor window.
Gu as
is ) h
a. Within the Code Editor window, navigate to the cloned Git directory named docker-
e om
b. Browse to the file HelloWorld-lb.yaml in the cloned Git directory and replace the
to gma
1) name: helloworld-deployment-<userID>
iss
r
2) namespace: ns-<userID>
.d
e
an
3) image: <region-key>.ocir.io/<tenancy-namespace>/<repo-name>:<tag>
(ri
Where,
E
Infrastructure Registry region you're using. For example, iad is the region
RI
key for US EAST (Ashburn) region. See the Availability by Region topic in the
iss
a) name : ocir-secret-<userID>
se
en
c. Also, replace the placeholders in the Service section:
lic
1) name: helloworld-service-<userID>
bl e
ra
2) namespace: ns-<userID>
sfe
an
The file will look similar after you’ve made all the changes:
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
riss
e .d
an
(ri
E
AN
RI
iss
Click Save from the File menu and exit the Code Editor.
Dr
After making changes to manifest, you are ready to deploy the application to the OKE cluster.
Tasks
se
$ cd ~/docker-helloworld-demo
en
lic
2. Run the following command:
bl e
$ kubectl create -f HelloWorld-lb.yaml
ra
sfe
A confirmation of deployment and service creation will be displayed.
an
Note: The HelloWorld Service Load Balancer is implemented as an OCI Load Balancer with
-tr
a backend set to route incoming traffic to the cluster nodes.
. non
The OKE service creates new Load Balancer in the root compartment. You can see the
ide a
new Load Balancer in the OCI Console by navigating to the Load Balancers page under
Gu as
Networking by selecting the root compartment from the List Scope menu from the left
is ) h
menu.
e om
us il.c
You will be working on a shared tenancy and might spot multiple entries. Choose the one
th
Make a note of overall health and public IP address for the Load Balancer.
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
Tasks
se
$ kubectl get services -n ns-<userID>
en
lic
For example,
bl e
$ kubectl get services -n ns-user22
ra
Note: The status of the EXTERNAL-IP column will show <pending> initially. Re-run the
sfe
command at some interval until the IP is allotted.
an
-tr
You’ll observe details of the services running on cluster nodes. You’ll also observe
. non
HelloWorld-Service Load Balancer details such as External/Public IP and Port Number.
2.
ide a
Launch an Internet Browser and enter the HelloWorld-Service Load Balancer’s
Gu as
External/Public IP into the browser’s address bar to access the deployed application. The
is ) h
In this lab, you’ll see one node as the replica count is set to 1 in the Kubernetes manifest.
us il.c
th
Once the request reaches the node, you’ll see the following webpage:
to gma
@
riss
e .d
an
(ri
E
AN
RI
iss
Now comes the fun part! Let’s pretend your sample web application has suddenly gained
popularity and you are now required to allocate more resources to it.
Dr
The OKE cluster is running on a single node pool with three worker nodes, thus you can
easily scale your deployment.
For example,
$ kubectl -n ns-user22 scale --replicas=2 deployment/helloworld-
se
deployment-user22
en
You will see a confirmation for deployment scaling on screen.
lic
bl e
b. Further, to see pod and deployment details, run the command:
ra
$ kubectl get all -n ns-<userID>
sfe
For example,
an
$ kubectl get all -n ns-user22
-tr
. non
Here, you will observe an additional row for the new pod that has spawned. You can
identify the new pod by comparing the Container ID or the value in Age column of the
output. ide a
Gu as
is ) h
Also, the Deployment row shows ‘2/2’ in the READY column, indicating the
e om
If you refresh the webpage a few times, you will observe that the two Container IDs
alternatively serving your request. This is because the traffic can reach any of these
@
Tasks
1. To delete the sample web application and all other resources you created on the cluster,
se
run the following command:
en
$ kubectl delete -f HelloWorld-lb.yaml -n ns-<userID>
lic
bl e
For example,
$ kubectl delete -f HelloWorld-lb.yaml -n ns-user22
ra
sfe
2. To confirm the resources are cleared, run the command:
an
$ kubectl get all -n ns-<userID>
-tr
. non
For example,
$ kubectl get all -n ns-user22
ide a
Gu as
You will observe that no resources are found in the namespace.
is ) h
e om
us il.c
th
Important Note: Do not delete the namespace and entry created in the kubeconfig
to gma
file in this lab, because they will be required in the upcoming labs.
@
Congratulations! You have successfully deployed a sample web application to the OKE cluster.
riss
e .d
an
(ri
E
AN
RI
iss
Dr
116
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
Project
ide a
. non
-tr
ra
bl e
Estimated Time: 45 minutes lic
Continuous Delivery:
en
se
Repositories in OCI DevOps
Continuous Integration and
Get Started
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Overview
There are many ways you can work with Git in the DevOps service. You can use GitHub,
GitLab, or Bitbucket or create an OCI Code repository inside your project and upload artifacts.
se
In this lab, you’ll create a sample repository and integrate your GitHub repository with OCI
en
DevOps service. You’ll also learn to test and validate your integration.
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
For more information on Code repositories in OCI DevOps project, see the OCI Code
Repositories Documentation.
Assumptions
• A pre-created OCI Vault OCI-ELS-DEVOPS-VAULT-1 is available in the root
se
compartment.
en
• This lab assumes you’re working in the Ashburn region. The resource naming
lic
convention (iad) used in this lab is according to Ashburn.
bl e
If you’re working in a different region, change the resource names accordingly. For
ra
example, for Phoenix, use phx.
sfe
• You will replace the <userID> placeholder with your user ID.
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
You’ll learn to fork a GitHub repository and create a Personal access token in your GitHub
account.
Tasks
se
1. Sign in to your GitHub account and go to the https://github.com/ou-
en
developers/docker-helloworld-demo repository.
lic
bl e
2. In the top-right corner, click Fork and then click Create fork at the bottom of Create a
ra
new fork page.
sfe
Note: By default, forks use the same name as their upstream repository.
an
-tr
3. In your GitHub account, click your profile icon on the top-right corner, and then go to
. non
Settings.
4. ide a
Navigate to Developer settings and find Personal access tokens > Token (classic) on
Gu as
the left menu and then click Generate new token > Generate new token (classic) for
is ) h
general use.
e om
c. In the Select scopes section, select repo (Full control of private repositories) as your
r
.d
scope.
e
an
6. Click Generate token and make a note of it in a notepad. You’ll need this token later when
(ri
you create secrets. Here’s an example how a token would look like:
E
AN
ghp_YnDABCDEPQRxzGZXXXXduoAZgrPemTj1xxXxx
RI
iss
Dr
You’ll use an existing Vault that is available in the root compartment to create keys and secrets
required to connect to an external repository.
Tasks
se
1. Sign in to your Oracle Cloud Infrastructure (OCI) account.
en
lic
2. Open the navigation menu. Click Identity & Security and then select Vault.
bl e
3. Select root compartment from List Scope on the left menu.
ra
sfe
4. From the list of available vaults, click OCI-ELS-DEVOPS-VAULT-1
an
-tr
5. On the vault Details page, Click Create Key to create a Master Encryption key.
. non
6. Enter the following values for your key:
•
ide a
Create in Compartment: Select your <assigned compartment>.
Gu as
• Protection Mode: HSM
is ) h
• Name: iad-dop-lab10-1-vk-01
e om
• Leave everything else to default values and click Create Key. It will take about a
us il.c
th
minute to create the master encryption key. The keys will go through the Creating
to gma
7. On the Vault details page, select your <assigned compartment> from List scope on
iss
the left menu. You’ll see the key “iad-dop-lab10-1-vk-01” that you created which is
r
in Enabled state.
e .d
an
8. Now, in the Resources section on the left menu of the Vault details page, click Secrets.
(ri
9. Click Create secret and enter the following values for your secret:
E
AN
• Name: iad-dop-lab10-1-vs-01-<userID>
iss
se
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
Tasks
1. In the Console, open the navigation menu and click Developer Services. Under
se
Application Integration, click Notifications.
en
lic
2. Select your <assigned compartment> from List scope on the left menu. The page gets
bl e
updated to display only the resources in that compartment.
ra
sfe
3. Click Topics under the notification in the left menu. You need this topic when you create
your DevOps project. This topic will help you to send messages to its subscriptions.
an
-tr
4. Click Create Topic at the top of the topic list.
. non
5. In the Create Topic page, configure your topic and click Create.
• ide a
Name: iad-dop-lab10-1-nt-01-<userID>. It must be unique across the tenancy;
Gu as
validation is case-sensitive.
is ) h
6. Open the navigation menu and click Developer Services. Under DevOps, click Projects.
th
to gma
7. On the DevOps Projects page, select your <assigned compartment> from List scope
@
• Name: IAD-DOP-LAB10-1-DP-01-<userID>
e
an
− In the Select topic window. Select the option “Select topic by name“
AN
− In the Topic field, select the topic that you created earlier iad-dop-lab10-1-
iss
nt-01-<userID>.
Dr
runs. This will mean that the build logs are available for use in other tooling. On the page
of your newly created project, click Enable Log which takes you to the log management
page.
In the Logs table, toggle to enable the log. This will pop-up to Enable Log window. Leave
all the options as default and click Enable Log at the bottom. The logs will go through the
se
Creating state to the Active state. You have successfully created a DevOps project.
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr
Tasks
1. Open the navigation menu and click Developer Services. Under DevOps, click Projects.
se
en
2. Select the project IAD-DOP-LAB10-1-DP-01-<userID> and go to External Connections
lic
on the left menu.
bl e
3. Click on Create external connection. Create an external connection by entering these
ra
sfe
values.
• Name: IAD-DOP-LAB10-1-EC-01
an
-tr
• Description: Connecting to GitHub.
. non
• Select a type of external connection: GitHub
• In the Vault Secret section, Under Vault in <compartment_name> click Change
Compartment and select the root compartment.ide a
Gu as
is ) h
• Under the Secret in <assigned compartment> field. Select the secret value iad-
dop-lab10-1-vs-01-<userID> within your compartment that contains your Personal
us il.c
th
4. Click Create. The connection to the selected external repository is successfully created
@
and active.
iss
r
Tasks
se
breadcrumb.
en
lic
2. Click Code Repositories on the left menu of your project page.
bl e
3. Click Mirror Repository to mirror code repository from GitHub. Fill the details as given
ra
sfe
below:
• Connection: Select IAD-DOP-LAB10-1-EC-01 from the drop-down list. This is the
an
external connection you created earlier.
-tr
. non
• Repository: Select the docker-helloworld-demo repository from the drop-down
list which you had forked earlier.
• ide a
Mirroring Schedule: Select Custom from the drop-down list and set the minutes
Gu as
field to 1.
is ) h
• Name: IAD-DOP-LAB10-1-MR-01
e om
After a while, the mirrored repository will be available in OCI Code Repository.
@
iss
4. Check if your files are getting updated from your Git Repository.
r
.d
a. Sign in to your GitHub account and navigate to the forked repository docker-
e
an
helloworld-demo.
(ri
b. Click Add File and select Create a New File. This opens a new file.
E
AN
e. Switch to the OCI Console and go to your Mirrored Code Repository (IAD-DOP-
LAB10-1-MR-01). You’ll see a message “Mirroring is in Progress” at the top of the
page.
a. Click Code Repositories on the left menu of your project page and locate your
mirrored repository IAD-DOP-LAB10-1-MR-01.
se
en
b. Click the three dots on the right to open the Actions menu. Select Delete.
lic
c. Type the repository name in the provided field to confirm the Delete action and then
bl e
click Delete.
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
You’ll learn to create a code repository inside your DevOps project, which is very similar to
your Git repository.
Tasks
se
1. Navigate to your DevOps project IAD-DOP-LAB10-1-DP-01-<userID>.
en
lic
2. Click Code Repositories on the left menu of your project page.
bl e
3. Click Create Repository. Enter the following details:
ra
sfe
• Repository name: IAD-DOP-LAB10-1-CR-01
an
• Description: This code repository will be cloned with Git.
-tr
• Default branch: main
. non
4. Click Create Repository. An empty code repository is created with the main branch.
ide a
Gu as
You can perform the following actions on the repository: access your files, access all the
is ) h
commits pertaining to the code repository you just created, compare file changes, branch
e om
actions such as GitHub, view Git tags, and monitor the status of all the operations.
us il.c
th
to gma
@
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr
You’ll clone the code repository to create a local copy on your cloud shell session, add or
remove files, commit changes, and work on different branches by using Git operations. You
can use two methods to clone: HTTPS and SSH keys. In this lab, you’ll use HTTPS.
Tasks
se
en
1. Navigate to your DevOps project IAD-DOP-LAB10-1-DP-01-<userID>.
lic
bl e
2. Click Code Repositories on the left menu of your project page.
ra
3.
sfe
Click IAD-DOP-LAB10-1-CR-01 and click Clone in the Code Repository details page.
an
4. In the Clone window, to the right of the Clone with HTTPS field, click Copy to get the
-tr
path to access the repository using Git. Save this information in a notepad.
. non
5. Open Cloud Shell. In the Cloud Shell, navigate to the home directory and copy-paste the
URL to clone the public repository. ide a
Gu as
is ) h
a. Go to home directory.
e om
$ cd ~
us il.c
$ git clone <paste the HTTPS URL copied in the Clone page.>
@
Sample code:
iss
LAB10-1-DP-01-<userID>/repositories/IAD-DOP-LAB10-1-CR-01
e
an
example, oracletenancy/user22.
E
AN
d. Your password is your auth token. When you enter or paste the password, you’ll not
RI
Note: You need an Auth Token to clone the repository using HTTPS. Use the auth
Dr
6. Switch to your recently cloned directory and you’ll see that there are no files.
$ cd ~/IAD-DOP-LAB10-1-CR-01
$ ls
7. You can now add the files from your existing docker-helloworld-demo directory to
se
the IAD-DOP-LAB10-1-CR-01 directory you just cloned.
en
$ cd ~/docker-helloworld-demo
lic
$ cp * ~/IAD-DOP-LAB10-1-CR-01
bl e
8. Navigate to the cloned directory (IAD-DOP-LAB10-1-CR-01) in Cloud Shell. You should see
ra
all the files copied.
sfe
$ cd ~/IAD-DOP-LAB10-1-CR-01
an
$ ls
-tr
. non
9. Now check the current configuration of Git in your IAD-DOP-LAB10-1-CR-01 directory with
the following command:
$ git remote -v
ide a
Gu as
is ) h
Check if the configuration for the remote repository is pointing to your OCI Code
Repository. For example,
e om
origin https://devops.scmservice.us-ashburn-
us il.c
1.oci.oraclecloud.com/namespaces/oracletenancy/projects/IAD-DOP-
th
LAB10-1-DP-01-<userID>/repositories/IAD-DOP-LAB10-1-CR-01
to gma
(fetch)
origin https://devops.scmservice.us-ashburn-
@
1.oci.oraclecloud.com/namespaces/oracletenancy/projects/IAD-DOP-
iss
LAB10-1-DP-01-<userID>/repositories/IAD-DOP-LAB10-1-CR-01 (push)
r
.d
10. Every time you make changes to your files and save it, it will not automatically update the
e
an
LAB10-1-DP-01-<userID>). All the changes you made in the file are updated only in your
local repository. To update the changes to the main branch in OCI Code Repository within
E
AN
Replace the <tenancy-namespace> and <username> values from the info given in
the Profile menu.
Your password is the auth token, this is token created in the earlier lab (IAD-DOP-LAB07-
se
1-AT-01), that you saved in your notepad earlier.
en
lic
11. In the OCI Console, go to your DevOps project and then to the IAD-DOP-LAB10-1-CR-01
bl e
code repository you created. Click Files in the left menu and notice all the files are
available in the code repository.
ra
sfe
The initial push of all your code for a sample Web Application has taken place into your
an
OCI Code Repository. As you do further practices, you will make changes to the files in the
-tr
local repository in the Cloud Shell and push it into your OCI Code Repository.
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
Tasks
se
$ cd ~/IAD-DOP-LAB10-1-CR-01
en
lic
2. Create a new branch in the local repository.
bl e
$ git branch new_branch
ra
3. Move to the newly created branch.
sfe
$ git checkout new_branch
an
-tr
4. Create a sample file in the new branch.
. non
$ echo “OCI_GIT_TEST” >> test1.txt
5.
ide a
Use the ls command to verify the new file is now present in the directory.
Gu as
$ ls
is ) h
Adds the file test1.txt in the local repository and stages them for commit.
@
iss
$ git status
e
an
Replace the <tenancy-namespace> and <username> values from the info given in
the Profile menu.
Your password is the auth token, this is token created in the earlier lab (IAD-DOP-LAB07-
se
1-AT-01), that you saved in your notepad earlier.
en
lic
10. In the Console, navigate to the code repository IAD-DOP-LAB10-1-CR-01 within your
bl e
Devops project.
ra
11. Select Files in the left menu and click the drop-down list to select a branch. You should
sfe
see new_branch. Select the newly created branch and scan through the files and check if
an
test1.txt is present in that branch.
-tr
. non
ide a
Important Note: Do not delete any artifacts and resources created in this lab because
Gu as
they will be required in the upcoming labs.
is ) h
Congratulations! in this lab, you've learned to create a project, mirror a repository, and clone
e om
134
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
Project
ide a
. non
-tr
bl e
Overview
Oracle Cloud Infrastructure (OCI) Artifact Registry is a repository service for storing, sharing,
and managing software development packages.
se
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
For more information on OCI Artifact Registry, see the OCI Artifact Registry Documentation.
iss
For more information on setting up artifacts and environments in a DevOps project, see the
Dr
136 Create an artifact registry and set up artifacts and environments in a DevOps project.
Prerequisites
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
• You must complete the Continuous Integration and Continuous Delivery: Work with
code repositories in OCI DevOps project (Lab10-1) to perform tasks for this practice.
Assumptions
se
• You are signed in to your Oracle Cloud Infrastructure (OCI) account using your
en
credentials.
lic
• A pre-created OKE cluster <EventID>-OCI-ELS-DEVOPS-OKE is available in the root
bl e
compartment. <EventID> can be fetched from the Lab tab available in the course
page.
ra
sfe
• This lab assumes you’re working in the Ashburn region. The resource naming
convention (iad)used in this lab is according to Ashburn.
an
-tr
If you’re working in a different region, change the resource names accordingly. For
. non
example, for Phoenix, use phx.
•
ide a
You will replace the <userID> placeholder with your user ID.
Gu as
is ) h
e om
us il.c
th
to gma
@
riss
e .d
an
(ri
E
AN
RI
iss
Dr
Create an artifact registry and set up artifacts and environments in a DevOps project. 137
Create a Repository to Store and Manage Artifacts
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
An artifact is a software package, library, or a zip file used for deploying your applications.
These artifacts are grouped into repositories, which are collections of related artifacts.
In this lab, you will create an Artifact Registry Repository to store your Kubernetes manifest.
se
Tasks
en
lic
1. In the Console, open the navigation menu and click Developer Services. Under
bl e
Containers & Artifacts, click Artifact Registry.
ra
2.
sfe
Select your <assigned compartment> from List scope on the left menu.
an
3. Click Create repository and fill the following values in the form:
-tr
. non
a. Name: IAD-DOP-LAB11-1-AR-01
b.
ide a
Compartment: Select your <assigned compartment>.
Gu as
is ) h
c. Select Immutable artifacts. Your new repository will make its artifacts immutable.
e om
d. Click Create.
us il.c
th
138 Create an artifact registry and set up artifacts and environments in a DevOps project.
Add Container Image Repository Artifact to Store
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Docker Images
Artifacts are used to specify software package versions for deployment. DevOps artifacts can
be of following types:
• Container image repository
se
• Instance group deployment configuration
en
• Kubernetes manifest
lic
• General artifact
bl e
• Helm Chart
ra
sfe
You will add container image repository artifact to store your Docker images.
an
-tr
Tasks
. non
1. Open the navigation menu and click Developer Services. Under DevOps, click Projects.
ide a
Gu as
2. Select your <assigned compartment> from List scope on the left menu.
is ) h
Integration and Continuous Delivery: Work with code repositories in OCI DevOps project
us il.c
(Lab10-1).
th
to gma
4. Click Artifacts from the left menu to navigate to the artifacts page.
@
5.
iss
Click Add artifact to create an artifact and fill the form with the following values:
r
.d
a. Name: IAD-DOP-LAB11-1-AF-01
e
an
<region-key>.ocir.io/<tenancy-namespace>/<repo-name>:<tag>
RI
For example,
iss
iad.ocir.io/oracletenancy/iad-dop-lab07-1-ocir-
Dr
1/oci_sample_webapp_<userID>:${BUILDRUN_HASH}
Replace <tenancy-namespace> with your tenancy name, <userID> with your user ID, and
<region-key> with the key for the Oracle Cloud Infrastructure Registry region you're using.
For example, iad is the region key for US EAST (Ashburn) region. See the Availability by
Region topic in the Oracle Cloud Infrastructure documentation.
Create an artifact registry and set up artifacts and environments in a DevOps project. 139
Ensure that you append ${BUILDRUN_HASH} in the fully qualified image URL as the tag. This
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
se
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr
140 Create an artifact registry and set up artifacts and environments in a DevOps project.
Create a Reference to Kubernetes Manifest
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Tasks
se
en
2. Click Artifacts from the left menu to navigate to the artifacts page.
lic
bl e
3. Click Add artifact to create an artifact and fill the form with the following values:
ra
a. Name: IAD-DOP-LAB11-1-AF-02
sfe
an
b. Type: Select Kubernetes Manifest from the list of options.
-tr
c.
. non
Artifact Source: Select Artifact Registry repository.’
d. Artifact Registry repository: Click Select and select your artifact registry IAD-DOP-
ide a
Gu as
LAB11-1-AR-01 created earlier.
is ) h
For example,
to gma
lab11-1-user22-oke-manifest
@
2) Version: ${BUILDRUN_HASH}
riss
You will now see both the artifacts IAD-DOP-LAB11-1-AF-01 and IAD-DOP-LAB11-1-AF-02,
(ri
Create an artifact registry and set up artifacts and environments in a DevOps project. 141
Create a DevOps Environment
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
An environment is the target platform for your application. You will now create an
Environment to point to your OKE cluster.
Tasks
se
1. Open the DevOps project IAD-DOP-LAB10-1-DP-01-<userID>.
en
lic
2. Click Environments from the left menu to navigate to the environments page.
bl e
3. Click Create environment and select Oracle Kubernetes Engine as the Environment
ra
sfe
Type. Fill the rest of the form with the following values:
an
a. Name: IAD-DOP-LAB11-1-ENV-01
-tr
. non
b. Description: This environment is pointing to pre created OKE
cluster.
ide a
Gu as
c. Click Next.
is ) h
d. Region: The region you are working in. This is populated by default.
e om
us il.c
NOTE: <EventID> can be fetched from the Lab tab available in the course page.
iss
r
.d
You will now see the environment IAD-DOP-LAB11-1-ENV-01 in active state, listed on the
(ri
Important Note: Do not delete any artifacts and resources created in this lab because
iss
Congratulations! in this lab you learned to create a repository to store, share and manage your
artifacts. You added a container image repository artifact to store your Docker images and
created a reference to your manifest in the Artifact Registry repository.
142 Create an artifact registry and set up artifacts and environments in a DevOps project.
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
. non
-tr
en
Deployment to an OKE
se
Cluster Using OCI DevOps
Continuous Integration and
Get Started
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Overview
The Oracle Cloud Infrastructure (OCI) DevOps service is an end-to-end, continuous integration
and continuous delivery (CI/CD) platform for developers.
se
You can use OCI DevOps service to easily build, test, and deploy software and applications on
en
Oracle Cloud. The DevOps build and deployment pipelines reduce change-driven errors and
lic
decrease the time customers spend on building and deploying releases.
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
.d
e
an
(ri
144 Deploy a Web App with a CI/CD pipeline to an OKE cluster using OCI DevOps
e. Automate Sample Web Application deployment to OKE cluster.
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
For more information on OCI DevOps project, see the OCI DevOps Documentation.
Prerequisites
se
• You are signed into your Oracle Cloud Infrastructure (OCI) account using your
en
credentials.
lic
• You must complete the following labs before you perform tasks for this practice:
bl e
− Microservices and Container Orchestration: Create Docker image for a web
ra
application using Dockerfile (Lab 06-1).
sfe
− Microservices and Container Orchestration: Create and work with OCIR repository
an
(Lab 07-1).
-tr
. non
− Microservices and Orchestration: Set up cluster access (Lab 08-1).
− Microservice and Container Orchestration: Deploy a sample Web application on a
cluster using kubectl (Lab 09-1). ide a
Gu as
− Continuous Integration and Continuous Delivery: Work with code repositories in OCI
is ) h
− Continuous Integration and Continuous Delivery: Create and set up artifacts and
us il.c
Assumptions
@
compartment. <EventID> can be fetched from the Lab tab available in the course
r
.d
page.
e
an
Orchestration: Create and work with OCIR repository (Lab 07-1) available.
iss
Container Orchestration: Create and work with OCIR repository (Lab 07-1) available.
• You have a namespace ns-<userID> created in Microservice and Container
Orchestration: Set up cluster access (Lab 08-1) available.
Deploy a Web App with a CI/CD pipeline to an OKE cluster using OCI DevOps 145
• You have the Kubernetes Secret ocir-secret-<userID> created in Microservice
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
se
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr
146 Deploy a Web App with a CI/CD pipeline to an OKE cluster using OCI DevOps
Prepare the Kubernetes Deployment Manifest for
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Automated Deployment
The Manifest is a specification of a Kubernetes API object in JSON or YAML format. A manifest
specifies the desired state of an object that Kubernetes will maintain when you apply the
manifest.
se
en
In this lab, you will edit the Kubernetes Deployment Manifest HelloWorld-lb.yaml to
lic
prepare for an automated deployment.
bl e
Tasks
ra
sfe
1. Open Cloud Shell and go to the cloned OCI DevOps Code Repository created in lab10-1.
an
$ cd ~/IAD-DOP-LAB10-1-CR-01/
-tr
2.
. non
Make sure that you’re in the git main branch.
$ git checkout main
3. ide a
Gu as
Open Code Editor. Code Editor allows you to edit files and source codes present in the
is ) h
The Tool Bar is on the left side of the Code Editor window. Click the Explorer (top) icon
us il.c
a. From inside the Code Editor, navigate to the local code repository IAD-DOP-LAB10-1-
CR-01, which was cloned in the Continuous Integration and Continuous Delivery: Work
@
iss
b. Browse to the file HelloWorld-lb.yaml and replace the tag latest with
e
image: <region-key>.ocir.io/<tenancy-namespace>/<repo-
(ri
name>:${BUILDRUN_HASH}
E
AN
Where,
RI
Registry region you're using, for example, iad is the region key for US EAST
Dr
(Ashburn) region. See the Availability by Region topic in the Oracle Cloud
Infrastructure documentation.
• <tenancy-namespace>: This is the auto-generated Object Storage namespace
string of the tenancy (as shown on the Tenancy Information page) to which you
want to push the image.
Deploy a Web App with a CI/CD pipeline to an OKE cluster using OCI DevOps 147
• <repo-name>: The repository name iad-dop-lab07-1-ocir-
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
The file will look similar when you make the changes:
se
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
Note: user22 is a sample reference in the above code snippet. Instead, your files must
e om
4. Click Save from the File menu and exit the Code Editor.
to gma
5. Run the following commands to commit and push your changes to code repository IAD-
@
a. Switch to the Cloud Shell and add the changes in the working directory to the staging
an
area:
(ri
$ git add .
E
AN
$ git status
iss
You will see the file HelloWorld-lb.yaml shown as modified and displayed in green
Dr
color.
148 Deploy a Web App with a CI/CD pipeline to an OKE cluster using OCI DevOps
d. Push the changes to the upstream code repository:
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
se
given in the Profile menu.
en
lic
Enter the auth token IAD-DOP-LAB07-1-AT-01 (random string) you copied earlier as the
bl e
password.
ra
For example,
sfe
R5kwpS-xxxxx((]51r]]
an
-tr
Note: When you enter or paste the password, you’ll not see masked characters. Press
. non
Enter on your keyboard to continue and you should see the following message on the
screen.
Enumerating objects: 5, done. ide a
Gu as
Counting objects: 100% (5/5), done.
is ) h
6. Verify if the changes have been pushed to the upstream code repository:
@
b. Navigate to Code Repositories from the left menu and open the repository IAD-
r
.d
DOP-LAB10-1-CR-01.
e
an
c. Navigate to Files from the left menu on the code repository page and you will notice
(ri
Deploy a Web App with a CI/CD pipeline to an OKE cluster using OCI DevOps 149
Create DevOps Build Pipeline and Build Stages
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
A build pipeline contains the stages that define the build process for successfully compiling,
testing, and running software applications before deployment.
A stage is an action in the build pipeline. The OCI DevOps service includes the following
predefined stages that you can use in a build pipeline:
se
en
• Managed Build: Build and test your software applications.
lic
• Deliver Artifacts: Store your software applications created from the Managed Build
bl e
stage in the OCI Artifact Registry or OCI Container Registry repositories.
• Trigger Deployment: Start a deployment pipeline to deploy the output from the
ra
sfe
build pipeline.
an
• Wait: Pause a specific duration for testing the build pipeline.
-tr
You can add multiple stages to a pipeline. Stages can be added in a sequence or in parallel.
. non
You can remove any stage from the pipeline. When you do, the stage and its associated
resources are deleted.
ide a
Gu as
In this lab, you will create DevOps build pipeline and build stages.
is ) h
e om
Tasks
us il.c
th
1. Open the navigation menu and click Developer Services. Under DevOps, click Projects.
to gma
2. Select your <assigned compartment> from the List scope on the left menu.
@
iss
4.
e
Click Build Pipelines from the left menu to navigate to the Build Pipelines page.
an
(ri
5. Click Create build pipeline and fill the form with the following values:
E
AN
a. Name: IAD-DOP-LAB12-1-BPL-01
RI
150 Deploy a Web App with a CI/CD pipeline to an OKE cluster using OCI DevOps
6. To add the first stage to the build pipeline, click the + icon and click Add stage.
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
a. Select Managed Build as stage type and click Next. Fill the form with the following
values:
se
2) Description: This stage executes the commands specified in
en
build_spec.yaml file.
lic
3) Default compute shape information is displayed for the OCI build agent.
bl e
Note: The Managed Build stage runs build instructions on a service managed
ra
build runner.
sfe
4)
an
Base container image: Default is Oracle Linux 7 x86 standard 1:0
-tr
5) Connect to your tenancy subnet: This is an optional field. Because there are no
. non
private resources in your compartment, you will leave this blank.
6) ide a
Build spec file path: The build specification contains build steps and settings
Gu as
that the build pipeline uses to run a build. The file build_spec.yaml is in the
is ) h
7) Primary code repository: Click Select. This opens the window to select Primary
th
code repository:
to gma
a) Select the OCI Code Repository from the drop-down list for Source:
@
Connection type.
iss
This will populate the Code repositories available within your DevOps project.
r
e .d
c) Click Select.
AN
RI
8) Additional code repositories: You do not have any additional code repositories,
therefore, leave this field blank.
iss
Dr
9) Timeout (in seconds): This is an optional field. You will continue with the default
value of 36000.
10) Click Add. You will notice a stage with name Build-Demo-WebApp (Managed
Build) has been added.
Deploy a Web App with a CI/CD pipeline to an OKE cluster using OCI DevOps 151
7. Add the second stage to the Build pipeline by clicking the + icon at the bottom of the
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
a. Select Deliver Artifacts as stage type from the optional section and click Next. Fill
the form with the following values:
se
en
2) Description: This stage uploads artifacts to registries.
lic
3) Click the Select Artifact(s) button. This opens the window to select artifacts
bl e
created in Continuous Integration and Continuous Delivery: Create and set up
ra
artifacts and environments in DevOps project (Lab11-1). Select the following
sfe
artifacts and click Add:
an
• IAD-DOP-LAB11-1-AF-01 Docker Image
-tr
• IAD-DOP-LAB11-1-AF-02 Kubernetes Manifest
. non
You will see both the artifacts now listed on the Add a stage page.
ide a
Gu as
b. Associate artifacts with build result: In this section, you will provide the output
is ) h
corresponding to the artifact types in the build config/result artifact name field.
us il.c
th
repository IAD-DOP-LAB10-1-CR-01.
152 Deploy a Web App with a CI/CD pipeline to an OKE cluster using OCI DevOps
After reading through the file snippet, you will be able to identify the output names
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
used for different artifact types. Fill the fields appropriately as shown in the following
table:
se
en
IAD-DOP-LAB11-1-AF-02 Kubernetes manifest oke_deploy_manifest
lic
c. Click Add. You will notice a stage with name Push WebApp Artifacts
bl e
(DeliverArtifacts) added.
ra
sfe
Note: At this point you have two stages in your Build pipeline IAD-DOP-LAB12-1-BPL-01.
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
riss
e .d
an
(ri
E
AN
RI
iss
Dr
Deploy a Web App with a CI/CD pipeline to an OKE cluster using OCI DevOps 153
Create DevOps Deployment Pipeline and Deploy Stage
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
A deployment pipeline holds the requirements that must be satisfied to deliver a set of
artifacts to the target environment. Deployment pipelines contain different stages for
automated deployment. Each stage is associated with certain actions in the pipeline.
se
DevOps service includes predefined stages, which could be readily used in a deployment
en
pipeline:
lic
• Deploy to a Kubernetes cluster: Uses the built-in Kubernetes rolling update strategy
bl e
ra
• Deploy to an instance group: Releases update incrementally to the instance group.
sfe
You can specify the maximum instances that can be offline at one time. This type
an
supports automatic rollbacks.
-tr
• Deploy to Functions: Uses the built-in Functions update strategy
. non
In this lab, you will create DevOps deployment pipeline and deploy stage.
ide a
Gu as
Tasks
is ) h
e om
LAB10-1-DP-01-user22.
th
to gma
2. Click Deployment Pipelines from the left menu to navigate to the Deployment Pipelines
page.
@
iss
3. Click Create pipeline and fill the form with the following values:
r
.d
a. Name: IAD-DOP-LAB12-1-DPL-01
e
an
(ri
4. To add a stage to the Deployment pipeline, click the + icon and click Add stage.
iss
a. Select Apply manifest to your kubernetes cluster as stage type and click Next. Fill
Dr
154 Deploy a Web App with a CI/CD pipeline to an OKE cluster using OCI DevOps
3) Environment: Select the environment IAD-DOP-LAB11-1-ENV-01 you created in
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Continuous Integration and Continuous Delivery: Create and set up artifacts and
environments in DevOps project (Lab11-1).
4) Under Select one or more artifacts field, click Select Artifact. This opens the
window to add Kubernetes Manifest type artifacts.
se
• Select IAD-DOP-LAB11-1-AF-02 and click Save changes.
en
5) Override Kubernetes namespace: Leave this field blank.
lic
bl e
Note: The namespace to which the application will be deployed is specified in the
HelloWorld-lb.yaml file which is ns-<userID>.
ra
sfe
6) If validation fails, automatically roll back to the last successful version?:
an
Select Yes to automatically roll back to the last successful version.
-tr
. non
7) Click Add. You will notice a stage with name OCI-WebApp-Deployment (Deploy
OKE: Rolling) added.
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
riss
e .d
an
(ri
E
AN
RI
iss
Dr
Deploy a Web App with a CI/CD pipeline to an OKE cluster using OCI DevOps 155
Create a Trigger Deployment Stage in Build Pipeline
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
In this lab, you will create a Trigger Deployment Stage within the build pipeline that triggers
the Deployment pipeline to deploy the application based on the output artifacts from the build
pipeline execution.
Tasks
se
en
1. Navigate to the Build pipeline IAD-DOP-LAB12-1-BPL-01 in your DevOps project.
lic
bl e
2. On the Build Pipeline tab, click the + icon at the bottom of the Push WebApp Artifacts
ra
(Deliver Artifacts) box and click Add stage.
sfe
a. Select Trigger Deployment as stage type from the optional section and click Next.
an
Fill the form with the following values:
-tr
. non
1) Stage name: Trigger OKE Deployment
2) ide a
Description: This triggers the IAD-DOP-LAB12-1-DPL-01 Deployment
Gu as
pipeline stages.
is ) h
e om
3) Click Select Deployment Pipeline. This opens the window to select the
deployment pipelines you have created.
us il.c
th
6) Click Add. You will notice a stage with name Trigger OKE Deployment (Trigger
E
deployment) added.
AN
RI
iss
Dr
156 Deploy a Web App with a CI/CD pipeline to an OKE cluster using OCI DevOps
Automate Sample Web Application Deployment to OKE
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Cluster
In this lab, you will run the Build pipeline to execute all its stages in sequence and populate the
artifact and container registry with the manifest and Docker image, respectively. The
successful execution of the Build pipeline will trigger the Deployment pipeline, which uses the
se
output artifacts and applies them to the target environment, which in this case is an OKE
en
cluster.
lic
Tasks
bl e
ra
1. On the Build Pipeline page IAD-DOP-LAB12-1-BPL-01. Click the Start Manual Run
sfe
button. The Start Manual Run page opens.
an
-tr
a. OCI assigns your build a Build run name.
. non
b. Click Start manual run at the bottom left.
ide a
Gu as
2. You will reach the Build pipeline tab. Observe that all the build stages are listed here.
is ) h
Build stages will execute sequentially. You can observe the logs for each stage in the right
window.
e om
us il.c
3. Once the Trigger OKE Deployment stage completes, click Deployments from the left
th
to gma
You will observe deployment listed here that got automatically kicked-off and is either in
r
Further, when you click the deployment name, you will reach the Deployments tab. Under
(ri
the Deployments tab, you can see the logs and additional details for the Deployment
E
pipeline run.
AN
RI
4. Because the deployment is successful, let’s now try to access the application using the
External (or Public) endpoint that is the HelloWorld Service Load Balancer IP.
iss
Dr
Deploy a Web App with a CI/CD pipeline to an OKE cluster using OCI DevOps 157
For example,
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
6. Launch a Web browser and enter the EXTERNAL-IP address into the browser’s address
bar to access the application. Once the request is processed, you’ll see the following
se
webpage:
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr
158 Deploy a Web App with a CI/CD pipeline to an OKE cluster using OCI DevOps
View the Artifacts Generated as Part of the Automated
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Build
In this lab, you will view the artifacts generated as part of the Build pipeline execution.
Tasks
se
en
1. To view Container Image Repository Artifact:
lic
a. In the Console, open the navigation menu and click Developer Services. Under
bl e
Containers & Artifacts, click Container Registry.
ra
sfe
b. Select your <assigned compartment> from List scope on the left menu.
an
c. Select the container repository iad-dop-lab07-1-ocir-
-tr
1/oci_sample_webapp_<userID> you created as part of Microservices and
. non
Container Orchestration: Manage OCIR and Push and Pull Images Using Docker CLI
ide a
(Lab 07-1).
Gu as
d. You will notice a new image present in your repository with a random string like
is ) h
qm3pznq as tag. This random string is the BUILDRUN_HASH of the build that pushed
e om
a. In the OCI Console, open the navigation menu and click Developer Services. Under
@
b. Select your <assigned compartment> from the List scope on the left menu.
e
an
Integration and Continuous Delivery: Create an Artifact Registry and Set Up Artifacts
E
d. You will notice the Kubernetes manifest used by the Deployment pipeline listed here
with the same string qm3pznq as tag.
iss
Dr
Every time you run a build pipeline, these artifacts will be generated and stored in the
container and artifact registry with a unique string to identify them. In case of a build failure,
these artifacts are used to roll back to last successful version.
Deploy a Web App with a CI/CD pipeline to an OKE cluster using OCI DevOps 159
Important Note: Do not delete any artifacts and resources created in this lab because
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Congratulations! You have successfully deployed a Web Application to an OKE cluster using
OCI DevOps Build and Deployment pipelines.
Further, you also verified the artifacts generated as part of the successful Build pipeline run.
se
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr
160 Deploy a Web App with a CI/CD pipeline to an OKE cluster using OCI DevOps
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
. non
-tr
Lab 13-1 Practices
an
sfe
ra
Estimated Time: 60 minutes bl e
Monitoring Queries
lic
en
Configure Alarms with
se
Notifications and Create
Monitoring - Notification:
Get Started
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Overview
The Oracle Cloud Infrastructure Monitoring service lets you actively and passively monitor
your cloud resources using metrics and alarms.
se
The Monitoring service uses metrics to monitor resources and alarms to notify you when
en
these measures respond to the triggers specified by the alarm.
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
b. Configure notifications.
(ri
E
For more information on OCI Alarms and Notifications, see the OCI Notification
Documentation and for Monitoring Queries, see the OCI Monitoring Documentation.
• You must complete the following labs before you perform tasks for this practice:
− Microservices and Container Orchestration: Create Docker image for a web
application using Dockerfile (Lab 06-1).
− Microservices and Container Orchestration: Create and work with OCIR repository
se
(Lab 07-1).
en
− Microservices and Orchestration: Set up cluster access (Lab 08-1).
lic
− Microservice and Container Orchestration: Deploy a sample Web application on a
bl e
cluster using kubectl (Lab 09-1).
ra
− Continuous Integration and Continuous Delivery: Work with code repositories in OCI
sfe
DevOps project (Lab10-1).
an
− Continuous Integration and Continuous Delivery: Create and set up artifacts and
-tr
environments in DevOps project (Lab11-1).
. non
− Continuous Integration and Continuous Delivery: Automate Web App deployment
to an OKE cluster using OCI DevOps CI/CD pipeline (Lab 12-1).
ide a
Gu as
Assumptions
is ) h
• This lab assumes you’re working in the Ashburn region. The resource naming
e om
If you’re working in a different region, change the resource names accordingly. For
to gma
• You will replace the <userID> placeholder with your user ID.
riss
e .d
an
(ri
E
AN
RI
iss
Dr
You will execute build runs from DevOps Project to ensure build runs are successful, measure
the total time taken for execution and verify deployments are working.
Tasks
se
1. Sign in to your Oracle Cloud Infrastructure (OCI) account.
en
lic
2. Open the navigation menu and select Developer Services. Under DevOps, select
bl e
Projects.
ra
3.
sfe
Select your <assigned compartment> from the List scope on the left menu.
an
4. Click to select your project IAD-DOP-LAB10-1-DP-01-<userID> under the Project name
-tr
column.
. non
5. From the left menu, click Build Pipelines and select IAD-DOP-LAB12-1-BPL-01 pipeline.
ide a
Gu as
6. Verify that there are three stages available in the Build pipeline: Build-Demo-WebApp,
is ) h
8. Keep the Build run name as default and click Start manual run.
The status at the top-left corner will be shown In progress, and the execution will take
@
iss
9. Upon completion, the Status at the top-left corner will be updated to Succeeded.
e
an
10. Also, convert the Total duration, mentioned at the top, into seconds.
(ri
E
For example, the build run of 3 minutes and 40 seconds will be equal to 220 seconds. You
AN
will use this value as threshold for BuildRunExecutionTime metric. Save this value on a
RI
notepad.
iss
11. Click your DevOps project IAD-DOP-LAB10-DP-01-<userID> using the breadcrumb list at
Dr
the top of the page and click Deployments from the left menu.
Now that you have validated build run and deployment, you will configure Notifications to
notify of such events. Alarms is a feature in the Monitoring service which will trigger
notifications based on the monitoring query and trigger rule conditions defined.
To create an alarm, you must first create a notification topic and a subscription so that the
se
alarm has a way to notify the relevant parties; for example, an alarm can email an
en
administrator when a deployment has failed.
lic
bl e
Task
ra
sfe
1. Open the navigation menu and select Developer Services. Under Application Integration,
an
click Notifications.
-tr
2. Select your <assigned compartment> from the List scope on the left menu.
. non
3. Click Create Topic at the top of the topic list. Enter the following values to configure your
topic and click Create: ide a
Gu as
is ) h
Note: Topic name is case-sensitive and must be unique across the tenancy.
@
iss
4. Once the state of the topic changes to Active, click the topic name iad-dop-lab13-1-
r
.d
5. Click Create Subscription and enter the following values to configure your subscription
(ri
6. Click the subscription that you just created. The Subscription Information will be
Dr
7. Check your email account for the confirmation email and click the Confirm subscription
verification link. A pop-up window will tell you that the subscription has been confirmed.
Note: You may need to refresh your browser if the status is not updated.
se
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr
You will now create an alarm that is triggered when the BuildRunExecutionTime metric
reaches a designated threshold.
Thereafter, you will execute a build run from the build pipeline of your DevOps project and
verify the alarm notifications.
se
en
Tasks
lic
bl e
Create an Alarm
ra
sfe
1. Open the navigation menu and select Observability & Management. Under Monitoring,
an
click Alarm Definitions.
-tr
2. Select your <assigned compartment> from the List scope on the left menu.
. non
3. Click Create Alarm and enter the following values:
ide a
Gu as
a. Define Alarm section:
is ) h
Note: The Tags section is optional. Therefore, keep the default selections.
@
iss
Note: The Resource Group field is optional, therefore, you can skip it for now. Keep the
iss
more than 60 seconds, and an alarm should be triggered which will send an email
notification based on the notifications configured in the previous task.
se
− Compartment: Select your <assigned compartment>.
en
− Topic: Select iad-dop-lab13-1-nt-01-<userID> from the drop-down list.
lic
Note: You have created the topic earlier and recall that the topic is the communication
bl e
channel, such as email. When the alarm is triggered, a notification is sent to the
ra
subscribed email addresses.
sfe
an
4. Keep the default selection in the Message grouping section which is Group notifications
-tr
across metric streams.
. non
5. Keep default selection in the Message Format section which is Send formatted
messages.
ide a
Gu as
is ) h
Note:
e om
• You can also choose to have a notification repeated at certain frequencies if an alarm
continues. Keep the Repeat notification option deselected.
us il.c
th
• You have option to suppress (pause) the notification. Keep the Suppress notifications
to gma
option deselected.
@
You should now be able to see the alarm’s details and are ready to execute Build Run from
e.d
Build Pipeline.
an
(ri
8. Click Build Pipelines from the left menu and click IAD-DOP-LAB12-1-BPL-01.
RI
10. Keep the Build run name as default and click Start manual run.
Dr
11. Wait until the Build run is finished. Verify that the status of build run is Succeeded.
12. Verify that the Total Duration mentioned on top is greater than 60 seconds which is the
trigger rule condition.
1. Open the navigation menu and select Observability & Management. Under Monitoring,
click Alarm Definitions.
se
3. The icon before IAD-DOP-LAB13-1-ALA-01 would have changed to Firing mode due to the
en
overall build execution time exceeding the threshold. Please wait for a minute if the status
lic
is not changed to Firing, and then refresh the page.
bl e
• Scroll down to the Alarm history graph which signifies that the execution time of the
ra
build has surpassed the set threshold.
sfe
• An email notification is sent to the configured subscription email of the notification’s
an
topic as alarm status changes from OK to Firing.
-tr
• The email provides details about alarm OCID, number of metrics breaching threshold,
. non
and dimensions as shown below in the screenshot.
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
riss
e .d
an
(ri
E
AN
RI
iss
Dr
4. Navigate back to the Alarm Definitions page and select the check box against the IAD-
DOP-LAB13-1-ALA-01 alarm name.
8. Click Close and verify that the Suppressed column shows the alarm is suppressed for the
period.
se
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr
You will now create an alarm that is triggered when the build is succeeded.
Thereafter, you will execute a build run from the build pipeline of your DevOps project and
verify alarm notifications using the BuildSuccess metric.
se
Tasks
en
lic
Create an Alarm
bl e
ra
1. Open the navigation menu and select Observability & Management. Under Monitoring,
sfe
click Alarm Definitions.
an
2. Select your <assigned compartment> from the List scope on the left menu.
-tr
. non
3. Click Create Alarm and enter the following values:
Note: The Tags section is optional. Therefore, keep the default selections.
@
Note: The Resource Group field is optional, therefore, you can skip it for now. Keep the
RI
4. Keep the default selection in the Message grouping section which is Group notifications
se
across metric streams.
en
lic
5. Keep the default selection in the Message Format section which is Send formatted
messages.
bl e
ra
6. Select Enable this alarm and click Save Alarm.
sfe
You should now be able to see the alarm’s details and are ready to execute Build Run from
an
Build Pipeline.
-tr
. non
7. Open your DevOps project IAD-DOP-LAB10-1-DP-01-<userID>.
8. ide a
Select Build Pipelines from the left navigation panel and click IAD-DOP-LAB12-1-BPL-01
Gu as
pipeline.
is ) h
e om
10. Keep the Build run name as default and click Start manual run.
to gma
11. Wait until the Build run is finished. Verify that the Status of Build run is succeeded.
@
iss
1. From the navigation menu, select Observability & Management. Under Monitoring, click
e
an
Alarm Definitions.
(ri
3. The icon before IAD-DOP-LAB13-1-ALA-02 would have changed to Firing mode as the
RI
build run has succeeded. Please wait for a minute if the status is not changed to Firing,
iss
• Scroll down to the Alarm history graph which signifies that the build has succeeded.
• An email notification is sent to the configured subscription email of the notifications
topic as alarm status changes from OK to Firing.
se
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
4. Navigate back to the Alarm Definitions page and select the check box against the IAD-
th
to gma
DOP-LAB13-1-ALA-02 alarm.
@
6. In the Suppress alarms window, keep the default Start time and End time and click
r
.d
7. Click Close and verify that the column Suppressed shows the alarm is suppressed for the
(ri
period.
E
AN
RI
iss
Dr
You will now create an alarm that is triggered when the Deployment gets Failed.
Thereafter, you will configure the Build run stage to fail the deployment, execute a build run
from the Build pipeline which will initiate the deployment and verify alarm notifications.
se
Tasks
en
lic
Create an Alarm
bl e
ra
You will now create an alarm for notifying Build Success Runs.
sfe
1. Open the navigation menu and select Observability & Management. Under Monitoring,
an
click Alarm Definitions.
-tr
. non
2. Select your <assigned compartment> from the List scope on the left menu.
3. ide a
Click Create Alarm and enter the following values:
Gu as
is ) h
Note: The Tags section is optional. Therefore, keep the default selections.
iss
Note: The Resource Group field is optional, therefore, you can skip it for now. Keep the
Dr
se
− Destination service: Select Notifications from the drop-down list.
en
− Compartment: Select your <assigned compartment>.
lic
− Topic: Select iad-dop-lab13-1-nt-01-<userID> from the drop-down list.
bl e
ra
4. Keep the default selection in the Message grouping section which is Group notifications
sfe
across metric streams.
an
5. Keep default selection in the Message Format section which is Send formatted
-tr
messages.
. non
6. Select Enable this alarm and click Save Alarm.
ide a
Gu as
You should now be able to see the alarm’s details.
is ) h
e om
You will disable the option to send build pipeline parameters so that the deployment task can
to gma
2. Select Build Pipelines from the left menu and click IAD-DOP-LAB12-1-BPL-01.
e .d
an
3. Click the three dots on Trigger OKE Deployment and click View details.
(ri
4. Click Edit Stage and deselect the Send build pipelines Parameters box.
E
AN
Note: This will block the build pipeline parameters to be shared with deployment pipeline
RI
Note: Select the Send build pipelines Parameters box after the alarm has been tested at
the end of this lab.
9. Click Project using the breadcrumb list and click Deployments from the left menu.
se
en
Trigger the Alarm
lic
1. Open the navigation menu and select Observability & Management. Under Monitoring,
bl e
click Alarm Definitions.
ra
sfe
2. Click IAD-DOP-LAB13-1-ALA-03 alarm you created earlier.
an
3. The icon before IAD-DOP-LAB13-1-ALA-03 would have changed to Firing mode as the
-tr
deployment has Failed. Please wait for a minute if the status is not changed to Firing, and
. non
then refresh the page.
•
ide a
Scroll down to the Alarm history graph which signifies that the deployment has
Gu as
failed.
is ) h
• The email provides details about alarm OCID, Query, number of metrics breaching
th
to gma
DOP-LAB13-1-ALA-03 alarm.
6. In the Suppress Alarms window, select the default Start time and End time and click
Apply suppressions to confirm.
se
en
7. Click Close and verify that the column Suppressed shows the alarm is suppressed for the
lic
period.
bl e
Update Build Pipeline Stage
ra
sfe
You will enable the option to send build pipeline parameters so that the deployment task can
an
run successfully.
-tr
. non
1. Open your DevOps project IAD-DOP-LAB10-1-DP-01-<userID>.
2. Select Build Pipelines from the left menu and click IAD-DOP-LAB12-1-BPL-01.
ide a
Gu as
3. Click the three dots on Trigger OKE Deployment and click View details.
is ) h
e om
4. Click Edit Stage and select the Send build pipelines Parameters checkbox.
us il.c
th
You will learn about query expressions and components, and you will execute sample queries
that can be used with the Monitoring. The Metrics Explorer creates queries that are used to
search and aggregate metric data points collected from resources.
A standard query includes a metric namespace (the source or application being measured), a
se
metric (what is being measured), an interval (over what period), and a statistic (how it’s being
en
measured, for example, a sum, rate, or max value).
lic
bl e
Tasks
ra
sfe
Create Standard Queries
an
1. Open the navigation menu and select Observability & Management. Under Monitoring,
-tr
. non
click Metrics Explorer.
2. To create a standard query, scroll down to the Query section and enter the following
ide a
Gu as
values:
is ) h
If the chart does not display the data, select Last 24 hours under Quick Selects on top of
e
an
the page. You can also toggle between Show Data Table and Show Graph option.
(ri
The chart generated is the output of the query. It represents the number of pulls done on the
E
AN
code repository in every 1-minute interval. The corresponding Monitoring Query Language
(MQL) is displayed under Query 1.
RI
iss
A filter condition is used along with a standard query to display graphs that satisfy specific
conditions. The filter condition is entered in the metric dimensions area which is optional and
includes a dimension name and a dimension value.
2. Enter the following values to create a grouping function using the Basic mode in the
Query section:
• Compartment: Select your <assigned compartment>.
se
• Metric namespace: Select oci_devops_build from the drop-down list.
en
• Metric name: Select StageExecutionTime from the drop-down list.
lic
• Interval: Select 1m from the drop-down list.
bl e
• Statistic: Select Mean from the drop-down list.
ra
sfe
3. In the Metric dimensions section, enter the following values:
an
• Dimension name: Select stageType from the drop-down list.
-tr
• Dimension value: Select BUILD from the drop-down list.
. non
• Do not enable the Aggregate metric streams.
The graph displays the time chart with time taken to execute the build stage. If the chart
e om
does not display data, select Last 24 hours under Quick Selects on top of the page. You
can also toggle between Show Data Table and Show Graph option.
us il.c
th
to gma
list.
an
The graph displays the time chart with time taken to complete trigger deployment pipeline
iss
stage.
Dr
The simple aggregation (grouping) function queries return the combined value of all metric
streams for the selected statistic. They can be written manually in the Query Code Editor pane
by checking the Advanced mode option, or you can use the Standard Query mode used above.
1. From the navigation menu, select Observability & Management. Under Monitoring,
se
click Metrics Explorer.
en
lic
2. Enter the following values to create a grouping function using Basic mode in the Query
bl e
section:
ra
• Compartment: Select your <assigned compartment>.
sfe
• Metric namespace: Select oci_devops_build from the drop-down list.
an
• Metric name: Select BuildSuccess from the drop-down list.
-tr
• Interval: Select 1m from the drop-down list.
. non
• Statistic: Select Mean from the drop-down list.
3. ide a
In the Metric dimensions section, enter the following values:
Gu as
is ) h
• Dimension value: Select <Project OCID> from the drop-down list. This is the OCID
of the DevOps project IAD-DOP-LAB10-1-DP-01-<userID>.
us il.c
th
If the chart does not display data, select Last 24 hours under Quick Selects on top of the
r
.d
page. You can also toggle between Show Data Table and Show Graph option.
e
an
The graph displays the aggregation of successful builds run on the project, with an interval of 1
(ri
minute, and a statistic option of the Mean function. The function Mean returns the value of
E
The selection of Aggregate metric streams check box is referred to as grouping function
RI
while using Advanced mode. This query can be viewed with selecting Advanced mode check
iss
box.
Dr
The nested queries are written as part of the Advanced mode in the Query code editor.
1. Open the navigation menu and select Observability & Management. Under Monitoring,
click Metrics Explorer.
se
2. Enter the following values to create a grouping function using Basic mode in the Query
en
section:
lic
• Compartment: Select your <assigned compartment>.
bl e
• Metric namespace: Select oci_devops_deployment from the drop-down list.
ra
• Metric name: Select DeploymentExecutionTime from the drop-down list.
sfe
• Interval: Select 1m from the drop-down list.
an
• Statistic: Select Max from the drop-down list.
-tr
. non
3. Leave the Metric dimensions section blank. Do not enable Aggregate metric streams
and click Update Chart.
ide a
Gu as
If the chart does not display data, select Last 7 days under Quick Selects on top of the
is ) h
page.
e om
The graph shows the deployment executions and time taken to complete in milliseconds,
us il.c
th
collected with an interval of 1m and shows the maximum reported duration of each
to gma
Deployment. You can also toggle between Show Data Table and Show Graph option.
@
4. Select the Advanced mode checkbox at the top-right corner of the Query 1 section.
riss
The displayed output groups the deployments and displays the ones that took more than
RI
Congratulations! You have successfully tested various types of Alarms and Monitoring Queries
which can be used with DevOps pipelines.
1. Open the navigation menu and select Observability & Management. Under Monitoring,
click Alarm Definitions.
se
2. Select your <assigned compartment> from List scope on the left menu.
en
lic
3. Select all the check boxes that correspond to the alarms IAD-DOP-LAB13-1-ALA-01, IAD-
bl e
DOP-LAB13-1-ALA-02, and IAD-DOP-LAB13-1-ALA-03.
ra
4. Click the Actions drop-down list and select Delete alarms.
sfe
an
5. Confirm to delete and click Close.
-tr
Purge Instructions for Topics and Subscriptions
. non
6. From the navigation menu, select Developer Services. Under Application Integration, click
ide a
Gu as
Notifications.
is ) h
8. Click the three dots on the right of the subscription to open the Actions menu and click
th
Delete.
to gma
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
. non
Lab 14-1 Practices -tr
OCI Console
an
sfe
ra
bl e
Estimated time: 40 minutes
lic
en
se
DevOps Project Log Using
Logging Services: Manage
Get Started
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Overview
The Oracle Cloud Infrastructure Logging service offers a fully managed, highly scalable single
point of access to all the logs in your tenancy. Logging provides access to logs from Oracle
se
Cloud Infrastructure resources. These logs include critical diagnostic information that
en
describes how resources are performing and being accessed.
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
For more information on OCI Logging, see the OCI Logging Documentation.
e
an
(ri
Prerequisites
E
• You must complete the following labs before you perform tasks for this practice:
AN
− Microservices and Container Orchestration: Create and work with OCIR repository
Dr
(Lab 07-1).
− Microservices and Orchestration: Set up cluster access (Lab 08-1).
− Microservice and Container Orchestration: Deploy a sample Web application on a
cluster using kubectl (Lab 09-1).
se
en
Assumptions
lic
• You are signed into your Oracle Cloud Infrastructure (OCI) account using your
bl e
credentials.
ra
• This lab assumes you’re working in the Ashburn region. The resource naming
sfe
convention (iad) used in this lab is according to Ashburn.
an
If you’re working in a different region, change the resource names accordingly. For
-tr
example, for Phoenix, use phx.
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
The log groups are logical containers for organizing and managing logs. A log must always be
inside a log group. You will first create a log group to enable or create logs.
After creating a log group, you will update logging for the DevOps Project.
se
Tasks
en
lic
1. Open the navigation menu and select Observability & Management. Under Logging,
bl e
click Log Groups.
ra
2.
sfe
Select your <assigned compartment> from List scope on the left menu.
an
3. Click Create Log Group.
-tr
. non
4. In the Create Log Group window, enter the following values:
• Compartment: auto-populated with your <assigned-compartment>.
• Name: IAD-DOP-LAB14-1-LGP-01 ide a
Gu as
is ) h
5. Click Create.
us il.c
th
to gma
Note: The DevOps Project is created with logs enabled with a default log group named
Default_Group. You will change this log group to IAD-DOP-LAB14-1-LGP-01 and create a
@
6. Open the navigation menu and select Developer Services. Under DevOps, click Projects.
r
e .d
9. Click the three dots on the right to open the Actions menu and click Edit Log.
RI
a. Click the Change Log Group button under the Choose new group field. Select IAD-
iss
10. Open the navigation menu and select Observability & Management. Under Logging,
click Log Groups.
11. Select your <assigned compartment> from List scope on the left menu.
se
12. Click Log Group IAD-DOP-LAB14-1-LGP-01.
en
13. Click Logs, verify the log name with IAD-DOP-LAB14-1-SLOG-01 is shown Active for
lic
Service: DevOps; Category: DevOps Logs.
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
Execute the build pipeline which will trigger the deployment pipeline as well. During and after
the execution for build and deployment pipelines, the logs are generated.
Tasks
se
1. Open the DevOps project IAD-DOP-LAB10-DP-01-<userID>.
en
lic
2. Select Build Pipelines on the left menu and click IAD-DOP-LAB12-1-BPL-01.
bl e
3. Verify that three stages are available in the build pipeline: Build-Demo-WebApp, Push
ra
sfe
WebApp Artifacts, and Trigger OKE Deployment.
an
4. Click Start manual run on the top right corner of the page.
-tr
. non
5. Keep Build run name as default and click Start manual run.
ide a
The Status on the top left will be shown as In progress, and the execution will take
Gu as
approximately 5 minutes to complete.
is ) h
the top of the page and click Deployments from the left menu.
Logging provides the tools to search any combination or scale of logs to identify events or
patterns that may be difficult to observe via legacy methods. This is especially true when
working in a distributed scale-out environment comprising several services and platforms.
You will explore the contents of your logs and become familiar with the built-in search
se
capabilities provided by the logging service. You will learn to select service logs to be included
en
in search, examine results, and refine search for service logs. Additionally, you will update a
lic
build stage and execute build run to generate corresponding log records.
bl e
ra
You will also learn to search logs from saved searches.
sfe
Tasks
an
-tr
Search your logs
. non
1. Open the navigation menu and select Observability & Management. Under Logging,
ide a
Gu as
click Search.
is ) h
2. Click Select logs to search text field. The Select logs to search window appears.
e om
us il.c
3. In the Select logs to search field, click (x) to remove your <assigned_compartment> if
th
selected by default.
to gma
4. Expand the root compartment under the Compartment column and select your
@
Note: Do not click the plus (+) sign. Click the compartment name only.
e
an
This will bring up the log groups in that compartment without including the compartment
(ri
itself as part of the search criteria. You don’t want the compartment itself included,
E
because you don’t want all the logs for that compartment in the search results.
AN
RI
5. In the Log Groups column, select IAD-DOP-LAB14-1-LGP-01 log group, but again, click
the name only without clicking the plus (+) sign. This will bring up the logs for that log
iss
group.
Dr
6. In the Logs column, select IAD-DOP-LAB14-1-SLOG-01 log. This time, click the plus (+)
sign to add it as the only search criteria. The Select logs to search field at the top of the
window will be updated to <assigned_compartment>/IAD-DOP-LAB14-1-LGP-
01/IAD-DOP-LAB14-1-SLOG-01.
Explore Filters
1. To examine results and refine search for service logs, in the Custom filters field at the top
of the Search area, enter the following and hit enter on your keyboard:
data.deployPipelineId = <Select pipleline OCID from the list>
se
en
This will show the log records that were executed for the selected pipeline.
lic
2. If there are no log records displayed, then Filter by time and select Today from the drop-
bl e
down list. This will return all the log records matching the condition for the entire day.
ra
sfe
3. In the Custom filters field at the top of the Search area, enter the following and hit enter
an
on your keyboard:
-tr
data.message = Completed Deployment execution
. non
This will show the log records that contains the message Completed Deployment
execution for the selected pipeline.
ide a
Gu as
is ) h
Note: You can remove the search filters by clicking (x) for Filters under Custom filters.
e om
4. In the Custom filters, enter the keyword failed and hit Enter on your keyboard.
us il.c
th
The Filters will show the following filter applied, which returns log records that contain
to gma
logContent=’*failed*’
iss
5. Select Filter by time as Past 5 minutes. Verify there is no recent log data. You may note
r
.d
3. Click the three dots on Trigger OKE Deployment and click View details.
se
en
4. Click Edit Stage and uncheck to disable the Send build pipelines Parameters box.
lic
Note: This will block the build pipeline parameters to be shared with deployment pipeline
bl e
and thus trigger a failure in deployment.
ra
sfe
5. Click Save changes.
an
6. Click Start manual run.
-tr
. non
7. Keep the build run name as default and click Start manual run.
8. ide a
Wait until the status of build run shows Succeeded.
Gu as
is ) h
the top of the page and click Deployments from the left menu.
us il.c
11. From the navigation menu, select Observability & Management, then click Search under
@
Logging. Under Logging, click Saved Searches to reach previously saved search
iss
Deployment-failures.
r
.d
12. Choose Filter by time as Past 15 minutes if the data is not shown for Past 5 minutes.
e
an
Verify the log records containing the string failed is shown for the deployment failures.
(ri
13. Expand one of the log records by clicking the down-arrow icon on the right.
E
AN
a. On the JSON tab, the log data is shown in JSON format. Review the message under
RI
the data section, which shows the log message for the failure.
iss
b. Click the Before & After Tab. This shows the logs representing what was going on
Dr
before and after the log message was generated, which helps in the troubleshooting.
14. From the OCI Console Main Menu, select Developer Services. Under DevOps, select
Projects.
17. Select Build Pipelines on the left and click the pipeline IAD-DOP-LAB12-1-BPL-01.
18. Click the three dots on Trigger OKE Deployment stage. Click View details.
se
en
19. Click Edit Stage, enable Send build pipelines Parameters.
lic
20. Click Save changes, Do NOT click Start manual run.
bl e
21. Click DevOps Projects on top to return to the Projects page.
ra
sfe
an
-tr
Congratulations! You have successfully configured and explored logs for your build and
. non
deployment pipelines in your DevOps Project.
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
1. Open the navigation menu and select Observability and Management. Under Logging,
click Log Groups.
se
2. Click IAD-DOP-LAB14-1-LGP-01 log group.
en
lic
3. Under Resources in the left menu, click Logs.
bl e
4. For IAD-DOP-LAB14-1-SLOG-01, click the three dots on the right to open the Actions
ra
menu and click Delete. Confirm to Delete.
sfe
an
5. Click Log Group.
-tr
. non
6. For IAD-DOP-LAB14-1-LGP-01, click the three dots on the right to open the Actions menu
and click Delete. Confirm to Delete.
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
194
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
Occurs
ide a
. non
-tr
Lab 15-1 Practices
an
sfe
ra
Estimated Time: 20 minutes bl e
lic
en
When a DevOps Event
se
Event Service: Define Rules
that Trigger a Specific Action
Get Started
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Overview
Oracle Cloud Infrastructure (OCI) Events enables the creation of automations based on
resource state changes across the tenancy. Use Events to allow your development teams to
se
react automatically when a resource changes state.
en
Events are structured messages indicating changes in resources.
lic
bl e
The use of events goes through the creation of rules. The rules include a filter that you define
ra
to indicate events produced by resources in your tenancy.
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
r iss
.d
a. Configure a notification
(ri
E
For more information on OCI Events, see the OCI Events Documentation.
Dr
196 Define rules that trigger a specific action when a DevOps event occurs
Prerequisites
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
• You must complete the following labs before you perform tasks for this practice:
− Microservices and Container Orchestration: Create Docker image for a web
application using Dockerfile (Lab 06-1).
− Microservices and Container Orchestration: Create and work with OCIR repository
se
(Lab 07-1).
en
− Microservices and Orchestration: Set up cluster access (Lab 08-1).
lic
− Microservice and Container Orchestration: Deploy a sample Web application on a
bl e
cluster using kubectl (Lab 09-1).
ra
− Continuous Integration and Continuous Delivery: Work with code repositories in OCI
sfe
DevOps project (Lab10-1).
an
− Continuous Integration and Continuous Delivery: Create and set up artifacts and
-tr
environments in DevOps project (Lab11-1).
. non
− Continuous Integration and Continuous Delivery: Deploy a Web App with a CI/CD
pipeline to an OKE cluster using OCI DevOps (Lab12-1)
• ide a
You are signed into your Oracle Cloud Infrastructure (OCI) account using your
Gu as
credentials.
is ) h
e om
Assumptions
us il.c
th
• This lab assumes you’re working in the Ashburn region. The resource naming
to gma
If you’re working in a different region, change the resource names accordingly. For
iss
• You will replace the <userID> placeholder with your user ID.
e .d
an
(ri
E
AN
RI
iss
Dr
Define rules that trigger a specific action when a DevOps event occurs 197
Configure a Notification
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Events Rules specify an action to trigger when the filter finds a matching event. The Action can
be the Notifications service to notify based on the rule conditions defined.
To configure an Events Rule, you must first create a Notifications Topic and Subscription so
that the rule condition has a way to notify the relevant parties.
se
en
Tasks
lic
bl e
1. Open the navigation menu and select Developer Services. Under Application
ra
Integration, select Notifications.
sfe
2. Select your <assigned compartment> from List scope on the left menu.
an
-tr
3. Click Create Topic and enter the following values in the form:
. non
• Name iad-dop-lab15-1-nt-01-<userID>
ide a
For Example, iad-dop-lab15-1-nt-01-user22
Gu as
• Description Topic for Lab15.
is ) h
e om
Note: Topic name must be unique across the tenancy; validation is case-sensitive.
us il.c
4. Click Create.
th
to gma
5. Once the topic changes state to Active, click the topic to view the details.
@
6. Select Subscriptions under Resources on the left menu, click Create Subscription and
iss
7. Click Create.
E
AN
8. Click the subscription that you just created. The Subscription Information will be displayed
RI
9. Check the verification email received on the email account you specified. Click the
Confirm subscription verification link. A pop-up browser window will tell you that the
subscription has been confirmed.
Note: If the email does not arrive in the inbox, look for it in the Promotions category or
the spam box.
198 Define rules that trigger a specific action when a DevOps event occurs
10. Navigate back to the Subscriptions page and verify that the subscription status has
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
changed to Active. You may need to refresh your browser if the status is not updated.
se
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
riss
e .d
an
(ri
E
AN
RI
iss
Dr
Define rules that trigger a specific action when a DevOps event occurs 199
Create an Event Rule
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
You will create Events Rule with few conditions and an action to send a notification.
Tasks
1. Open the navigation menu and select Observability & Management. Under Events, click
se
Rules.
en
lic
2. Select your <assigned compartment> from List scope on the left menu.
bl e
3. Click Create Rule and enter the following values in the form:
ra
sfe
a. Display Name: IAD-DOP-LAB15-1-RLE-01
an
-tr
b. Description: Notify on Build Runs and Deployments.
. non
c. Under the Rule Conditions section, choose Condition as Event Type and Service
Name as DevOps Build.
ide a
Gu as
is ) h
200 Define rules that trigger a specific action when a DevOps event occurs
Validate Event Rule by Running a Build
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Execute a manual build run from DevOps Project. After the build run, an email will be triggered
with event details.
Tasks
se
1. Open the navigation menu and select Developer Services. Under DevOps, select
en
Projects.
lic
bl e
2. Select your <assigned compartment> from List scope on the left menu.
ra
sfe
3. Open the DevOps project IAD-DOP-LAB10-1-DP-01-<userID>.
an
4. Select Build Pipelines on the left menu and click the IAD-DOP-LAB12-1-BPL-01 pipeline.
-tr
. non
5. Verify the three stages are available: Build WebApp, Push WebApp Artifacts, and Trigger
OKE Deployment.
ide a
Gu as
6. Click Start manual run on the top right. Enter the Build run name as IAD-DOP-LAB15-1-
is ) h
BRUN-01.
e om
7. Click Start manual run. A Build Run is created with name IAD-DOP-LAB15-1-BRUN-01.
us il.c
th
to gma
Define rules that trigger a specific action when a DevOps event occurs 201
9. Open the navigation menu, select Observability & Management. Under Events, click
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Rules.
10. Select your <assigned compartment> from List scope on the left menu.
se
12. Under Rule Conditions, click + Another Condition to add a second condition as follows:
en
• Condition: Event Type
lic
• Service Name: Devops Deploy
bl e
• Click within Event Type field and select: DeployStage – Create Begin, and
ra
Deployment – Create.
sfe
13. Click Save changes.
an
-tr
After updating the event rule, execute another manual build run to receive email
. non
notification according to the updated event rules.
ide a
14. Open the DevOps project IAD-DOP-LAB10-1-DP-01-<userID>.
Gu as
is ) h
15. Select Build Pipelines on the left menu and click the IAD-DOP-LAB11-1-BPL-1 pipeline.
e om
16. Verify the three stages are available: Build WebApp, Push WebApp Artifacts, and Trigger
us il.c
th
OKE Deployment.
to gma
17. Click Start manual run on top right. Enter the Build run name as IAD-DOP-LAB15-1-
@
BRUN-02.
iss
18. Click Start manual run. A Build Run is created with name IAD-DOP-LAB15-1-BRUN-02.
r
e.d
an
19. You will receive an email with the subject line Event -
(ri
202 Define rules that trigger a specific action when a DevOps event occurs
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
se
en
lic
bl e
ra
sfe
20. You will receive another email with the subject line Event -
an
com.oraclecloud.devopsbuild.createdeployment along with Event details in the body in
-tr
JSON format.
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
riss
e .d
an
(ri
E
AN
Congratulations! You have successfully configured event rules to trigger email notifications for
RI
specific actions.
iss
Dr
Define rules that trigger a specific action when a DevOps event occurs 203
Purge Instructions
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
1. Open the navigation menu and select Observability & Management. Under Events, click
Rules.
se
2. Select your <assigned compartment> from List scope on the left menu.
en
lic
3. For the rule IAD-DOP-LAB15-1-RLE-01, click the three dots on the right to open the
bl e
Actions menu and select Delete
ra
4. Type DELETE to confirm, click Delete.
sfe
an
Purge Instructions for Subscription
-tr
1. Open the navigation menu and select Developer Services. Under Application
. non
Integration, click Notifications.
ide a
Gu as
2. Select your <assigned compartment> from List scope on the left menu.
is ) h
4. For the subscription, click the three dots on the right to open the Actions menu and select
th
Delete.
to gma
1. Open the navigation menu and select Developer Services. Under Application Integration,
e
an
click Notifications.
(ri
2. Select your <assigned compartment> from List scope on the left menu.
E
AN
3. For the topic IAD-DOP-LAB15-1-TOP-01, click the three dots on the right to open the
RI
204 Define rules that trigger a specific action when a DevOps event occurs
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
DevOps
ide a
. non
-tr
Overview
Rapid delivery of software is essential for efficiently running your applications in the cloud.
Automating software releases with pipeline deployment increases developer productivity and
se
allows you to release features more frequently and with fewer errors. It helps avoid downtime
en
during deployments and automates the complexity of updating applications.
lic
The Oracle Cloud Infrastructure (OCI) DevOps service is an end-to-end, continuous integration
bl e
and continuous delivery (CI/CD) platform for developers. You can use OCI DevOps service to
ra
easily build, test, and deploy software and applications on Oracle Cloud. The DevOps build and
sfe
deployment pipelines reduce change-driven errors and decrease the time customers spend on
an
building and deploying releases.
-tr
. non
Oracle Cloud Infrastructure (OCI) DevOps service supports deployment of Helm charts to
Container Engine for Kubernetes (OKE) cluster. The developers can add a specific Helm chart
ide a
stage to deployment pipelines to automate the Helm deployment and automatically roll back
Gu as
on OKE environments.
is ) h
e om
us il.c
th
to gma
@
riss
e .d
an
(ri
E
AN
RI
iss
Dr
276 Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps in OCI DevOps
For more information on OCI DevOps Project Helm Chart Deployment, see the OCI Deploying
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
se
b. Create OCIR repositories for Container Image and Helm Chart
en
c. Set up artifacts and environments for your DevOps project
lic
bl e
d. Create DevOps build pipeline and build stages
ra
sfe
e. Create DevOps deployment pipeline and deploy stage
an
f. Create a Trigger Deployment Stage in build pipeline
-tr
. non
g. Set up the kubeconfig file and create a Kubernetes namespace.
h.
ide a
Automate sample web application deployment to OKE cluster using Helm Chart
Gu as
is ) h
Prerequisites
us il.c
th
• You are signed in to your Oracle Cloud Infrastructure (OCI) account using your
to gma
credentials.
@
compartment. <EventID> can be fetched from the Lab tab available in the course
e .d
page.
an
(ri
Assumptions
E
AN
• You will replace the <userID> placeholder with your user ID.
• This lab assumes you’re working in the Ashburn region. The resource naming
RI
If you’re working in a different region, change the resource names accordingly. For
Dr
Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps 277
Create a DevOps Project and Manage Code Repositories
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
You will fork a repository, create access token, and use an existing Vault that is at the root level
compartment to create keys and secrets required to connect to an external repository.
You’ll then create a topic, a DevOps project, and a connection to external repositories, such as
GitHub.
se
en
You’ll also learn to mirror repositories to and from external sources.
lic
bl e
Fork GitHub Repository
ra
1. Sign in to your GitHub account and go to the https://github.com/ou-developers/oci-
sfe
helm-node-service repository.
an
-tr
2. In the top right, click Fork and then click Create fork at the bottom of Create a new fork
. non
page.
ide a
Note: By default, forks use the same name as their upstream repository.
Gu as
is ) h
1. In your GitHub account, click the profile icon on the top-right corner, and then go to
us il.c
th
Settings.
to gma
2. Navigate to Developer settings and find Personal access tokens > Token (classic) on
@
the left menu and then click Generate new token > Generate new token (classic) for
iss
general use.
r
.d
c. In the Select scopes section, select repo (Full control of private repositories) as your
iss
scope
Dr
4. Click Generate token and make a note of it in a notepad. You’ll need this token later when
you create secrets. Here’s an example how a token would look like:
ghp_YnDABCDEPQRxzGZXXXXduoAZgrPemTj1xxXxx
278 Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps in OCI DevOps
Create a Master Encryption Key in OCI Vault
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
1. Switch to the OCI Console, navigate to Identity & Security, and select Vault. From the list
of vaults, select OCI-ELS-DEVOPS-VAULT-1 under the root compartment.
2. On the Vault details page, click Create Key to create a master encryption key.
se
Enter the following values for your key:
en
• Create in Compartment: Select your <assigned compartment>.
lic
• Protection Mode: HSM
bl e
• Name: iad-dop-lab18-1-vk-01
ra
sfe
• Leave everything else to default values and click Create Key.
It will take about a minute to create the master encryption key. The key will go from the
an
Creating state to the Enabled state.
-tr
. non
3. On the Vault details page, select your <assigned compartment> from List scope on
the left menu. You’ll see the key “iad-dop-lab18-1-vk-01” that you created which is
ide a
Gu as
in Enabled state.
is ) h
1. In the Resources section of the Vault details page, click Secrets. Click Create Secret and
th
to gma
• Name: iad-dop-lab18-1-vs-01-<userID>
iss
• Secret Contents: <Add the Personal access token string that you created in GitHub
earlier>
RI
• Click Create Secret. It will take few minutes to create the Vault Secret. The secret will
iss
Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps 279
Create a Topic
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
1. In the Console, open the navigation menu and click Developer Services. Under
Application Integration, click Notifications.
2. Select your <assigned compartment> from List scope on the left menu. The page
updates to display only the resources in that compartment.
se
en
3. Click Topics. Click Create Topic at the top of the topic list.
lic
bl e
4. In the Create Topic page, configure your topic and click Create.
• Name: iad-dop-lab18-1-nt-01-<userID>.
ra
sfe
• Description: This topic is for my Devops lab.
an
Note: Topic name is case-sensitive and must be unique across the tenancy.
-tr
. non
Create a DevOps project
1. ide a
Open the navigation menu and click Developer Services. Under DevOps, click Projects.
Gu as
is ) h
• Name: IAD-DOP-LAB18-1-DP-01-<userID>
us il.c
• To set up project notifications, click Select Topic. Select the topic that you created
earlier, for example iad-dop-lab18-1-nt-01-user22. Project notifications keep you
@
3. You can use the OCI logging service to record the output it generates when the pipeline
an
runs. On the page of your newly created project, click Enable Log which takes you to the
(ri
4. In the Logs table, toggle to enable the log. This will pop-up to the Enable Log window.
RI
Leave all the options as default and click Enable Log at the bottom. The logs will go
iss
through the Creating state to the Active state. You have successfully created a DevOps
Dr
project.
280 Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps in OCI DevOps
Create an External Connection
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
1. Open the navigation menu and click Developer Services. Under DevOps, click Projects.
se
• Name: IAD-DOP-LAB18-1-EC-01
en
• Description: Connecting to GitHub.
lic
• Type: GitHub
bl e
• In the Vault Secret section,
ra
1)
sfe
Click Change Compartment and select the root compartment.
an
2) Select the Vault OCI-ELS-DEVOPS-VAULT-1 from the drop-down list.
-tr
. non
3) Select the secret iad-dop-lab18-1-vs-01-<userID> within you compartment that
contains your Personal Access Token (PAT) to connect to GitHub.
• Click Create. ide a
Gu as
is ) h
The connection to the selected external repository is successfully created and active.
e om
2. Click Code Repositories on the left menu and then click Mirror Repository to mirror
iss
• Mirroring Schedule: Select Custom from the drop-down list and set the minutes
AN
field to 2.
RI
• Name: IAD-DOP-LAB18-1-MR-01
iss
Click Mirror repository at the bottom. After some time, the mirrored repository will be
available in OCI Code Repository.
Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps 281
3. You will have to update the build_spec.yaml file in your git repository to have it
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
se
en
c. Click the Edit this file option and make the following two changes in the highlighted
lic
section:
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
• Scroll to the end of the file and locate line containing following code:
e om
service-<userID> .
th
to gma
service-user22 .
r
e .d
• Move to the last line of this file and make the following change in the
an
outputArtifacts section:
(ri
location: iad-dop-lab18-1-ocir-1/node-service-<userID>:latest
E
AN
iad-dop-lab18-1-ocir-1/node-service-user22:latest
iss
e. Switch to the OCI Console, navigate to the Mirrored Code Repository IAD-DOP-
LAB18-1-MR-01. You’ll see a message “Mirroring is in Progress” at the top of the
page. You can also start the Mirroring process manually by clicking the Synchronize
now button.
282 Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps in OCI DevOps
f. After two minutes, click Files from the left menu and scan through the
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
build_spec.yaml file to see if the changes are now reflecting in the mirrored OCI
Repository.
se
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps 283
Create OCI Repositories for Container Image and Helm
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Chart
You will create two empty repositories in your compartment and give them a name that's
unique in the entire tenancy. One repository will be used to host the container image and the
other one for Helm artifacts.
se
en
Tasks
lic
1. Navigate to the Oracle Cloud Infrastructure Registry (OCIR):
bl e
ra
a. In the Console, open the navigation menu and click Developer Services. Under
sfe
Containers & Artifacts, click Container Registry.
an
b. Select your <assigned compartment> from List scope on the left menu.
-tr
. non
2. Click Create Repository to create a new repository.
a. ide a
Compartment: Select your <assigned compartment>.
Gu as
is ) h
<userID>
us il.c
th
Where,
to gma
• <region-key> is the key for the Oracle Cloud Infrastructure Registry region
you're using. For example, iad is the region key for US EAST (Ashburn)
@
iss
region. See the Availability by Region topic in the Oracle Cloud Infrastructure
documentation.
r
.d
3. Now, repeat the Step 2 to create another public repository with the name <region-
Dr
key>-dop-lab18-1-ocir-2/helm-repo-<userID>/node-service
284 Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps in OCI DevOps
Set Up Artifacts and Environments for Your DevOps
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Project
Artifacts are used to specify software package versions for deployment. DevOps artifacts can
be of following types:
• Container image repository
se
• Instance group deployment configuration
en
• Kubernetes manifest
lic
• General artifact
bl e
• Helm Chart
ra
sfe
You will add Container image repository, Helm Chart, and general artifacts to the OCI
an
Repositories. Additionally, you will create an environment to point to your OKE cluster which
-tr
will work as a target platform for your application.
. non
Tasks
ide a
Gu as
1. Let’s add the container image repository artifact. Open the navigation menu and click
is ) h
2. Select your <assigned compartment> from List scope on the left menu.
us il.c
th
to gma
4. Click Artifacts from the left menu to navigate to the artifacts page.
iss
5. Click Add artifact to create an artifact and fill the form with following values:
r
.d
• Name: IAD-DOP-LAB18-1-AF-01
e
an
<region-key>.ocir.io/<tenancy-namespace>/<repo-name>:<tag>
AN
RI
For example,
iss
iad.ocir.io/oracletenancy/iad-dop-lab18-1-ocir-1/node-service-
user22:${BUILDRUN_HASH}
Dr
Note: Replace <tenancy-namespace> with your tenancy name and <userID> with your
user ID and ensure you append ${BUILDRUN_HASH} in the fully qualified image URL.
This dynamically updates the version of the pushed docker image.
• Select Allow parameterization and click Add.
Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps 285
6. Again, click Add artifact to create a Helm Chart artifact and enter the following values in
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
the form:
• Name: IAD-DOP-LAB18-1-AF-02
• Type: Select Helm Chart from the list of options.
• Helm Chart URL:
oci://<region-key>.ocir.io/<tenancy-namespace>/<repo-name>:<tag>
se
en
For example,
lic
oci://iad.ocir.io/oracletenancy/iad-dop-lab18-1-ocir-2/helm-
repo-<userID>/node-service
bl e
ra
Note: Replace <tenancy-namespace> with your tenancy name, <region-key> with
sfe
the code for the region in use i.e., iad, <userID> with your user ID.
an
• Version: 0.1.0-${BUILDRUN_HASH}
-tr
• Click Add.
. non
7. Finally, click Add artifact to create a Generic artifact and enter the following values in the
form: ide a
Gu as
• Name: values.yaml
is ) h
replicaCount: 3
@
service:
iss
type: LoadBalancer
r
.d
port: 80
e
an
image:
(ri
repository: iad.ocir.io/<tenancy-namespace>/iad-dop-lab18-1-
E
ocir-1/node-service-<userID>
AN
pullPolicy: IfNotPresent
RI
tag: ${BUILDRUN_HASH}
Dr
Note: Replace <tenancy-namespace> with your tenancy name and <userID> with your
user ID under the image: section in the code snippet.
286 Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps in OCI DevOps
For example,
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
iad.ocir.io/oracletenancy/iad-dop-lab18-1-ocir-1/node-service-
user22
Note: Also ensure if you are working in any region other than US EAST(Ashburn) then
replace “iad” with the respective region key of the region you are working in. See
the Availability by Region topic in the Oracle Cloud Infrastructure documentation.
se
en
• Select Allow parameterization and click Add.
lic
8.
bl e
On the Artifacts page, you will see the following three artifacts created:
ra
Name Type Source Path Version
sfe
an
General
values.yaml Inline - -
-tr
artifact
. non
oci://iad.ocir.io/<tena 0.1.0-
IAD-DOP- ncy-namespace>/iad-dop-
LAB18-1-AF-
Helm ide a lab18-1-ocir-2/helm- ${BUILD
Gu as
Helm chart
Chart repo-<userID>/node- RUN_HAS
02
is ) h
service H}
e om
iad.ocir.io/<tenancy-
namespace>/iad-dop-
us il.c
IAD-DOP-
lab18-1-ocir-1/node-
th
Docker OCI
LAB18-1-AF- -
to gma
After creating the artifacts, you’ll now create an Environment for your project.
r
.d
10. Click Environments from the left menu to navigate to the environments page.
E
11. Click Create environment. Select Oracle Kubernetes Engine as the Environment Type.
AN
RI
− Name: IAD-DOP-LAB18-1-ENV-01
Dr
Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps 287
b. Click Next and enter the following information:
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
− Region: The region you are working in. This is populated by default.
− Compartment: Select the root compartment.
− Cluster: Select <EventID>-OCI-ELS-DEVOPS-OKE from the list.
se
en
You will now see the environment IAD-DOP-LAB18-1-ENV-01 in Active state, listed on the
lic
Environment details page in your DevOps project IAD-DOP-LAB18-1-DP-01-<userID>.
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
riss
e .d
an
(ri
E
AN
RI
iss
Dr
288 Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps in OCI DevOps
Create DevOps Build Pipeline and Build Stages
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
A build pipeline contains the stages that define the build process for successfully compiling,
testing, and running software applications before deployment.
A stage is an action in the build pipeline. The OCI DevOps service includes the following
predefined stages that you can use in a build pipeline:
se
en
• Managed Build: Build and test your software applications.
lic
• Deliver Artifacts: Store your software applications created from the Managed Build
bl e
stage in the OCI Artifact Registry or OCI Container Registry repositories.
• Trigger Deployment: Start a deployment pipeline to deploy the output from the
ra
sfe
build pipeline.
an
• Wait: Pause a specific duration for testing the build pipeline.
-tr
You can add multiple stages to a pipeline. Stages can be added in a sequence or in parallel.
. non
You can remove any stage from the pipeline. When you do, the stage and its associated
resources are deleted.
ide a
Gu as
In this lab, you will create DevOps build pipeline and build stages.
is ) h
e om
Tasks
us il.c
th
1. Open the navigation menu and click Developer Services. Under DevOps, click Projects.
to gma
2. Select your <assigned compartment> from List scope on the left menu.
@
iss
4.
e
Click Build Pipelines from the left menu to navigate to the Build pipelines page.
an
(ri
5. Click Create build pipeline and enter the following values in the form:
E
• Name: IAD-DOP-LAB18-1-BPL-01
AN
7. To add the first stage to the build pipeline, click the (+) icon and click Add stage.
Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps 289
8. Select Managed Build as stage type and click Next. Only fill the fields mentioned here
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
se
build pipeline uses to run a build. The file build_spec.yaml is in the root directory,
en
so you will leave this field blank.
lic
• Primary code repository: Click Select. This opens the window to select Primary code
bl e
repository:
ra
sfe
a. Select the OCI Code Repository from the drop-down list for Source: Connection
type.
an
-tr
This will populate the Code repositories available within your DevOps project.
. non
b. Select the code repository IAD-DOP-LAB18-1-MR-01.
ide a
Gu as
c. Select the main branch.
is ) h
e om
e. Click Select.
th
to gma
9. Click Add. You will notice a stage with name Build-Demo-Node-service (Managed
@
10. Add the second stage to the Build pipeline by clicking the (+) icon at the bottom of the
r
.d
11. Select Deliver Artifacts as stage type from the optional section and click Next. Fill the
(ri
• Click the Select Artifact(s) button: Select the following artifact and click Add.
Dr
You will see the artifact now listed on the Add stage page.
290 Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps in OCI DevOps
12. Associate artifacts with build result: In this section, you will provide the output names
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
se
en
lic
bl e
ra
sfe
The build_spec.yaml is available in the root directory of your DevOps code repository
IAD-DOP-LAB18-1-CR-01.
an
-tr
After reading through the code snippet, you will be able to identify the output name used
. non
for image artifact type. Fill the field as shown in the following table:
13. Click Add. You will notice a stage with name Push Node Service Artifacts (Deliver
us il.c
th
Artifacts) added.
to gma
Note: At this point you have two stages in your Build pipeline IAD-DOP-LAB18-1-BPL-01.
@
iss
14. You will now create an auth token to be use with Oracle Cloud Infrastructure Registry
r
(OCIR):
e .d
an
a. In the top-right corner of the Console, open the Profile menu, and then click User
(ri
Settings.
E
AN
Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps 291
d. Click Generate Token. The new auth token is displayed. Here’s a sample of how an
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Note: Copy the auth token to a notepad because you won't see the auth token again
in the Console. You’ll need this auth token later in this lab.
For example,
se
R5kwpS-xxxxx((]51r]]
en
lic
15. Navigate back to the Devops project IAD-DOP-LAB18-1-DP-01-<userID> build pipeline
IAD-DOP-LAB18-1-BPL-01
bl e
ra
16. The build_spec.yaml file takes care of running build and pushing helm charts to the
sfe
OCI Repository. For publishing helm charts to OCIR, the credentials and OCIR path are
an
sent as parameters.
-tr
. non
Under Parameters tab, create below parameters with appropriate values.
Name
ide a
Default value Description
Gu as
oci://<REGION-
is ) h
KEY>.ocir.io/<tenancy-
OCIR Helm Repo
HELM_REPO_URL namespace>/<REGION-KEY>-
e om
URL
dop-lab18-1-ocir-2/helm-
us il.c
repo-<userID>/
th
Username to
<tenancy-
HELM_REPO_USER publish helm
@
namespace>/<username>
package to OCIR
iss
Here,
an
• <region-key> is the key for the Oracle Cloud Infrastructure Registry region you're
using. For example, iad is the region key for US EAST (Ashburn) region. See
RI
• Replace <username> with your user ID from profile menu. For example, user22.
Dr
• The auth token IAD-DOP-LAB18-1-AT-01 (random string) you pasted to your notepad.
For example, XX6{KJr<q:zBdXXXXXX_.
292 Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps in OCI DevOps
The parameters will appear like the following table:
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
se
Username to
en
HELM_REPO_USER oracletenancy/user22 publish helm
lic
package to OCIR
USER_AUTH_TOKEN XX6{KJr<q:zBdXXXXXX_ User auth token
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps 293
Create DevOps Deployment Pipeline and Deploy Stage
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
A deployment pipeline holds the requirements that must be satisfied to deliver a set of
artifacts to the target environment. Deployment pipelines contain different stages for
automated deployment. Each stage is associated with certain actions in the pipeline.
DevOps service includes predefined stages, which could be readily used in a deployment
se
pipeline:
en
• Deploy based on Blue-Green strategy: Uses blue-green release strategy for
lic
Container Engine for Kubernetes (OKE) and instance group deployment.
bl e
• Deploy based on Canary strategy: Uses Canary release strategy for OKE and
ra
instance group deployment
sfe
• Deploying a Helm Chart: Install Helm charts in OKE cluster
an
You will create the DevOps deployment pipeline and add stage to deploy a helm chart.
-tr
. non
Tasks
1. ide a
Open the DevOps project IAD-DOP-LAB18-1-DP-01-<userID>. For example, IAD-DOP-
Gu as
LAB18-1-DP-01-user22.
is ) h
e om
2. Click Deployment Pipelines from the left menu to navigate to the Deployment pipelines
us il.c
page.
th
to gma
3. Click Create pipeline and enter the following values in the form:
@
• Name: IAD-DOP-LAB18-1-DPL-01
iss
5. To add a stage to the Deployment pipeline, click the (+) icon and click Add stage.
(ri
E
6. Select Install Helm chart to Kubernetes cluster as stage type and click Next. Enter the
AN
Note: Replace <userID> with your user ID. For example, user22.
294 Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps in OCI DevOps
• Under helm chart deploy artifact field, click Select Artifact. This opens the window to
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
add helm chart. Select the following artifact and click Save Changes.
• IAD-DOP-LAB18-1-AF-02 Helm Chart
You will see the artifact now listed on the Add stage page.
• Under select values artifacts (optional) field, click Select Artifact. This opens the
se
window to add values.yaml file. Select the following artifact and click Save
en
Changes.
lic
• values.yaml Generic artifact
bl e
You will see the artifact now listed on the Add stage page.
ra
• Override Kubernetes namespace: set this field as ns-helm-<userID>.
sfe
an
Note: Replace <userID> with your user ID. For example, ns-helm-user22.
-tr
• Timeout: Set timeout to 1200 seconds.
. non
• If validation fails, automatically rollback to the last successful version? Select Yes
ide a
to automatically rollback to last successful version.
Gu as
7. Click Add. You will notice a stage with name OCI-Helm-Chart-Deployment (Helm chart)
is ) h
added.
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps 295
Create a Trigger Deployment Stage in Build Pipeline
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
You will create a Trigger Deployment Stage within the build pipeline that triggers the
deployment pipeline to deploy the application based on the output artifacts from the build
pipeline execution and the helm charts.
Tasks
se
en
1. Navigate to the build pipeline IAD-DOP-LAB18-1-BPL-01 in your current DevOps project.
lic
bl e
2. On the Build Pipeline tab, click the (+) icon at the bottom of the Push-Node-Service-
ra
Artifacts (Deliver Artifacts) box and click Add stage.
sfe
3. Select Trigger Deployment as stage type from the optional section and click Next. Enter
an
the following values in the form:
-tr
• Stage name: Trigger Helm-Chart OKE Deployment
. non
• Description: This triggers the IAD-DOP-LAB18-1-DPL-01 Deployment
pipeline stages.
ide a
Gu as
• Click Select Deployment Pipeline. This opens the window to select the deployment
is ) h
4. Click Add. You will notice a stage with name Trigger Helm-Chart OKE Deployment
iss
296 Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps in OCI DevOps
Set Up the kubeconfig File and Create a Kubernetes
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Namespace
To access a cluster using kubectl, you must set up a Kubernetes configuration file commonly
known as a kubeconfig file for the cluster. The kubeconfig file provides the necessary
details to access the cluster.
se
en
Having set up the kubeconfig file, you can start using kubectl to access the cluster by
lic
creating a sample deployment in OKE cluster.
bl e
Tasks
ra
sfe
1. In the Console, open the navigation menu and click Developer Services. Under
an
Containers and Artifacts, click Kubernetes Clusters (OKE).
-tr
. non
2. Choose root compartment from List Scope on the left menu.
3.
ide a
In the table listing Clusters, click the cluster <EventID>-OCI-ELS-DEVOPS-OKE to access
Gu as
using kubectl. The Cluster details page shows information on the cluster.
is ) h
5. Click Cloud Shell Access, copy the command to access the kubeconfig for your cluster via
th
to gma
6.
@
Launch Cloud Shell and run the copied command. On successful execution, it will return a
iss
For example,
e
ocid1.cluster.oc1.iad.xxxxxaaaziwdigokvlwhuaeslgxi6tdk473xqgodcb
(ri
Note: This is just a representation of the command. Do not use this command to connect
RI
This will return the IP addresses of three worker nodes setup within this OKE cluster.
Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps 297
8. Create namespace in your Kubernetes cluster to manage your helm resources.
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Where,
ns-helm-<userID> is a unique namespace for your group of resources within a cluster.
Replace <userID> with your user ID. For example, user22.
se
For example,
en
$ kubectl create ns ns-helm-user22
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
riss
e .d
an
(ri
E
AN
RI
iss
Dr
298 Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps in OCI DevOps
Automate Sample Web Application Deployment to OKE
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
se
output artifacts and Helm Charts and applies them to the target environment, which in this
en
case is an OKE cluster.
lic
Tasks
bl e
ra
1. Switch to the OCI Console, navigate to the Build Pipeline IAD-DOP-LAB18-1-BPL-01.
sfe
Click the Start Manual Run button. The Start Manual Run page opens.
an
-tr
a. OCI assigns your build a Build run name.
. non
b. The parameters you specified in the parameters tab are displayed here.
ide a
Gu as
Note: You can change the parameters for the build run if required.
is ) h
2. You will reach the Build run tab. Observe that all the build stages are listed here. Build
th
stages will execute sequentially. You can observe the logs for each stage in the right
to gma
window.
@
Note: If the build pipeline fails due to timeout issues, Re-run the build pipeline.
iss
r
.d
Once the Trigger Helm-Chart OKE Deployment stage completes, click Deployments from
e
You will observe deployment listed here that got automatically kicked-off and is either in
AN
Further, when you click the deployment name, you will reach the Deployments tab. Under
Dr
the Deployments tab, you can see the logs and additional details for the Deployment
pipeline run.
Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps 299
3. Once the deployment is successful, let’s now confirm the helm chart deployment and try
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
to access the application using the External (or Public) endpoint i.e., the oke-helm-
<userID>-node-service Load Balancer IP.
Note: If the Deployment Pipeline fails due to timeout issues, Re-run the build pipeline.
se
en
$ helm list -n ns-helm-<userID>
lic
Note: Replace <userID> with your user ID. For example, user22.
bl e
ra
For example,
sfe
$ helm list -n ns-helm-user22
an
You will observe the helm chart deployed with revision set to 1 in the ns-helm-
-tr
<userID> namespace using the chart available in the OCIR Helm Repository iad-
. non
dop-lab18-1-ocir-2/helm-repo-user22/node-service.
b. ide a
Gu as
To access the application deployed on the OKE cluster, you can retrieve the service
is ) h
Note: Replace <userID> with your user ID. For example, user22.
th
to gma
For example,
$ kubectl get svc -n ns-helm-user22
@
c. Launch a Web Browser and enter the IP address into the browser’s address bar to
e
access the application. Once the request is processed, you’ll see a web page with the
an
following content:
(ri
E
AN
RI
iss
Dr
300 Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps in OCI DevOps
View the Artifacts Generated as Part of the Automated
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Build
You will view the artifacts generated as part of the build pipeline execution.
Tasks
se
en
1. To view Container Image Repository Artifact:
lic
a. In the Console, click Developer Services. Under Containers & Artifacts, click
bl e
Container Registry.
ra
sfe
b. Select your compartment and then select the container repository iad-dop-lab18-
1-ocir-1/node-service-<userID>
an
-tr
c. You will notice a new image present in your repository with a random string like
. non
xxmjbpxx as tag. This random string is the BUILDRUN_HASH of the build that
pushed the image in OCIR.
ide a
Gu as
2. To view the Helm Artifacts:
is ) h
e om
a. In the Console, click Developer Services. Under Containers & Artifacts, click
us il.c
Container Registry.
th
to gma
b. Select your compartment and then select the container repository iad-dop-lab18-
1-ocir-1/helm-repo-<userID>/node-service
@
iss
c. You will notice an artifact present in your repository with a random string like 0.1.0-
r
amjbpm4 as tag. This random string is the BUILDRUN_HASH of the build that pushed
e .d
Every time you run a build pipeline, these artifacts will be generated and stored in the
E
container registry with a unique string to identify them. In case of a build failure, these
AN
Congratulations! You have successfully deployed a Web Application to an OKE cluster using
iss
Further, you also verified the artifacts generated as part of the successful build pipeline run
Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps 301
Purge Instructions
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
1. Open Cloud Shell, run the following command to list all Helm deployments in your
namespace:
se
$ helm list -n ns-helm-<userID>
en
2. Choose the deployment you wish to remove and run the following command:
lic
$ helm delete <helm_release_name> -n ns-helm-<userID>
bl e
Where,
ra
sfe
• <helm_release_name> is your Helm release name.
an
• ns-helm-<userID> is your Kubernetes namespace name. Replace <userID> with
-tr
you user ID.
. non
The output says release "oke-helm-<userID>" uninstalled.
1. Open Cloud Shell, run the following command for the namespace you wish to delete:
e om
2. Open the Deployment Pipelines page from the left menu under DevOps project
E
3. On the Pipeline tab, for the box representing OCI-WebApp-Deployment (deploy OKE:
iss
Rolling) stage, click the three dots on the right to open the Actions menu. Select Delete
Dr
302 Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps in OCI DevOps
Purge Instructions for Deployment Pipeline
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
1. Switch to the Deployment Pipelines page under your DevOps project IAD-DOP-LAB18-
1-DP-01-<userID>.
2. For the deployment pipeline IAD-DOP-LAB18-1-DPL-01, click the three dots on the right
to open the Actions menu. Select Delete and click Delete to confirm.
se
en
Purge Instructions for Build Stages
lic
1. Open your DevOps project IAD-DOP-LAB18-1-DP-01-<userID> by navigating to Projects
bl e
under DevOps in Developer Services.
ra
sfe
2. Open the Build Pipelines page from the left menu under DevOps project resources and
an
select your build pipeline IAD-DOP-LAB18-1-BPL-01.
-tr
. non
3. On the Build Pipeline tab, for each box representing a build stage, click the three dots on
the right to open the Actions menu. Select Delete and then click Delete to confirm.
ide a
Gu as
The stages will have to be deleted in reverse order, starting from Trigger Deployment,
is ) h
1. Switch to the Build Pipelines page under your DevOps project IAD-DOP-LAB18-1-DP-01-
<userID>.
@
2. For the build pipeline IAD-DOP-LAB18-1-BPL-01, click the three dots on the right to open
iss
the Actions menu. Select Delete and then click Yes, delete to confirm.
r
e .d
2. Click Artifacts from the left menu to navigate to the Artifacts page.
iss
3. For the artifact you wish to delete, click the three dots on the right to open the Actions
Dr
Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps 303
Purge Instructions for Environment in DevOps project
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
2. Click Environments from the left menu to navigate to the Environments page.
3. For the environment you wish to delete, click the three dots on the right to open the
se
Actions menu. Select Delete Environment and click Yes, delete to confirm.
en
lic
Purge Instructions for Mirrored Code Repository in DevOps Project
bl e
1. Open the DevOps project IAD-DOP-LAB10-1-DP-01-<userID>.
ra
sfe
2. Click Code Repositories on the left menu of your project page and locate your mirrored
an
repository IAD-DOP-LAB18-1-MR-01.
-tr
3. Click the three dots on the right to open the Actions menu. Select Delete.
. non
4. Type the repository name in the provided field to confirm the Delete action and then click
Delete. ide a
Gu as
is ) h
2. Click External Connections on the left menu of your project page and locate your
connection IAD-DOP-LAB18-1-EC-01.
@
iss
3. Click the three dots on the right to open the Actions menu. Select Delete.
r
.d
1.
AN
In the Console, open the navigation menu and click Developer Services. Under DevOps,
click Projects.
RI
iss
2. For your DevOps project IAD-DOP-LAB18-1-DP-01-<userID>, click the three dots on the
Dr
3. Type the project name in the provided field to confirm the Delete action and then click
Delete.
304 Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps in OCI DevOps
Purge Instructions for OCIR Repositories
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
1. In the Console, open the navigation menu and click Developer Services. Under
Containers & Artifacts, click Container Registry.
se
1) <region-key>-dop-lab18-1-ocir-1/node-service-<userID>
en
lic
2) <region-key>-dop-lab18-1-ocir-2/helm-repo-<userID>/node-service
bl e
3. Click the Actions menu on the repository summary page and select Delete Repository.
ra
sfe
4. Click Delete to confirm that you want to delete the repository.
an
Purge Instructions for Auth Token
-tr
. non
1. In the top-right corner of the OCI Console, open the Profile menu, and then click User
Settings.
ide a
Gu as
2. On the left menu, click Auth Tokens.
is ) h
e om
3. For the auth token you want to delete “<region-key>-DOP-LAB18-1-AT-01”, click the three
dots on the right to open the Actions menu. Select Delete and then click Delete to
us il.c
th
confirm.
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps 305
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
306
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
Deploy a sample web application to OKE cluster using Helm Chart deployment in OCI DevOps in OCI DevOps
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
. non Operations
Lab 19-1 Practice
-tr
an
sfe
ra
Estimated Time: 30 minutes bl e
lic
en
se
Perform Cryptographic
Using OCI Vault Service to
DevSecOps: Generate a Key
Get Started
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Overview
Oracle Cloud Infrastructure (OCI) Vault is a key management service that stores and manages
master encryption keys and secrets for protected resource access. Specifically, depending on
se
the protection mode, vault keys are either saved on the server or stored in highly accessible
en
and robust hardware security modules (HSM).
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
d. Perform encryption
(ri
E
e. Perform decryption
AN
RI
For more information on OCI Vault, see the OCI Vault Documentation.
Dr
Assumptions
• You are signed in to your Oracle Cloud Infrastructure account using your credentials.
• A pre-created Vault OCI-ELS-DEVOPS-VAULT-1 is available in the root
compartment.
308 Generate a key using OCI Vault service to perform cryptographic operations
Prepare for Master Encryption Key
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
To create a master encryption key, you’ll need the compartment OCID and management
endpoint URL.
Note: While you’re performing these tasks, copy and save the compartment OCID, Vault OCID,
and management endpoint URL in a notepad. You’ll be using these OCIDs and URL later in this
se
lab.
en
lic
Tasks
bl e
ra
1. Sign in to your Oracle Cloud Infrastructure (OCI) account.
sfe
2. Open Cloud Shell.
an
-tr
3. Verify that you are in the home directory.
. non
$ cd ~
'<assigned_compartment>\|ocid1.compartment'
e om
assigned to you.
th
to gma
For example,
@
Sample Output:
e
"id": "ocid1.compartment.oc1..axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
an
"name": "<assigned_compartment>"
(ri
E
a. You will need a Vault OCID to get the management endpoint URL. To get the Vault
RI
OCID:
iss
Dr
1) Open the navigation menu, click Identity & Security, and then click Vault.
3) From the list of vaults, click the vault OCI-ELS-DEVOPS-VAULT-1. The Console
displays the vault configuration details.
Generate a key using OCI Vault service to perform cryptographic operations 309
4) Copy the Vault OCID and paste it to a notepad for later use. OCID is the unique
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
se
Note: Replace <vault_ocid> with the vault OCID you copied earlier.
en
For example,
lic
$ oci kms management vault get --vault-id
bl e
ocid1.vault.oc1.iad.bzqtr2wtaacuu.xxxxxxxxxxxvqpv6ftcjfgazjls7mv
ra
hcoadxxxxxxxxxust5aq | grep 'display-name\|management-endpoint'
sfe
Sample Output: Copy the URL highlighted below in bold.
an
"display-name": "OCI-ELS-DEVOPS-VAULT-1",
-tr
"management-endpoint": "https://bxxxxxu-management.kms.us-
. non
ashburn-1.oraclecloud.com",
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
.d
e
an
(ri
E
AN
RI
iss
Dr
310 Generate a key using OCI Vault service to perform cryptographic operations
Create Master Encryption Key
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
You will create a master encryption key needed to carry out cryptographic operations
using an existing Vault at the root level compartment.
Tasks
se
1. Create a master encryption key.
en
$ oci kms management key create --compartment-id
lic
<compartment_ocid> --display-name <key_name> --key-shape
bl e
<key_encryption_information> --endpoint
<management_endpoint_url>
ra
sfe
Note: Replace <compartment_ocid> and <management_endpoint_url> with the
an
compartment OCID and the management endpoint URL you saved earlier.
-tr
Replace <key_name> with IAD-DP-LAB19-1-MSK-01 and
. non
<key_encryption_information> with '{"algorithm":"AES","length":"16"}'
ide a
Gu as
For example,
is ) h
management.kms.us-ashburn-1.oraclecloud.com
to gma
Sample Output:
@
riss
e .d
an
(ri
E
AN
RI
iss
Dr
Generate a key using OCI Vault service to perform cryptographic operations 311
Prepare for Encryption and Decryption
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
To perform encryption and decryption, you will need the master encryption key OCID and OCI
Vault cryptographic endpoint URL to perform encryption.
Note: Copy and save master encryption key OCID and OCI Vault cryptographic endpoint URL
in a notepad. You’ll be using these OCIDs and URL later in this lab.
se
en
Tasks
lic
bl e
1. Get the master encryption key OCID and copy in notepad.
ra
$ oci kms management key list --compartment-id
sfe
<compartment_ocid> --endpoint <management_endpoint_url> | grep
'display-name\|ocid1.key'
an
-tr
Note: Replace <compartment_ocid> and <management_endpoint_url> with the
. non
compartment OCID and the management endpoint URL you saved earlier.
For example,
ide a
Gu as
$ oci kms management key list --compartment-id
is ) h
ocid1.compartment.oc1..axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --
endpoint https://bxxxxxu-management.kms.us-ashburn-
e om
Sample Output:
to gma
"display-name": "IAD-DP-LAB19-1-MSK-01",
"id": "ocid1.key.oc1.iad.bxxuu.xxxxxxxxxxxxxxxxxxwxxxxxxxxxxxxx"
@
iss
'display-name\|crypto-endpoint'
e
an
Note: Replace <vault_ocid> with the Vault OCID you saved earlier.
(ri
E
For example,
AN
ocid1.vault.oc1.iad.bzqtr2wtaacuu.abuwcljrylhau3fxxxxxxxxxxazjls
7mvhcoadxxxxxxxxxxt5aq | grep 'display-name\|crypto-endpoint'
iss
Dr
Sample Output:
"crypto-endpoint": "https://bxxxxxuu-crypto.kms.us-ashburn-
1.oraclecloud.com",
"display-name": "OCI-ELS-DEVOPS-VAULT-1",
312 Generate a key using OCI Vault service to perform cryptographic operations
Perform Encryption
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
You will execute CLI commands to perform encryption. The CLI command invokes oci kms
crypto encrypt to perform data encryption which will require three inputs: the plain text to
be encrypted, the OCID of the master encryption key you created in the last step, and the OCI
Vault cryptographic endpoint.
se
en
Tasks
lic
1. Perform encryption.
bl e
ra
$ oci kms crypto encrypt --key-id <master_encryption_key_OCID> --
sfe
endpoint <crypto_endpoint> --plaintext "base64_plain_text"
an
Note: Replace <master_encryption_key_OCID> and <crypto_endpoint> with the
-tr
master key OCID and crypto endpoint you saved in the previous task. Additionally, add a
. non
base64 plain text for encryption.
ocid1.key.oc1.iad.bxxuu.xxxxxxxxxxxxxxxxxxwxxxxxxxxxxxxx --
e om
endpoint https://bxxxxxuu-crypto.kms.us-ashburn-
1.oraclecloud.com --plaintext "$(echo HELLO_WORLD | base64)"
us il.c
th
Sample Output:
to gma
@
riss
e .d
an
2. Copy ciphertext from your output as highlighted using arrow in the sample output and
(ri
Generate a key using OCI Vault service to perform cryptographic operations 313
Perform Decryption
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
You will execute CLI commands to perform decryption. The CLI command invokes oci kms
crypto decrypt to perform data encryption which will require three inputs: the encrypted
plain text that needs to be decrypted, the OCID of the master encryption key you created in
the previous step, and the OCI Vault cryptographic endpoint.
se
en
Tasks
lic
1. Perform decryption.
bl e
$ oci kms crypto decrypt --key-id <master_encryption_key_OCID> -
ra
-endpoint <crypto_endpoint> --ciphertext <ciphertext>
sfe
Note: Replace the <master_encryption_key_OCID>, <crypto_endpoint>, and the
an
<ciphertext> with the master key OCID, crypto endpoint, and the ciphertext
-tr
respectively you saved earlier.
. non
For example,
ide a
Gu as
oci kms crypto decrypt --key-id
is ) h
ocid1.key.oc1.iad.bxxuu.xxxxxxxxxxxxxxxxxxwxxxxxxxxxxxxx --
e om
endpoint https://bxxxxxuu-crypto.kms.us-ashburn-
1.oraclecloud.com --ciphertext
us il.c
Qc1hSOIo3b4+ADKTNBoqrxxxxxxx/LsWz95x9aN4AAAAA
th
to gma
Sample Output:
@
iss
r
e.d
an
(ri
E
2. Copy the plaintext code from your output as highlighted using arrow in the sample
AN
Note: Replace the <plaintext_code> with the plaintext code you saved in the previous
step. For example,
314 Generate a key using OCI Vault service to perform cryptographic operations
Rotate the Master Encryption Key
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
You will rotate the master encryption key to restrict the data/sensitive information encrypted
using one master encryption key version. It's a good practice as it reduces the risk of
compromising a master encryption key.
Tasks
se
en
1. Sign in to your Oracle Cloud Infrastructure (OCI) account.
lic
bl e
2. Navigate to Identity & Security and select Vault.
ra
3.
sfe
Select root compartment from List scope on the left menu.
an
4. From the list of vaults, click the vault OCI-ELS-DEVOPS-VAULT-1.
-tr
. non
5. Select your <assigned compartment> from List scope on the left menu. You will see
the key that you have created.
ide a
Gu as
6. Click your Master Encryption Key - IAD-DP-LAB19-1-MSK-01.
is ) h
8. On the Key details page, under the Key Information tab. Notice Key version OCID. When
th
to gma
you rotate a key, the Vault service generates a new key version. But the master encryption
key’s unique, Oracle Cloud ID (OCID), remains the same across rotations.
@
9.
iss
On the Key details page, click Rotate Key. Leave the Import External key version
unchecked. Confirm that you want to rotate the key by clicking the Rotate Key. Close the
r
.d
pop-up after success. You will notice Vault service generated a new key version.
e
an
10. Perform the process of decryption again as earlier on the same encrypted text.
(ri
E
11. Observation on Output: The key version ID in the output is now different from what is
AN
data/objects encrypted with an earlier version of this key will continue to use the older key
iss
version.
Dr
Congratulations! You learned to generate a master encryption key and use it to conduct
cryptographic operations.
Generate a key using OCI Vault service to perform cryptographic operations 315
Purge Instructions
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
2. Open the navigation menu, click Identity & Security, and then click Vault.
se
en
3. Select root compartment from List scope on the left menu.
lic
4. From the list of vaults, click the vault OCI-ELS-DEVOPS-VAULT-1.
bl e
ra
5. Select your <assigned compartment> from List scope on the left menu.
sfe
an
6. Click Master Encryption Keys and locate the key with the name IAD-DP-LAB19-1-MSK-
01.
-tr
. non
7. Click the three dots on the right to open the Actions menu. Select Delete Key.
• ide a
Confirm that you want to delete the key by clicking the box and then typing the key
Gu as
name.
is ) h
e om
• Schedule when you want the Vault service to delete the key. You can set a date after 8
us il.c
days.
th
to gma
316 Generate a key using OCI Vault service to perform cryptographic operations
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
. non
-tr
Lab 20-1 Practices
an
sfe
ra
bl e
Estimated Time: 30 minutes
lic
en
se
Image for Vulnerabilities
DevSecOps: Scan Container
Get Started
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Overview
se
delivery (CI/CD) tool kicking off a build process. Then, the CI/CD tool pushes the newly built
en
container image to an Oracle Cloud Infrastructure Registry (OCIR) repository and when ready,
lic
the new image is deployed to a production Oracle Cloud Infrastructure (OCI) Container Engine
for Kubernetes (OKE) cluster.
bl e
ra
While this CI/CD process sounds reasonable, it is missing few key steps. Critical to shipping
sfe
compliant and secure containers, system administrators need to ensure that container images
an
have the following characteristics:
-tr
• Are free of known critical vulnerabilities that can cause an accidental system failure or
. non
result in malicious activity
• Have not been modified since they were published to maintain their integrity
ide a
Gu as
• Are only deployed to a Kubernetes cluster and come from a trusted source
is ) h
OCI container image scanning, signing, and verification address all these secure container
e om
deployment needs.
us il.c
th
to gma
@
riss
e .d
an
(ri
E
AN
RI
iss
Dr
se
d.
en
Sign in to OCIR from the Cloud Shell
lic
e. Pull the Docker image from Docker hub
bl e
f. Tag the Docker image
ra
sfe
g. Push the tagged Docker image to OCIR
an
-tr
h. Verify if the image has been pushed
. non
i. View scan results
ide a
Gu as
j. View vulnerability reports
is ) h
For more information on OCI container image security, see the OCI Scanning Images for
Vulnerabilities Documentation.
@
iss
Prerequisites
r
.d
• You are signed in to your Oracle Cloud Infrastructure account using your credentials.
e
an
Create an auth token to use when authenticating with your <assigned user account> with
Oracle Cloud Infrastructure Registry (OCIR).
Tasks
se
1. In the top-right corner of the OCI Console, open the Profile menu, and then click User
en
settings.
lic
bl e
2. On the Auth Tokens page, click Generate Token.
ra
sfe
Note: Each user can only have two auth tokens at a time. Delete an older auth token if you
need to create a new one.
an
-tr
3. Enter IAD-DOP-LAB20-1-AT-01, as a friendly description for the auth token.
. non
Click Generate Token. The new auth token is displayed. Here’s a sample of how an auth
ide a
token looks like R5kwpS-xxxxx((]51r]]. It’ll be different in your case.
Gu as
is ) h
Note: Copy the auth token to a notepad because you won't see the auth token again in
e om
the Console. You’ll need this auth token later in the labs.
us il.c
th
For example,
to gma
R5kwpS-xxxxx((]51r]]
@
4. Click Close.
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr
Create a repository in your assigned compartment and give it a name that's unique across all
compartments in the entire tenancy. Having created the new repository, you can push an
image to the repository using the Docker CLI.
Tasks
se
en
1. Sign in to the Oracle Cloud Infrastructure (OCI) Console.
lic
bl e
2. Open the navigation menu and click Developer Services. Under Containers & Artifacts,
ra
click Container Registry.
sfe
3. Select your <assigned compartment> from List scope on the left menu.
an
-tr
4. Click Create repository.
. non
5. Select your <assigned compartment> to create a new repository.
ide a
Gu as
6. Enter a name for the new repository: <region-key>-dop-lab20-1-ocir-
is ) h
1/oci_demo_imagescan_<userID>
e om
Where,
us il.c
th
• <region-key> is the key for the Oracle Cloud Infrastructure Registry region you're
to gma
using. For example, iad is the region key for US EAST (Ashburn) region. See
the Availability by Region topic in the Oracle Cloud Infrastructure documentation.
@
iss
Note: Only use lower case characters, numbers, and special characters.
(ri
E
When you create a new repository, image scanning is disabled by default. You can use
the Console to enable image scanning for a repository by creating a new image scanner. If
image scanning has already been enabled, you can use the Console to disable it.
Tasks
se
en
1. Once the repository is created, select the newly created repository <region-key>-dop-
lic
lab20-1-ocir-1/oci_demo_imagescan_<userID> from the list of repositories by
bl e
clicking on the dropdown menu labelled Repositories and images.
ra
sfe
2. Click on Add scanner button.
an
Note: The Add scanner option will take some time to load.
-tr
. non
3. In the Add scanner to repository pane, enter the following values:
• Target name: IAD-DOP-LAB20-1-ISC-01-<userID>
ide a
Gu as
For example, IAD-DOP-LAB20-1-ISC-01-user22
is ) h
• Name: Scan_Config_<userID>
e
an
5. Click Create.
RI
Note: Now that a scanner has been created and configured, images saved to the
iss
repository will be scanned for vulnerabilities. If the repository already contains images, the
Dr
four most recently saved images will have been immediately scanned for vulnerabilities
when the scanner was created.
Once you have generated the auth token and created a new repository, sign in to OCIR from
Docker CLI in cloud shell.
Tasks
se
1. Open Cloud Shell.
en
lic
Note: The OCI CLI running in Cloud Shell will execute commands against the region
bl e
selected in the Console's region selection menu when Cloud Shell was started.
ra
2.
sfe
In the Cloud Shell, log in to OCIR by entering:
$ docker login <region-key>.ocir.io
an
-tr
Where,
. non
<region-key> is the key for the Oracle Cloud Infrastructure Registry region you're
using. For example, iad is the region key for US EAST (Ashburn) region. See the
ide a
Availability by Region topic in the Oracle Cloud Infrastructure documentation.
Gu as
is ) h
For example,
e om
<tenancy-namespace>/<username>.
@
iss
of the tenancy in which to create repositories (as shown on the Tenancy Information
E
page). And for username use the username as shown in the profile menu. For example,
AN
Note that for some older tenancies, the namespace string might be the same as the
iss
If your tenancy is federated with Oracle Identity Cloud Service, use the format <tenancy-
namespace>/oracleidentitycloudservice/<username>.
Enter the auth token IAD-DOP-LAB20-1-AT-01 (random string) you copied earlier as
the password.
For example,
R5kwpS-xxxxx((]51r]]
Note: When you enter or paste the password, you’ll not see masked characters. Press
Enter on your keyboard to continue and you should see the “Login Succeeded”
message on the screen.
se
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
riss
e.d
an
(ri
E
AN
RI
iss
Dr
Begin by copying a prebuilt maven image tagged latest (maven:latest) from Docker
Hub. This image will later be tagged and pushed to your OCIR repository.
Tasks
se
1. Issue the following Docker pull command:
en
$ docker pull maven:latest
lic
bl e
For example,
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
$ docker images
to gma
Note: You should see the maven:latest image in the list of images.
@
riss
e .d
an
(ri
E
AN
RI
iss
Dr
A tag identifies the Oracle Cloud Infrastructure Registry region, tenancy, and repository to
which you want to push the image.
Tasks
se
1. In the Cloud Shell, run the following command to attach a tag to the image that you're
en
going to push to OCIR repository:
lic
$ docker tag maven:latest <region-key>.ocir.io/<tenancy-
bl e
namespace>/<repo-name>:<tag>
ra
Where,
sfe
• <region-key> is the key for the Oracle Cloud Infrastructure Registry region you're
an
using. For example, iad is the region key for US EAST (Ashburn) region. See
-tr
the Availability by Region topic in the Oracle Cloud Infrastructure documentation.
. non
• ocir.io is the Oracle Cloud Infrastructure Registry name.
• ide a
<tenancy-namespace> is the auto-generated Object Storage namespace string of
Gu as
the tenancy (as shown on the Tenancy Information page) to which you want to push
is ) h
• <repo-name> is the name of the target repository to which you want to push the
us il.c
• <tag> is an image tag you want to give the image in Oracle Cloud Infrastructure
Registry (for example, 1.0).
@
iss
For example,
r
.d
lab20-1-ocir-1/oci_demo_imagescan_user22:1.0
an
(ri
Note: Although two tagged images will be shown (latest and 1.0), both are based on
RI
After assigning a tag to the image, push it to Oracle Cloud Infrastructure Registry repository.
Tasks
1. In the Cloud Shell, run the following command to push the tagged Docker image to OCIR
se
repository:
en
$ docker push <region-key>.ocir.io/<tenancy-namespace>/<repo-
lic
name>:<tag>
bl e
Where,
ra
sfe
• <region-key> is the key for the Oracle Cloud Infrastructure Registry region you're
using. For example, iad is the region key for US EAST (Ashburn) region. See the
an
Availability by Region topic in the Oracle Cloud Infrastructure documentation.
-tr
. non
• ocir.io is the Oracle Cloud Infrastructure Registry name.
• <tenancy-namespace> is the auto-generated Object Storage namespace string of
ide a
the tenancy (as shown on the Tenancy Information page) to which you want to push
Gu as
the image. For example, oracletenancy.
is ) h
• <repo-name> is the name of the target repository to which you want to push the
e om
• <tag> is an image tag you want to give the image in Oracle Cloud Infrastructure
to gma
For example,
r
1/oci_demo_imagescan_user22:1.0
e
an
You will see the different layers of the image are pushed in turn.
(ri
E
AN
RI
iss
Dr
Tasks
1. Go back to the OCIR Service page and select your <assigned compartment> from List
se
scope on the left menu.
en
lic
2. Click on the dropdown menu labelled Repositories and images
bl e
3. You’ll see the private repository iad-dop-lab20-1-ocir-
ra
sfe
1/oci_demo_imagescan_<userID> that you created.
an
4. Expand by clicking on the (+) icon preceding the name of the repository that contains the
-tr
image you just pushed. You’ll see:
. non
• An image with the tag 1.0.
•
ide a
A summary page that shows you the details about the repository, including who
Gu as
created it and when, its size, and whether it's a public or a private repository.
is ) h
On the Summary page, you’ll see the image size, when it was pushed and by which user,
th
to gma
The results of a container image scan include the specific vulnerabilities in the CVE database
that were detected in the image.
Tasks
se
1. While still on the OCIR Service page, and having selected the image 1.0, click the Scan
en
Results tab. This will show you the following info:
lic
• Risk level
bl e
• Issues found
ra
sfe
• Scan started
an
• Scan completed
-tr
Note: It will take some time before the scan results show up.
. non
2. Click the three dots on the right to open the Actions menu. Select View Details to see the
ide a
issues in more detail with risk level associated with each of them and their descriptions.
Gu as
is ) h
e om
us il.c
th
to gma
@
riss
e .d
an
(ri
E
AN
RI
iss
Dr
The results of a container image scan include the specific vulnerabilities in the CVE database
that were detected in the image.
In this section, you will explore Vulnerability Reports, accessing information about specific
vulnerabilities that were detected in one or more targets.
se
en
Tasks
lic
bl e
1. Open the navigation menu and click Identity & Security. Under Scanning,
ra
click Vulnerability Reports.
sfe
Note: If you are presented with a general information screen labeled Vulnerability
an
Scanning Service, locate, and click Skip.
-tr
. non
2. From the left menu, under Scanning, and select Vulnerability Reports.
3. ide a
Select your <assigned compartment> from List scope on the left menu.
Gu as
is ) h
4. From the left menu, under Filters, select the Risk level, All.
e om
6. To view a description of a specific vulnerability, click Show in the CVE description column.
7. To view details about a specific vulnerability, click a report's CVE ID. This will result in your
@
iss
viewing a vulnerabilities report. A vulnerabilities report includes details about the affected
resources and CVEs.
r
e.d
8. On the Vulnerabilities report page, in the left menu, under Resources, select Container
an
Images to view a list of Container images that are affected by the selected vulnerability.
(ri
E
AN
RI
iss
Dr
The results of a container image scan include the specific vulnerabilities in the CVE database
that were detected in the image.
Tasks
se
1. Open the navigation menu and click Identity & Security. Under Scanning, click Scanning
en
Reports.
lic
bl e
2. Select your <assigned compartment> from List scope on the left menu.
ra
sfe
3. Click the Container images tab.
an
4. Locate the Risk level filter drop-down menu. Select All.
-tr
. non
5. Locate the Scan start date and Scan end date filter drop-down menus.
ide a
By default, only the most recent scan reports are displayed. To view older reports, choose
Gu as
specific start and end dates.
is ) h
Alternatively, click Scan start date and choose to view reports for either the Past 7
e om
6. Locate the Reset button. Click Reset at any time to set the risk level and date ranges back
to the default values.
@
7.
iss
(Optional) Click the table columns to sort the container image scans by:
r
• Issues found
e .d
• Risk level
an
• Scan completed
(ri
E
8. To view a Container image report, click the name of the Container image.
AN
9. The following details are shown for each issue that was detected in this image:
iss
• Issue ID
Dr
• Risk level
• Issue description
• Last detected
11. Navigate back to the Container image report details page using breadcrumb link. Click
the View detail button in the Cause and remediation column to get more information on
se
how to address this vulnerability.
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr
Use the Console to export all vulnerabilities reports as a file in comma-separated value (CSV)
format for offline analysis.
Tasks
se
1. Open the navigation menu and click Identity & Security. Under Scanning,
en
click Vulnerability Reports.
lic
bl e
2. Select your <assigned compartment> from List scope on the left menu.
ra
sfe
3. Click Export CSV and save the .csv file on your local machine.
an
Example output:
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
Congratulations! You have successfully uploaded an image to the OCIR repository, run the
th
1. In the Console, open the navigation menu and click Developer Services. Under
Containers & Artifacts, click Container Registry.
se
2. Click the name of the name of the repository to be deleted from the dropdown menu.
en
lic
3. Click the Delete Repository button on the repository summary page.
bl e
4. Click Delete to confirm.
ra
sfe
Purge Instructions for Auth Token
an
-tr
1. In the top-right corner of the Console, click the user Profile menu, and select User
. non
settings.
1. In the Cloud Shell, run the following command to list all the images to get the image IDs,
image name and other details:
@
iss
$ docker images
r
.d
Deleting a Target
(ri
E
Deleting a target doesn’t delete the cloud resources (compute instances, container image for
AN
2. Open the navigation menu and click Identity & Security. Under Scanning, click Targets.
Dr
6. Click Delete.
7. When prompted for confirmation, click Delete.
se
To delete a scan recipe, it must not be associated with any scan targets.
en
lic
1. Log in to the Oracle Cloud Infrastructure (OCI) console.
bl e
2. Open the navigation menu and click Identity & Security. Under Scanning, click Scan
ra
Recipes.
sfe
3. Select the Compartment that contains your recipe.
an
-tr
4. Click the Container image tab for the type of recipe that you want to delete.
. non
5. Click the name of the recipe.
6. Click Delete.
ide a
Gu as
7. When prompted for confirmation, click Delete.
is ) h
e om
2. Open the navigation menu and click Identity & Security. Under Scanning, click Scanning
r
Reports.
e .d
6. Click Delete.
RI
336
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
Dr
iss
RI
AN
E
(ri
an
e .d
riss
@
to gma
us il.c
e om
th
is ) h
Gu as
ide a
. non
-tr
Lab 21-1 Practices
an
sfe
ra
bl e
Estimated Time: 40 minutes
lic
en
se
Container Image in OCIR
DevSecOps: Sign and Verify
Get Started
Unauthorized reproduction or distribution prohibited. Copyright© 2024, Oracle University and/or its affiliates.
Overview
For compliance and security reasons, system administrators seek to deploy a software into a
production system only when they are sure that:
se
• The software comes from a trusted source
en
• The software has not been modified since it was published, thus its integrity is
lic
maintained
bl e
To fulfil these requirements, you can sign images stored in the Oracle Cloud Infrastructure
ra
(OCI) Registry, also known as Container Registry. Signed images provide a way to verify both
sfe
the source and the integrity of an image.
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e.d
an
(ri
For more information on OCI container image security, see the OCI Signing Images for
Security Documentation.
se
Prerequisites
en
• You are signed in to your Oracle Cloud Infrastructure account using your credentials.
lic
• A pre-created Vault OCI-ELS-DEVOPS-VAULT-1 is available in the root
bl e
compartment.
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
r iss
e .d
an
(ri
E
AN
RI
iss
Dr
To push or pull Docker images from OCIR, you must have an OCI username and an auth
token. You only see the auth token string when you create it, so be sure to copy the auth token
to a secure location immediately. Each OCI user can have up to two auth tokens at a time. So,
if you do lose or forget the auth token, you can always create a second auth token.
se
Tasks
en
lic
1. In the top-right corner of the Console, click the user Profile menu, and select User
bl e
settings.
ra
sfe
2. On the Auth Tokens page, click Generate Token.
an
Note: Each user can only have two auth tokens at a time. Delete an older auth token if you
-tr
need to create a new one.
. non
3. Enter IAD-DOP-LAB21-1-AT-01, as a friendly description for the auth token.
ide a
Gu as
4. Click Generate Token. The new auth token is displayed. Here’s a sample of how an auth
is ) h
Note: Copy the auth token to a notepad because you won't see the auth token again in
us il.c
th
the Console. You’ll need this auth token later in this lab.
to gma
For example,
@
R5xxxx-ZS519((]51r]]
iss
5. Click Close.
r
e.d
an
(ri
E
AN
RI
iss
Dr
se
You will now create an empty repository with a unique name across the tenancy.
en
Tasks
lic
bl e
1. Check if you can access OCIR:
ra
sfe
a. In the Console, open the navigation menu and click Developer Services, under
an
Containers & Artifacts, click Container Registry.
-tr
b. Select your <assigned compartment> from List scope on the left menu.
. non
c. Review the repositories that already exist.
ide a
Gu as
2. Click Create Repository.
is ) h
e om
1/oci_demo_imagesign_<userID>
@
Where <region-key> is the key for the Oracle Cloud Infrastructure Registry region
iss
you're using. For example, iad is the region key for US EAST (Ashburn) region. See
r
5. Select the Public option to enable unauthenticated access to the new repository.
E
AN
Once you have generated an auth token and created a new repository, sign in to OCIR from
Docker CLI in Cloud Shell and pull a sample image from docker hub.
Tasks
se
1. Open Cloud Shell.
en
lic
Note: The OCI CLI running in Cloud Shell will execute commands against the region
bl e
selected in the Console's region selection menu when Cloud Shell was started.
ra
2.
sfe
In Cloud Shell window, log in to OCIR by entering:
$ docker login <region-key>.ocir.io
an
-tr
Where <region-key> is the key for the Oracle Cloud Infrastructure Registry region
. non
you're using. For example, iad is the region key for US EAST (Ashburn) region. See
the Availability by Region topic in the Oracle Cloud Infrastructure documentation.
ide a
Gu as
For example,
is ) h
For example,
iss
R5kwpS-xxxxx((]51r]]
r
.d
Note: When you enter or paste the password, you’ll not see masked characters. Press
e
an
4. As a sample image, you will pull the official mysql:latest image from the Docker Hub:
E
AN
5. Run the following command to check whether the image is pulled successfully:
Dr
$ docker images
Once you have pulled the sample image from the docker hub, sign in to OCIR using Docker CLI
in Cloud Shell to tag the new image and push it to OCIR.
Tasks
se
1. In the Cloud Shell, run the following command to attach a tag to the image that you're
en
going to push to OCIR repository:
lic
$ docker tag mysql:latest <region-key>.ocir.io/<tenancy-
bl e
namespace>/<repo-name>:<tag>
ra
Where,
sfe
• <region-key> is the key for the Oracle Cloud Infrastructure Registry region you're
an
using. For example, IAD is the region key for US EAST (Ashburn) region. See the
-tr
Availability by Region topic in the Oracle Cloud Infrastructure Registry
. non
documentation.
• ide a
ocir.io is the Oracle Cloud Infrastructure Registry name.
Gu as
• <tenancy-namespace> is the auto-generated Object Storage namespace string of
is ) h
the tenancy (as shown on the Tenancy Information page) to which you want to push
e om
the image.
us il.c
• <repo-name> is the name of the target repository to which you want to push the
th
to gma
• <tag> is an image tag you want to give the image in Oracle Cloud Infrastructure
iss
Registry.
r
.d
• For example,
e
lab21-1-ocir-1/oci_demo_imagesign_user22:1.0
(ri
E
2. Run the following command to validate whether the newly tagged image is listed:
iss
$ docker images
Dr
For example,
$ docker push iad.ocir.io/oracletenancy/iad-dop-lab21-1-ocir-
1/oci_demo_imagesign_user22:1.0
se
en
The different layers of the image are pushed in turn.
lic
4. In the Console, open the navigation menu and click Developer Services. Under
bl e
Containers & Artifacts, click Container Registry.
ra
sfe
5. Go to the OCIR repository iad-dop-lab21-1-ocir-
1/oci_demo_imagesign_<userID> and check if a new image is available under the
an
repository with the tag 1.0.
-tr
. non
6. Also check the Signatures tab on the right. It should say, “No items found”.
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
After you have built and pushed the image to the Container Registry, you can also sign the
image using a master encryption key obtained from OCI Vault, thus creating an image
signature. Note that the image signature is associated with an image's OCID, making it specific
to a particular push of the image.
se
Tasks
en
lic
1. In the Console, open the navigation menu and click Developer Services, under
bl e
Containers & Artifacts, click Container Registry.
ra
sfe
2. Select the image you just pushed in your repository with tag 1.0 to see detailed
an
information. Copy the OCID of the image shown on the Summary page and paste it on a
notepad. For example,
-tr
ocid1.containerimage.oc1.iad.0.ocuocictrng6.aaaaaaaav27t3aua3vjszar
. non
lz3hw44a5prlm2id63dfd6aej2s72exxxxxxx
3. ide a
Now, navigate to Identity & Security and click Vault. Select the vault OCI-ELS-DEVOPS-
Gu as
VAULT-1 under root compartment.
is ) h
e om
4. Click Create Key to create a master encryption key in the vault OCI-ELS-DEVOPS-VAULT-
us il.c
1.
th
to gma
• Name: iad-dop-lab21-1-vk-01
e .d
• Leave other fields to default values and click Create Key. It will take about a minute to
RI
see the key that you just created listed under the Master Encryption Keys on the left
side. The key will go from the Creating state to the Enabled state.
OCI Vault.
se
mo2kvzw4djnsz33n6f6d2xxxxxxx
en
lic
Click Versions under Resources from the left menu and copy the OCID of the key
bl e
version. For example,
ocid1.keyversion.oc1.iad.bzqtr2wtaacuu.asqkmm3k2daaa.abuwcljsvvf
ra
ffqdzi275zx2hdv2cs6phvmk4nzrgexnz37wagd4ehxxxxxxx
sfe
an
Copy and paste both the OCIDs on a notepad for future reference.
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr
Once you obtain the OCIDs for both the master encryption key and the key version in the Vault
service, you can sign the image you pushed to Container Registry by creating an image
signature using the Container Registry CLI.
Tasks
se
en
1. Open Cloud Shell.
lic
bl e
2. In Cloud Shell window, log in to OCIR by entering:
ra
$ docker login iad.ocir.io
sfe
3. When prompted, enter your username in the format <tenancy-
an
namespace>/<username>. For example, oracletenancy/user22. Enter the auth
-tr
token IAD-DOP-LAB21-1-AT-1 (random string) you copied earlier as the password.
. non
4. Run the following command to create an image signature:
ide a
$ oci artifacts container image-signature sign-upload --
Gu as
compartment-id <compartment-ocid> --kms-key-id <key-ocid> --kms-
is ) h
<signature-description>
us il.c
th
Where,
to gma
repository belongs. Open the navigation menu, click Identify & Security. Under
iss
Identity, click Compartments. Search your assigned compartment and copy the
r
OCID.
e .d
• <key-ocid>: The OCID of the master encryption key to use to sign the image.
an
• <key-version-ocid>: The OCID of the key version to use to sign the image.
E
AN
SHA_224_RSA_PKCS_PSS
Dr
SHA_256_RSA_PKCS_PSS
SHA_384_RSA_PKCS_PSS
SHA_512_RSA_PKCS_PSS
SHA_224_RSA_PKCS1_V1_5
SHA_256_RSA_PKCS1_V1_5
SHA_384_RSA_PKCS1_V1_5
ECDSA_SHA_256
ECDSA_SHA_384
ECDSA_SHA_512
The algorithm to choose depends on the type of the master encryption key. For RSA
keys, supported signature schemes include PKCS #1 and RSASSA-PSS, along with
se
different hashing algorithms. For example, --signing-algorithm
en
SHA_224_RSA_PKCS_PSS
lic
• <image-ocid>: The OCID of the image to sign. Check your notepad for the OCID.
bl e
• <signature-description>: Optional field for text to describe the image. This
ra
description is included as part of the signature and is shown in the Console. For
sfe
example, "Demo Image signing for integrity test."
an
• For example,
-tr
$ oci artifacts container image-signature sign-upload --
. non
compartment-id
ocid1.compartment.oc1..aaaaaaaaztwigv63hbyoxyovjo46xorslvqplozs7
j7gioik6hh2cbxxxxxx --kms-key-id
ide a
Gu as
ocid1.key.oc1.iad.bzqtr2wtaacuu.abuwcljs6e5r63s54irrvi3f4zl5rnkj
mo2kvzw4djnsz33n6f6d2xxxxxxx --kms-key-version-id
is ) h
ocid1.keyversion.oc1.iad.bzqtr2wtaacuu.asqkmm3k2daaa.abuwcljsvvf
e om
ffqdzi275zx2hdv2cs6phvmk4nzrgexnz37wagd4ehxxxxxxx --signing-
us il.c
ocid1.containerimage.oc1.iad.0.ocuocictrng6.aaaaaaaav27t3aua3vjs
to gma
• You will see the details of the uploaded image signature as the output.
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr
An image signature associates an image with the master key (obtained from the Vault service)
that was used to sign the image. An image can have multiple signatures, each created using a
different master encryption key.
Having signed an image in Container Registry and created an image signature, you can:
se
en
• View details of the signature
lic
• Verify the signature with the Vault service to confirm that the master encryption key
bl e
used to sign the image is still valid and available
• Delete the signature to indicate that the image is no longer to be considered as
ra
sfe
trusted
an
Now that the image signature is uploaded, you’ll view the signed image.
-tr
Tasks
. non
1. In the Console, open the navigation menu and click Developer Services. Under
ide a
Gu as
Containers & Artifacts, click Container Registry.
is ) h
2. Select your <assigned compartment> from List scope on the left menu.
e om
us il.c
You will notice the image with tag 1.0 labelled as a Signed.
iss
4. Click the name of a signed image and click the Signatures tab to view the details of the
r
.d
• Description: A description of the signature that was specified when the image was
(ri
signed
E
• Verification response: The result of the last attempt to verify the image signature
AN
• Date: Date and time when the image was signed, and the image signature created
iss
5. Beside the signature, click the three dots on the right to open the Actions menu.
Dr
a. Select View key details to view the master encryption key, key version, and signing
algorithm for a signature. Click Close.
Vault service.
Note:
The Vault service checks if:
• The image source had access to a valid private key when they pushed the image
se
• The image has not been modified since it was pushed
en
lic
If both conditions are met, the signature is shown with a Verified status. Users or
systems pulling the image from the registry can be confident that the source of the
bl e
image is trusted, and that the image's integrity has not been compromised.
ra
sfe
an
Congratulations! You have successfully signed an image by creating an image signature using
-tr
a master encryption key and key version from the OCI Vault service.
. non
Further, you also checked whether image source is trusted and whether image’s integrity is
maintained by verifying the signature.
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e .d
an
(ri
E
AN
RI
iss
Dr
se
2. Click the name of a signed image and click the Signatures tab to view the list of
en
signatures for the image.
lic
bl e
3. Besides the signature, click the three dots on the right to open the Actions menu. Select
Delete signature to delete a signature.
ra
sfe
Once the signature is deleted, it is no longer visible in the Signatures tab. If the image has
an
no other signatures, the label Signed no longer appears beside the image name in the list
-tr
of images in the repository.
. non
Purge Instructions for the Image Pushed in the Container Repository
ide a
Gu as
1. Select the image pushed in the repository on the Container Registry page.
is ) h
e om
2. Click the Actions drop-down list beside the image name and select Delete image.
us il.c
th
2. Click the Actions drop-down list beside the repository name and select Delete
e
an
Repository.
(ri
1. In the top-right corner of the Console, open the Profile menu, and then click User
Settings.
Dr
3. For the auth token you want to delete, click the three dots on the right to open the Actions
menu. Select Delete and then click Delete to confirm.
1. Run the following command to list all the images to get the image ID, image name, and
other details:
$ docker images
se
$ docker rmi <your-image-id>
en
lic
bl e
ra
sfe
an
-tr
. non
ide a
Gu as
is ) h
e om
us il.c
th
to gma
@
iss
r
e.d
an
(ri
E
AN
RI
iss
Dr