From 9195a50385a9370e287bb715f78fbeeef52cdb90 Mon Sep 17 00:00:00 2001 From: dipeshrath <111430850+dipeshrath@users.noreply.github.com> Date: Tue, 13 Aug 2024 20:47:27 +0530 Subject: [PATCH] update readme --- fn-ci-cd-deployment-pipeline/README.md | 43 ++++++++++++++++--- fn-ci-cd-deployment-pipeline/oci-fn-build.yml | 24 ++++------- .../oci-fn-deploy.yml | 22 +++++----- 3 files changed, 57 insertions(+), 32 deletions(-) diff --git a/fn-ci-cd-deployment-pipeline/README.md b/fn-ci-cd-deployment-pipeline/README.md index 61bbd29..854a077 100644 --- a/fn-ci-cd-deployment-pipeline/README.md +++ b/fn-ci-cd-deployment-pipeline/README.md @@ -1,15 +1,48 @@ # CI/CD pipeline for OCI function deployment using Fn CLI ## Introduction -This repository contains custom scripts developed and published in public blogs by Oracle Cloud Engineering Services for OCI Infrastructure Automation. +This is a reference yaml as an action workflow to build and deploy the OCI function using FN CLI. -It will help to update or enhance the code also easy to clone and reuse by community. +### Pipeline Definition +- [oci-fn-build.yml](./oci-fn-build.yml) +- [oci-fn-deploy.yml](./oci-fn-deploy.yml) -### Prerequisites -Custom code from published blogs only must be contributed here. +### Build and Deploy Pipeline + +Deploy a function using the Fn Project CLI, the function is built as a Docker image and pushed to a specified Docker registry. + +- Provide value for non senstive information as an input and update during runtime. + + ``` + OCI_FN_NAME + OCI_FN_APP + OCI_FN_COMPARTMENT + OCI_FN_IMAGE + ```` + +- Create environment variables for other non senstive information. + + ``` + OCI_TENANCY_NAME + OCI_FN_REGISTRY + OCI_FN_API_URL + OCI_FN_USER_NAME + OCI_FN_OCIR + ``` + +- Create secrets for all senstive information to use in the pipeline. + ``` + OCI_CLI_USER + OCI_CLI_FINGERPRINT + OCI_CLI_TENANCY + OCI_CLI_REGION + OCI_CLI_KEY_CONTENT + ``` + +OCI Functions pulls the function's Docker image from the specified Docker registry, runs it as a Docker container, and executes the function. ## License -Copyright (c) 2022 Oracle and/or its affiliates. +Copyright (c) 2024 Oracle and/or its affiliates. Licensed under the Universal Permissive License (UPL), Version 1.0. diff --git a/fn-ci-cd-deployment-pipeline/oci-fn-build.yml b/fn-ci-cd-deployment-pipeline/oci-fn-build.yml index 78ea740..18c8be4 100644 --- a/fn-ci-cd-deployment-pipeline/oci-fn-build.yml +++ b/fn-ci-cd-deployment-pipeline/oci-fn-build.yml @@ -6,25 +6,17 @@ on: # but only for the main branch workflow_dispatch: inputs: - OCI_FN_APP: - description: Function app name - default: dip-str OCI_FN_COMPARTMENT: description: Function compartment - 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 + 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 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 @@ -37,7 +29,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=${{secrets.OCI_CLI_REGION}}" >> ~/.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 @@ -60,16 +52,18 @@ jobs: curl -LSs https://raw.githubusercontent.com/fnproject/cli/master/install | sh - name: 'Docker login' - run: docker login -u ${{ vars.OCI_FN_USER }} -p ${{ secrets.OCI_CLI_AUTH_TOKEN }} ${{ vars.OCI_FN_OCIR }} + 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 dipeshrathod60 --provider oracle - fn use context dipeshrathod60 + 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/oci-fn-deploy.yml b/fn-ci-cd-deployment-pipeline/oci-fn-deploy.yml index a6d3e31..d793350 100644 --- a/fn-ci-cd-deployment-pipeline/oci-fn-deploy.yml +++ b/fn-ci-cd-deployment-pipeline/oci-fn-deploy.yml @@ -6,26 +6,24 @@ on: # 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: dip-str + default: demo-function-app OCI_FN_COMPARTMENT: description: Function compartment - default: ocid1.compartment.oc1..aaaaaaaanovmfmmnonjjyxeq4jyghszj2eczlrkgj5svnxrtrvqvfhmbubeq - OCI_FN_NAME: - description: Function Name - default: oci-logs-stream + default: ocid1.compartment.oc1.... OCI_FN_IMAGE: description: OCIR Image to use for Function - default: bom.ocir.io/bmpmwyacrlcj/repodip1/oci-logs-stream:0.0.19 - OCI_TENANCY_NAME: - description: Tenancy Name - default: dipeshrathod60 + 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 @@ -63,8 +61,8 @@ jobs: - name: 'Setting up Fn context' run: | - fn create context ${{ inputs.OCI_TENANCY_NAME }} --provider oracle - fn use context ${{ inputs.OCI_TENANCY_NAME }} + 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 }}