Skip to content

Instantly share code, notes, and snippets.

@kral2

kral2/fn-cli_autoconfig.sh

Last active Feb 27, 2020
Embed
What would you like to do?
This script auto-configure your OCI Cloud Shell Fn CLI context.
#!/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