Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added sample code #4

Merged
merged 6 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions fn-ci-cd-deployment-pipeline/.github/workflows/oci-fn-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: 'oci-fn-build'
permissions:
contents: read
on:
# Trigger the workflow on push or pull request,
# but only for the main branch
workflow_dispatch:
inputs:
OCI_FN_COMPARTMENT:
description: Function compartment
default: ocid1.compartment.oc1....

jobs:
# This workflow contains a single job called "build"
Build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4

# Runs a set of commands using the runners shell
- name: 'Write Config & Key Files'
run: |
mkdir ~/.oci
echo "[DEFAULT]" >> ~/.oci/config
echo "user=${{secrets.OCI_CLI_USER}}" >> ~/.oci/config
echo "fingerprint=${{secrets.OCI_CLI_FINGERPRINT}}" >> ~/.oci/config
echo "tenancy=${{secrets.OCI_CLI_TENANCY}}" >> ~/.oci/config
echo "region=${{vars.OCI_CLI_REGION}}" >> ~/.oci/config
echo "${{secrets.OCI_CLI_KEY_CONTENT}}" >> ~/.oci/key.pem
echo "key_file=~/.oci/key.pem" >> ~/.oci/config

- name: 'Install OCI CLI'
run: |
curl -L -O https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh
chmod +x install.sh
./install.sh --accept-all-defaults
export PATH=$PATH:/home/runner/bin
exec -l $SHELL

- name: 'Fix Config File Permissions'
run: |
export PATH=$PATH:/home/runner/bin
oci setup repair-file-permissions --file ~/.oci/key.pem
oci setup repair-file-permissions --file ~/.oci/config

- name: 'Install Fn CLI'
run: |
curl -LSs https://raw.githubusercontent.com/fnproject/cli/master/install | sh

- name: 'Docker login'
run: docker login -u ${{ vars.OCI_FN_USER_NAME }} -p ${{ secrets.OCI_CLI_AUTH_TOKEN }} ${{ vars.OCI_FN_OCIR }}

- name: 'Setting up Fn context'
run: |
fn create context ${{ vars.OCI_TENANCY_NAME }} --provider oracle
fn use context ${{ vars.OCI_TENANCY_NAME }}
fn update context registry ${{ vars.OCI_FN_REGISTRY }}
fn update context oracle.compartment-id ${{ inputs.OCI_FN_COMPARTMENT }}
fn update context api-url ${{ vars.OCI_FN_API_URL }}

- name: 'Build Image for OCI Function'
run: fn build --verbose

- name: 'Push image to OCI Registry'
run: fn push --verbose
71 changes: 71 additions & 0 deletions fn-ci-cd-deployment-pipeline/.github/workflows/oci-fn-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: 'oci-fn-deploy'
permissions:
contents: read
on:
# Trigger the workflow on push or pull request,
# but only for the main branch
workflow_dispatch:
inputs:
OCI_FN_NAME:
description: Function Name
default: demo-function
OCI_FN_APP:
description: Function app name
default: demo-function-app
OCI_FN_COMPARTMENT:
description: Function compartment
default: ocid1.compartment.oc1....
OCI_FN_IMAGE:
description: OCIR Image to use for Function
default: bom.ocir.io/<imagepath-oci:0.0.2>

jobs:
# This workflow contains a single job called "build"
Deploy:
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4

# Runs a set of commands using the runners shell
- name: 'Write Config & Key Files'
run: |
mkdir ~/.oci
echo "[DEFAULT]" >> ~/.oci/config
echo "user=${{secrets.OCI_CLI_USER}}" >> ~/.oci/config
echo "fingerprint=${{secrets.OCI_CLI_FINGERPRINT}}" >> ~/.oci/config
echo "tenancy=${{secrets.OCI_CLI_TENANCY}}" >> ~/.oci/config
echo "region=${{secrets.OCI_CLI_REGION}}" >> ~/.oci/config
echo "${{secrets.OCI_CLI_KEY_CONTENT}}" >> ~/.oci/key.pem
echo "key_file=~/.oci/key.pem" >> ~/.oci/config

- name: 'Install OCI CLI'
run: |
curl -L -O https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh
chmod +x install.sh
./install.sh --accept-all-defaults
export PATH=$PATH:/home/runner/bin
exec -l $SHELL

- name: 'Fix Config File Permissions'
run: |
export PATH=$PATH:/home/runner/bin
oci setup repair-file-permissions --file ~/.oci/key.pem
oci setup repair-file-permissions --file ~/.oci/config

- name: 'Install Fn CLI'
run: |
curl -LSs https://raw.githubusercontent.com/fnproject/cli/master/install | sh

- name: 'Setting up Fn context'
run: |
fn create context ${{ vars.OCI_TENANCY_NAME }} --provider oracle
fn use context ${{ vars.OCI_TENANCY_NAME }}
fn update context registry ${{ vars.OCI_FN_REGISTRY }}
fn update context oracle.compartment-id ${{ inputs.OCI_FN_COMPARTMENT }}
fn update context api-url ${{ vars.OCI_FN_API_URL }}
- name: 'Create or Update OCI Function'
run: |
fn update function ${{ inputs.OCI_FN_APP }} ${{ inputs.OCI_FN_NAME }} --image ${{ inputs.OCI_FN_IMAGE }}
21 changes: 21 additions & 0 deletions fn-ci-cd-deployment-pipeline/func.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import io
import json
import logging

from fdk import response


def handler(ctx, data: io.BytesIO = None):
name = "World"
try:
body = json.loads(data.getvalue())
name = body.get("name")
except (Exception, ValueError) as ex:
logging.getLogger().info('error parsing json payload: ' + str(ex))

logging.getLogger().info("Inside Python Hello World function")
return response.Response(
ctx, response_data=json.dumps(
{"message": "Hello {0}".format(name)}),
headers={"Content-Type": "application/json"}
)
8 changes: 8 additions & 0 deletions fn-ci-cd-deployment-pipeline/func.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
schema_version: 20180708
name: hello-world
version: 0.0.1
runtime: python
build_image: fnproject/python:3.9-dev
run_image: fnproject/python:3.9
entrypoint: /python/bin/fdk /function/func.py handler
memory: 256
24 changes: 15 additions & 9 deletions fn-ci-cd-deployment-pipeline/oci-fn-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,25 @@ on:
# Add Trigger for push or pull request, if needed
workflow_dispatch:
inputs:
OCI_FN_APP:
description: Function app name
default: dip-str
OCI_FN_COMPARTMENT:
description: Function compartment
default: ocid1.compartment.oc1....

default: ocid1.compartment.oc1..aaaaaaaanovmfmmnonjjyxeq4jyghszj2eczlrkgj5svnxrtrvqvfhmbubeq
OCI_FN_NAME:
description: Function Name
default: oci-logs-stream
OCI_FN_IMAGE:
description: OCIR Image to use for Function
default: bom.ocir.io/bmpmwyacrlcj/repodip1/oci-logs-stream:0.0.19
jobs:
# This workflow contains a single job called "Build"
Build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
Expand All @@ -28,7 +36,7 @@ jobs:
echo "user=${{secrets.OCI_CLI_USER}}" >> ~/.oci/config
echo "fingerprint=${{secrets.OCI_CLI_FINGERPRINT}}" >> ~/.oci/config
echo "tenancy=${{secrets.OCI_CLI_TENANCY}}" >> ~/.oci/config
echo "region=${{vars.OCI_CLI_REGION}}" >> ~/.oci/config
echo "region=${{secrets.OCI_CLI_REGION}}" >> ~/.oci/config
echo "${{secrets.OCI_CLI_KEY_CONTENT}}" >> ~/.oci/key.pem
echo "key_file=~/.oci/key.pem" >> ~/.oci/config

Expand All @@ -51,18 +59,16 @@ jobs:
curl -LSs https://raw.githubusercontent.com/fnproject/cli/master/install | sh

- name: 'Docker login'
run: docker login -u ${{ vars.OCI_FN_USER_NAME }} -p ${{ secrets.OCI_CLI_AUTH_TOKEN }} ${{ vars.OCI_FN_OCIR }}
run: docker login -u ${{ vars.OCI_FN_USER }} -p ${{ secrets.OCI_CLI_AUTH_TOKEN }} ${{ vars.OCI_FN_OCIR }}

- name: 'Setting up Fn context'
run: |
fn create context ${{ vars.OCI_TENANCY_NAME }} --provider oracle
fn use context ${{ vars.OCI_TENANCY_NAME }}
fn create context dipeshrathod60 --provider oracle
fn use context dipeshrathod60
fn update context registry ${{ vars.OCI_FN_REGISTRY }}
fn update context oracle.compartment-id ${{ inputs.OCI_FN_COMPARTMENT }}
fn update context api-url ${{ vars.OCI_FN_API_URL }}

- name: 'Build Image for OCI Function'
run: fn build --verbose

- name: 'Push image to OCI Registry'
run: fn push --verbose
17 changes: 8 additions & 9 deletions fn-ci-cd-deployment-pipeline/oci-fn-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ on:

workflow_dispatch:
inputs:
OCI_FN_NAME:
description: Function Name
default: demo-function
OCI_FN_APP:
description: Function app name
default: demo-function-app
default: dip-str
OCI_FN_COMPARTMENT:
description: Function compartment
default: ocid1.compartment.oc1....
default: ocid1.compartment.oc1..aaaaaaaanovmfmmnonjjyxeq4jyghszj2eczlrkgj5svnxrtrvqvfhmbubeq
OCI_FN_NAME:
description: Function Name
default: oci-logs-stream
OCI_FN_IMAGE:
description: OCIR Image to use for Function
default: bom.ocir.io/<imagepath-oci:0.0.2>
Expand All @@ -24,12 +24,11 @@ on:
options:
- create
- update

jobs:
# This workflow contains a single job called "Deploy"
Deploy:
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
Expand Down Expand Up @@ -67,8 +66,8 @@ jobs:

- name: 'Setting up Fn context'
run: |
fn create context ${{ vars.OCI_TENANCY_NAME }} --provider oracle
fn use context ${{ vars.OCI_TENANCY_NAME }}
fn create context ${{ inputs.OCI_TENANCY_NAME }} --provider oracle
fn use context ${{ inputs.OCI_TENANCY_NAME }}
fn update context registry ${{ vars.OCI_FN_REGISTRY }}
fn update context oracle.compartment-id ${{ inputs.OCI_FN_COMPARTMENT }}
fn update context api-url ${{ vars.OCI_FN_API_URL }}
Expand Down
1 change: 1 addition & 0 deletions fn-ci-cd-deployment-pipeline/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fdk>=0.1.75