Last active
February 27, 2020 20:28
-
-
Save kral2/6944a0ddb07bbe4c44005ceed8b9b460 to your computer and use it in GitHub Desktop.
This script auto-configure your OCI Cloud Shell Fn CLI context.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Last update : February, 2020 | |
# Author: cetin.ardal@oracle.com | |
# | |
# This script auto-configure your Fn CLI context on OCI Cloud Shell. | |
# 1. On OCI Console, create an OCIR repository named like your tenant | |
# 2. Then just run this one-liner at the Cloud Shell prompt: | |
# | |
# sh <( curl -L http://xxx.xxx/xxxxxx ) | |
# Magic sauce is made of OCI IAM Instance Principal + OCI cli JMESPath integration and a glimpse of jq ;-) | |
# (oci raw-request parsing with JMESPath seems to not follow the standard. Forced here to use jq) | |
COMPARTMENT=$(oci iam availability-domain list --raw-output --query 'data[0]."compartment-id"') | |
REGION_NAME=$(oci iam region-subscription list --raw-output --query 'data[?"is-home-region"]."region-name" | [0]') | |
REGION_KEY=$(oci iam region-subscription list --raw-output --query 'data[?"is-home-region"]."region-key" | [0]' | tr '[:upper:]' '[:lower:]') | |
NAMESPACE=$(oci os ns get --query 'data' --raw-output) | |
CONTEXT=$(oci raw-request --http-method GET --target-uri https://identity.$REGION_NAME.oraclecloud.com/20160918/tenancies/$COMPARTMENT | jq -r '.data.name') | |
REPO=$CONTEXT | |
fn create context $CONTEXT --provider oracle-ip | |
fn use context $CONTEXT | |
fn update context oracle.compartment-id $COMPARTMENT | |
fn update context api-url https://functions.$REGION_NAME.oci.oraclecloud.com | |
fn update context registry $REGION_KEY.ocir.io/$NAMESPACE/$REPO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment