Installing OCI CLI on Mac OS

Command Line Interface (CLI) provides the same core functionality as the console, plus additional commands, like the ability to run scripts which extends the console functionality.

To install CLI, you must have

  • OCI cloud account
  • User in a group with the right permissions
  • A key pair used for signing API requests- public key uploaded at Oracle cloud

To install the CLI on Mac OS with HomeBrew:

brew update && brew install oci-cli

To verify the OCI CLI installation

oci --version

To set up the configuration File- there are two ways to do it;

a) Use the set up config Dialog

oci setup config

this command prompts with the information required to create the configuration file and API keys. After the set up, you should upload the public api key on your the API keys section of your profile on OCI.

b) Manual set up

Log into your Oracle cloud, go to your profile, -> API keys & add an API key

Add an API Key in PEM format or generate an API key pair

Download the private key & save config file details – You will use them to set up the config file.

On your MAC OS, navigate to the .oci folder.

cd ~/.oci

if you don’t have the .oci folder, make the directory

mkdir ~/.oci 

Paste the private key downloaded from OCI on this folder and edit the permissions to ensure that only you can read the private key file:

 chmod go-rwx ~/.oci/<oci_api_key_name.pem  

Create a config file and paste the config file details from OCI.

vi config

The config file content looks similar to this- add yours,

[DEFAULT]
user=ocid1.user.oc1..<unique_ID>
fingerprint=<your_fingerprint>
key_file=~/.oci/oci_api_key.pem
tenancy=ocid1.tenancy.oc1..<unique_ID>
region=uk-london-1

(To exit vi, press escape, :wq!)

All done! Test if the OCI CLI is correctly installed and working;

oci os ns get

You should be able to read, create, update, delete the OCI resources. The output from the above command should be the Tenancy name of your OCI cloud.

{
  "data": "<tenancyname>"
}

To create an OCI object storage bucket using OCI CLI example

oci os bucket create --compartment-id <Compartment OCID> --name TestCLI

Add a file on Object Storage using the pipe command

echo "Hello World" | oci os object put --bucket-name my-bucket --name file.txt --file - 

Delete Objects in a bucket (Use –dry-run at the end if you want to first preview)

oci os object bulk-delete --namespace-name <object_storage_namespace> --bucket-name <bucket_name> 

Other useful cmds;

To upgrade your CLI install on Mac OS using Homebrew:

brew update && brew upgrade oci-cli

To uninstall the CLI on Mac OS using Homebrew:

brew uninstall oci-cli

Creating OCI CLI profile

oci setup config --profile myprofile

To use the profile, specify the name on the –profile section

oci os ns get --profile myprofile

To generate new public and private keys on the .oci folder

openssl rsa -pubout -in ~/.oci/oci_api_key.pem -out ~/.oci/oci_api_key_public.pem

References

Oracle Cloud Documentation

Bash commands you can never live without!

This is more of a generic post. I am posting some of the Bash/Linux/Windows commands i find useful everyday!

Source Control :Git

When you want to push your local project to GitHub, create a repository (Don’t add a Readme file yet) on GitHub.

On your local workstation, fire the bash utility in the root folder of your project on your windows file system.

On the Git Bash, run:

git init
git remote add origin https:// (link to your online repository)
git remote -v (Just to confirm your remote repo)
echo 'node_modules'>>.gitignore (Files you want to ignore to pushing to GitHub)
git add .
git commit -m "First commit"
git push origin master

A times you may have commit issues due to file conflicts:

Open the conflicting file -edit and merge the head accordingly. Then;

git add filename
git commit -m "merged file A and B"git push origin master

Other commands:

Ngrok: (helps you expose your localhost to public internet)

http localhost:<port>  (Windows, where port is your port number)

./ngrok http <port> (Linux, where port is your port number)

In Oracle compute, you might want to run a “screen” command to run the ngrok  on detached mode:

screen-S <name of the new screen> This opens a new Screen.

Deploy ngrok on this screen. When done press Ctrl +A+ D to exit.

To confirm the the screen got created:

screen -ls  (shows you all the screens and their ids named "Detached")

To re-access the screen:

screen -r <screen_ID>

To quit:

screen -X -S <screen_id> quit

What other commands do you use daily… but you keep forgetting?

Happy coding! Keep Innovating!