Description

Hands-on Challenge Day - CI/CD with Docker on Google Cloud

Introduction

Embracing CI/CD and Docker in Cloud Environments

Continuous Integration/Continuous Deployment (CI/CD) represents a method of software development designed to improve code quality and enable rapid delivery. Incorporating Docker in CI/CD pipelines facilitates consistent environments from development through to production, reducing "it works on my machine" issues.

Why Google Cloud?

Google Cloud Platform (GCP) offers robust services that support scalable and efficient CI/CD pipelines, such as Cloud Build for automating the build, test, and deploy phases, and Google Kubernetes Engine (GKE) for managing containerized applications with ease.

Challenge Scenario

InnovativeApps Ltd., a software development company, has developed a cutting-edge web application aimed at providing unique digital experiences. To stay ahead in the fast-paced tech industry, they need to implement a CI/CD pipeline that ensures quick releases and high-quality updates to their application.

Problem Statement: InnovativeApps Ltd. struggles with slow release cycles and inconsistent environments across development, testing, and production, leading to delays and increased bugs.

Your Mission: Implement a CI/CD pipeline using Docker and Google Cloud services to automate the deployment of InnovativeApps Ltd.'s web application, ensuring fast, consistent, and reliable delivery.

Challenge: Implementing CI/CD for a Web Application on Google Cloud with Docker

Requirements:

  1. Google Cloud Account: Access to a Google Cloud Platform account.
  2. Sample Web Application: A simple Python Flask application.

Steps:

  1. Set Up Google Cloud Build:

  2. Prepare the Application:

    **app.py:**

    from flask import Flask
    app = Flask(__name__)
    
    @app.route('/')
    def home():
        return 'Hello, Google Cloud CI/CD with Docker!'
    
    if __name__ == '__main__':
        app.run(debug=True, host='0.0.0.0', port=8080)
    
    

    Dockerfile:

    FROM python:3.8-slim
    WORKDIR /app
    COPY . /app
    RUN pip install Flask
    EXPOSE 8080
    CMD ["python", "app.py"]
    
    

    cloudbuild.yaml:

    steps:
    - name: 'gcr.io/cloud-builders/docker'
      args: ['build', '-t', 'gcr.io/$PROJECT_ID/my-app:$SHORT_SHA', '.']
    images:
    - 'gcr.io/$PROJECT_ID/my-app:$SHORT_SHA'
    
    
  3. Deploy the Application:

    deployment.yaml:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: my-app
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: my-app
      template:
        metadata:
          labels:
            app: my-app
        spec:
          containers:
          - name: my-app
            image: gcr.io/$PROJECT_ID/my-app:$SHORT_SHA
            ports:
            - containerPort: 8080
    
    
  4. Test the CI/CD Pipeline: