Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Automated Google Cloud Functions Workflow with ...

GDG Lahore
December 18, 2021

Automated Google Cloud Functions Workflow with GitHub Actions (By: Adil Shehzad) - DevFest 2021

Talk by Adil Shehzad (https://twitter.com/adilshehzad69) at DevFest Lahore 2021 by GDG Lahore.

Alternative link (with animated GIFs): https://www.canva.com/design/DAEygtd8ID4/ScxjP1gVOKEGcCocEtZ3Pw/view

GDG Lahore

December 18, 2021
Tweet

More Decks by GDG Lahore

Other Decks in Technology

Transcript

  1. TODAY'S AGENDA 02 Why is Code Automations Important? Background of

    Today Talk Basic Concepts Setting up the Google Cloud environment Configuring the Github workflow Creating our Python app Deploying our cloud function Where To Get Started? TOPICS COVERED AUTOMATED GOOGLE CLOUD FUNCTIONS WORKFLOW USING GITHUB ACTIONS
  2. It Reduces the time it takes to make large- scale

    code changes by 80 percent. Increase speed and accuracy while reducing the risk of introducing breaking changes. Improve code quality throughout the organization by reducing the risk of bugs or bad code making it to production. WHY IS CODE AUTOMATIONS IMPORTANT? 03 WHY IS CODE AUTOMATIONS IMPORTANT?
  3. It Reduces the time it takes to make large- scale

    code changes by 80 percent. Increase speed and accuracy while reducing the risk of introducing breaking changes. Improve code quality throughout the organization by reducing the risk of bugs or bad code making it to production. WHY IS CODE AUTOMATIONS IMPORTANT? 03 WHY IS CODE AUTOMATIONS IMPORTANT?
  4. BASIC CONCEPTS 5 What is CI / CD? What are

    GitHub Actions? What are Google Cloud Functions?
  5. WHAT IS CONTINUOUS INTEGRATIONS The developers follow this practice to

    merge their code changes in the master/main repository as often as possible. These changes were validated by automated build and Test Cases.
  6. WHAT ARE CONTINUOUS DELIVERY/DEPLOYMENT Continuous Delivery makes sure that the

    release can be made in Production after Testing. Continuous Deployment is a step ahead of continuous Delivery. With this practice, every change that passes all stages of the production pipeline is released to the customers.
  7. WHAT ARE GITHUB ACTIONS? Github’s automation solution that allows you

    to supply a yaml configuration to automate tasks such as CI/CD operations.
  8. Cloud Functions is a serverless platform for building event-based microservices.

    You write small snippets of code and Google Cloud handles all infrastructure for you. WHAT ARE GOOGLE CLOUD FUNCTIONS?
  9. SETTING UP THE GOOGLE CLOUD ENVIRONMENT 5 Enabling the Cloud

    Build API Creating a service account Creating a service account key
  10. ENABLING THE CLOUD BUILD API To Enable Navigate to APIs

    & Services and then Library search for "Cloud Build API" to enable. Cloud Build is a service that executes our builds on the Google Cloud Platform.
  11. CREATING A SERVICE ACCOUNT Next, we need to create a

    service account. Navigate to the sidebar Type IAM & ADMIN on the left panel navigate to the Service accounts.
  12. CREATING A SERVICE ACCOUNT KEY Lastly we need to create

    a service account key. Visit the created service and open the "keys" tab. Create a new key with type “JSON”. Save the json key because we need to configure this as a Github secret.
  13. .GITHUB/WORKFLOWS /DEPLOYER.YML name: Deployment # on commit push, run job

    on: [push] jobs: run: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Cloud Functions Deploy uses: google-github-actions/[email protected] with: credentials: ${{ secrets.GCP_SA_KEY }} name: python-hello-world-cf description: Test python cloud function # nullable project_id: ${{ secrets.GCP_PROJECT_ID }} region: europe-west1 source_dir: src entry_point: hello_world # runtime to use for the function runtime: python39 max_instances: 1 Add the Key file details to the Github Repo Secrets
  14. CREATING OUR PYTHON APP HELLO WORLD IN PYTHON def hello_world(request):

    """ Args: request (flask.Request): The request object Returns: The response text, or any set of values that can be turned into a Response object using `make_response` """ return "Hello World!"
  15. DEPLOYING OUR CLOUD FUNCTION- STEP 1 Github will run our

    deployment script as soon as we push a new commit to our repository.
  16. We have now deployed our app as a cloud function

    to the Google Cloud Platform. Within GCP head over to the cloud functions (sidebar → Cloud functions) DEPLOYING OUR CLOUD FUNCTION- STEP 2
  17. We deployed an HTTP-based cloud function, this means our app

    is executed when a certain URL is pinged. RUNNING OUR CLOUD FUNCTION