Wednesday, June 30, 2021

Google Cloud Devops

 Summary

This post will demonstrate the usage of Google Cloud's serverless deployment pipeline - Cloud Build.  The use case for this will be a fairly simple Python app that exposes a REST interface via Flask + NLTK for tokenization of text.

Overall Architecture

The diagram below depicts the Cloud Build pipeline.

Python Application Organization



Cloud Build Steps

Cloud Build is orchestrated from a cloudbuild.yaml file.  Example code below with associated diagram.

  1. steps:
  2. #Unit Test
  3. - name: python
  4. entrypoint: /bin/sh
  5. args: ["-c",
  6. "pip install -r requirements.txt &&\
  7. python -c \"import nltk; nltk.download('popular', download_dir='/home/nltk_data')\" &&\
  8. export NLTK_DATA=/home/nltk_data &&\
  9. python -m unittest"]
  10. #Docker Build
  11. - name: 'gcr.io/cloud-builders/docker'
  12. args: ['build', '-t',
  13. 'us-central1-docker.pkg.dev/$PROJECT_ID/$_REPO_NAME/cleaner', '.']
  14. #Docker push to Google Artifact Registry
  15. - name: 'gcr.io/cloud-builders/docker'
  16. args: ['push', 'us-central1-docker.pkg.dev/$PROJECT_ID/$_REPO_NAME/cleaner']
  17. #Deploy to Cloud Run
  18. - name: google/cloud-sdk
  19. args: ['gcloud', 'run', 'deploy', 'cleaner',
  20. '--image=us-central1-docker.pkg.dev/$PROJECT_ID/$_REPO_NAME/cleaner',
  21. '--region', 'us-central1', '--platform', 'managed',
  22. '--allow-unauthenticated']


Screenshots of Results

Cloud Build





Artifact Registry



Cloud Run




Source


Copyright ©1993-2024 Joey E Whelan, All rights reserved.