{OCI Functions} OCIコンピュート・インスタンスでのファンクションQuickStart

https://docs.oracle.com/ja-jp/iaas/Content/Functions/Tasks/functionsquickstartocicomputeinstance.htm
https://qiita.com/letian/items/519abc36c32eb40c461c
https://docs.oracle.com/ja-jp/iaas/Content/Functions/home.htm

 

前提: VCN,コンピュートインスタンス(OL9)作成済み


-- 1. アプリケーション作成


oci fn application list \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 

oci fn application create --generate-full-command-json-input

 

oci fn application create \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 \
--display-name app01 \
--subnet-ids '[
  "ocid1.subnet.oc1.iad.000000000000000000000000000000000000000000000000000000000000"
]' 


oci fn application delete \
--application-id ocid1.fnapp.oc1.iad.000000000000000000000000000000000000000000000000000000000000 \
--force 


-- 2. 動的グループ作成

oci iam dynamic-group list 

oci iam dynamic-group create --generate-full-command-json-input


oci iam dynamic-group create \
--description dg01 \
--matching-rule "ANY {instance.id = 'ocid1.instance.oc1.iad.000000000000000000000000000000000000000000000000000000000000'}" \
--name dg01 

 

oci iam dynamic-group delete \
--dynamic-group-id ocid1.dynamicgroup.oc1..000000000000000000000000000000000000000000000000000000000000 \
--force 


-- 3. 動的グループポリシー作成

oci iam policy list \
--compartment-id ocid1.tenancy.oc1..000000000000000000000000000000000000000000000000000000000000 

oci iam policy create \
--compartment-id ocid1.tenancy.oc1..000000000000000000000000000000000000000000000000000000000000 \
--description policy03 \
--name policy03 \
--statements '[
"Allow dynamic-group dg01 to manage functions-family in compartment cmp01",
"Allow dynamic-group dg01 to use virtual-network-family in compartment cmp01",
"Allow dynamic-group dg01 to manage repos in tenancy",
]' 


oci iam policy delete \
--policy-id ocid1.policy.oc1..000000000000000000000000000000000000000000000000000000000000 \
--force 

 

-- 4. OCIコンピュート・インスタンスの開発環境の設定 [vm01で実施]

ssh -i $HOME/.ssh/id_rsa opc@192.0.2.1

docker version

sudo dnf install -y yum-utils
sudo dnf -y update

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

sudo dnf install -y docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo docker container run hello-world
sudo usermod -aG docker opc

再ログイン

docker container run hello-world

 

-- 5. Fn Project CLIインストール [vm01で実施]

curl -LSs https://raw.githubusercontent.com/fnproject/cli/master/install | sh
fn version

 


-- 6. Fn ProjectのCLIコンテキスト設定 [vm01で実施]
fn list context

fn create context context01 --provider oracle-ip

fn use context context01
fn list context


fn update context oracle.compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000

fn update context api-url https://functions.us-ashburn-1.oci.oraclecloud.com

fn update context registry iad.ocir.io/xxxxxxxxxxxx/repo01

fn update context oracle.image-compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000


-- 7. 認証トークン作成
コンソールで実行


-- 8. レジストリログイン [vm01で実施]

 


docker login -u 'xxxxxxxxxxxx/oracleidentitycloudservice/hoge@example.com' iad.ocir.io

パスワードは認証トーク

 

-- 9. ファンクションの作成、デプロイおよび呼出し [vm01で実施]

fn init --runtime java hello-java

cd hello-java

fn -v deploy --app app01

fn invoke app01 hello-java

echo -n 'John' | fn invoke app01 hello-java


-- 10. レポジトリ削除

oci artifacts container repository list \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 

 

oci artifacts container repository delete \
--repository-id ocid1.containerrepo.oc1.iad.0.xxxxxxxxxxxx.000000000000000000000000000000000000000000000000000000000000 \
--force 

-- 11. ファンクション削除

oci fn function list \
--application-id ocid1.fnapp.oc1.iad.000000000000000000000000000000000000000000000000000000000000 


oci fn function delete \
--function-id ocid1.fnfunc.oc1.iad.000000000000000000000000000000000000000000000000000000000000 \
--force