diff --git a/fn-ci-cd-deployment-pipeline/.github/workflows/oci-fn-build.yml b/fn-ci-cd-deployment-pipeline/.github/workflows/oci-fn-build.yml new file mode 100644 index 0000000..18c8be4 --- /dev/null +++ b/fn-ci-cd-deployment-pipeline/.github/workflows/oci-fn-build.yml @@ -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 diff --git a/fn-ci-cd-deployment-pipeline/.github/workflows/oci-fn-deploy.yml b/fn-ci-cd-deployment-pipeline/.github/workflows/oci-fn-deploy.yml new file mode 100644 index 0000000..d793350 --- /dev/null +++ b/fn-ci-cd-deployment-pipeline/.github/workflows/oci-fn-deploy.yml @@ -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/ + +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 }} diff --git a/fn-ci-cd-deployment-pipeline/func.py b/fn-ci-cd-deployment-pipeline/func.py new file mode 100644 index 0000000..5a53a22 --- /dev/null +++ b/fn-ci-cd-deployment-pipeline/func.py @@ -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"} + ) diff --git a/fn-ci-cd-deployment-pipeline/func.yaml b/fn-ci-cd-deployment-pipeline/func.yaml new file mode 100644 index 0000000..427102d --- /dev/null +++ b/fn-ci-cd-deployment-pipeline/func.yaml @@ -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 diff --git a/fn-ci-cd-deployment-pipeline/oci-fn-build.yml b/fn-ci-cd-deployment-pipeline/oci-fn-build.yml index ed44afd..436757a 100644 --- a/fn-ci-cd-deployment-pipeline/oci-fn-build.yml +++ b/fn-ci-cd-deployment-pipeline/oci-fn-build.yml @@ -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 @@ -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 @@ -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 diff --git a/fn-ci-cd-deployment-pipeline/oci-fn-deploy.yml b/fn-ci-cd-deployment-pipeline/oci-fn-deploy.yml index 74b1224..4db5639 100644 --- a/fn-ci-cd-deployment-pipeline/oci-fn-deploy.yml +++ b/fn-ci-cd-deployment-pipeline/oci-fn-deploy.yml @@ -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/ @@ -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 @@ -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 }} diff --git a/fn-ci-cd-deployment-pipeline/requirements.txt b/fn-ci-cd-deployment-pipeline/requirements.txt new file mode 100644 index 0000000..2d4d785 --- /dev/null +++ b/fn-ci-cd-deployment-pipeline/requirements.txt @@ -0,0 +1 @@ +fdk>=0.1.75 \ No newline at end of file