Hands-on Challenge Day - CI/CD with Docker on Google Cloud
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.
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.
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.
Set Up Google Cloud Build:
Prepare the Application:
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)
FROM python:3.8-slim
WORKDIR /app
COPY . /app
RUN pip install Flask
EXPOSE 8080
CMD ["python", "app.py"]
cloudbuild.yaml
file in the repository to specify the build steps for Cloud Build.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'
Deploy the Application:
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
Test the CI/CD Pipeline: