Skip to content

Commit

Permalink
updates readme
Browse files Browse the repository at this point in the history
  • Loading branch information
pprajapa-42 committed Oct 17, 2024
1 parent 324cf6c commit 7c4c384
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 188 deletions.
212 changes: 73 additions & 139 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
# tq_solution

# Pipeline status
[![CI/CI Pipeline](https://github.com/pprajap/tq_solution/actions/workflows/ci-cd.yml/badge.svg?branch=main)](https://github.com/pprajap/tq_solution/actions/workflows/ci-cd.yml)
This project provides a comprehensive solution for setting up and managing a desktop/web application using Docker and Kubernetes on Google Cloud. It includes scripts for building and pushing Docker images, starting the application, and configuring Google Cloud resources.

# Index
- [tq\_solution](#tq_solution)
- [Index](#index)
- [Pipeline Status](#pipeline-status)
- [Build All Docker Images](#build-all-docker-images)
- [Push All Docker Images to Docker Hub](#push-all-docker-images-to-docker-hub)
- [Start Desktop/Web Solution](#start-desktopweb-solution)
- [Setting Up Google Cloud](#setting-up-google-cloud)
- [Set Variables](#set-variables)
- [Install and Authenticate Google Cloud SDK](#install-and-authenticate-google-cloud-sdk)
- [Create GKE Cluster](#create-gke-cluster)
- [Interact with Created GKE Cluster Using kubectl on Your Host Machine](#interact-with-created-gke-cluster-using-kubectl-on-your-host-machine)
- [Generate Kubernetes Manifests to Cluster](#generate-kubernetes-manifests-to-cluster)
- [Verify](#verify)
- [Upgrade/Rolling Restart of the Nodes in the Cluster](#upgraderolling-restart-of-the-nodes-in-the-cluster)

# Pipeline Status
[![CI/CD Pipeline][def]](https://github.com/pprajap/tq_solution/actions/workflows/ci-cd.yml)

# Build All Docker Images
```sh
./build_docker_images.sh
```
# Push All Docker images to docker hub

# Push All Docker Images to Docker Hub
```sh
./push_docker_images.sh
```
Expand All @@ -21,152 +40,67 @@ OR
./start_web_solution.sh
```

# Setting Up Google Cloud

# Generate kubernetes manifests out of docker-compose
## Set Variables
```sh
cd k8_manifests
kompose convert -f ../docker-compose-web.yml
```

# Setting up Google Cloud

# Set variables
CLUSTER_NAME="your-cluster-name"
ZONE="your-cluster-zone"
```

# install and authenticate google cloud sdk
## Install and Authenticate Google Cloud SDK
```sh
gcloud init
gcloud auth login
gcloud config set project YOUR_PROJECT_ID
```

# create GKE cluster
gcloud container clusters create <cluster-name> --num-nodes=3 --zone=<ZONE>

# interact with created GKE cluster using kubectl on your host machine
gcloud container clusters get-credentials <cluster-name> --zone=<ZONE>
## Create GKE Cluster
```sh
gcloud container clusters create $CLUSTER_NAME --num-nodes=3 --zone=$ZONE
```

# apply generated k8 manifests to cluster
kubectl apply -f k8_manifests/.
## Interact with Created GKE Cluster Using kubectl on Your Host Machine
```sh
gcloud container clusters get-credentials $CLUSTER_NAME --zone=$ZONE
```

# verify
## Generate Kubernetes Manifests to Cluster
1. Download latest Kompose:
```sh
# Download and install Kompose
curl -L https://github.com/kubernetes/kompose/releases/latest/download/kompose-linux-amd64 -o kompose
chmod +x kompose
sudo mv kompose /usr/local/bin/kompose
```

2. Convert Docker Compose to Kubernetes Manifests:
```sh
kompose convert -f docker-compose-web.yml
```

3. Apply the Manifests:
```sh
kubectl apply -f k8_manifests/.
```

## Verify
```sh
kubectl get services
kubectl get deployments
kubectl get pods
kubectl get nodes
```

## Upgrade/Rolling Restart of the Nodes in the Cluster
1. Get the Current Node Version:
```sh
CURRENT_NODE_VERSION=$(gcloud container clusters describe $CLUSTER_NAME --zone $ZONE --format="get(currentNodeVersion)")
```

2. Upgrade the Nodes to the Same Version to Restart Them:
```sh
gcloud container clusters upgrade $CLUSTER_NAME --zone $ZONE --cluster-version $CURRENT_NODE_VERSION
```

# upgrade/ rolling restart of the nodes in the cluster
# Get the current node version
CURRENT_NODE_VERSION=$(gcloud container clusters describe $CLUSTER_NAME --zone $ZONE --format="get(currentNodeVersion)")

# Upgrade the nodes to the same version to restart them
gcloud container clusters upgrade $CLUSTER_NAME --zone $ZONE --cluster-version $CURRENT_NODE_VERSION



# setup CI/CD

1. Set Up GitHub Secrets
First, you need to set up the necessary secrets in your GitHub repository. Go to your repository settings and add the following secrets:

DOCKER_USERNAME: Your Docker Hub username.
DOCKER_PASSWORD: Your Docker Hub password.
GCP_PROJECT_ID: Your Google Cloud project ID.
GCP_SA_KEY: Your Google Cloud service account key in JSON format.
GKE_CLUSTER_NAME: Your GKE cluster name.
GKE_CLUSTER_ZONE: The zone where your GKE cluster is located.
2. Create GitHub Actions Workflow
Create a GitHub Actions workflow file in your repository. This file will define the CI/CD pipeline.

Create a file named .github/workflows/ci-cd.yml with the following content:

name: CI/CD Pipeline

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push tq-backend image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/tq-backend:latest -f tq_backend/Dockerfile ./tq_backend
docker push ${{ secrets.DOCKER_USERNAME }}/tq-backend:latest

- name: Build and push tq-frontend-desktop image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/tq-frontend-desktop:latest -f tq_frontend/qtdeskDockerfile ./tq_frontend
docker push ${{ secrets.DOCKER_USERNAME }}/tq-frontend-desktop:latest

- name: Build and push tq-frontend-web-light image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/tq-frontend-web-light:latest -f tq_frontend/qtwebDockerfile ./tq_frontend
docker push ${{ secrets.DOCKER_USERNAME }}/tq-frontend-web-light:latest

- name: Build and push tq-frontend-web image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/tq-frontend-web:latest -f tq_frontend/qtwasmDockerfile ./tq_frontend
docker push ${{ secrets.DOCKER_USERNAME }}/tq-frontend-web:latest

deploy:
needs: build
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true

- name: Configure Docker
run: |
gcloud auth configure-docker

- name: Get GKE credentials
run: |
gcloud container clusters get-credentials ${{ secrets.GKE_CLUSTER_NAME }} --zone ${{ secrets.GKE_CLUSTER_ZONE }}

- name: Update Kubernetes deployments
run: |
kubectl set image deployment/tq-backend tq-backend=${{ secrets.DOCKER_USERNAME }}/tq-backend:latest
kubectl set image deployment/tq-frontend-web tq-frontend-web=${{ secrets.DOCKER_USERNAME }}/tq-frontend-web:latest
kubectl set image deployment/tq-frontend-web-light tq-frontend-web-light=${{ secrets.DOCKER_USERNAME }}/tq-frontend-web-light:latest
kubectl set image deployment/tq-frontend-desktop tq-frontend-desktop=${{ secrets.DOCKER_USERNAME }}/tq-frontend-desktop:latest

Explanation
Checkout code: Checks out the code from the repository.
Set up Docker Buildx: Sets up Docker Buildx for building multi-platform images.
Log in to Docker Hub: Logs in to Docker Hub using the provided credentials.
Build and push Docker images: Builds and pushes the Docker images for the backend and frontend services.
Set up Cloud SDK: Sets up the Google Cloud SDK using the provided service account key.
Configure Docker: Configures Docker to use Google Cloud credentials.
Get GKE credentials: Retrieves the credentials for the GKE cluster.
Update Kubernetes deployments: Updates the Kubernetes deployments with the new Docker images.


Summary
Set Up GitHub Secrets: Add the necessary secrets to your GitHub repository.
Create GitHub Actions Workflow: Create a workflow file to define the CI/CD pipeline.
Build and Push Docker Images: Build and push the Docker images to Docker Hub.
Update Kubernetes Deployments: Update the Kubernetes deployments with the new Docker images.
These steps will help you set up a CI/CD pipeline for your project, automating the process of building Docker images, pushing them to Docker Hub, and updating your GKE cluster to reflect the changes.
[def]: https://github.com/pprajap/tq_solution/actions/workflows/ci-cd.yml/badge.svg?branch=main
52 changes: 8 additions & 44 deletions build_docker_images.sh
Original file line number Diff line number Diff line change
@@ -1,49 +1,13 @@
#!/bin/bash

# call ./tq_backend/build_push_backend_docker_image.sh to build and push backend image
echo "Building backend Docker image..."
if [ -d "tq_backend" ]; then
cd tq_backend
./build_backend_docker_image.sh
cd ..
echo "Backend Docker image built."
else
echo "Error: tq_backend directory not found."
exit 1
fi
# call ./tq_backend/build_backend_docker_image.sh to build backend image
./tq_backend/build_backend_docker_image.sh

# call ./tq_frontend/build_push_frontend_desktop_docker_image.sh to build and push frontend desktop image
echo "Building frontend desktop Docker image..."
if [ -d "tq_frontend" ]; then
cd tq_frontend
./build_frontend_desktop_docker_image.sh
cd ..
echo "Frontend desktop Docker image built."
else
echo "Error: tq_frontend directory not found."
exit 1
fi
# call ./tq_frontend/build_frontend_desktop_docker_image.sh to build frontend desktop image
./tq_frontend/build_frontend_desktop_docker_image.sh

# call ./tq_frontend/build_push_frontend_web_light_docker_image.sh to build and push frontend web light image
echo "Building frontend web light Docker image..."
if [ -d "tq_frontend" ]; then
cd tq_frontend
./build_frontend_web_light_docker_image.sh
cd ..
echo "Frontend web light Docker image built."
else
echo "Error: tq_frontend directory not found."
exit 1
fi
# call ./tq_frontend/build_frontend_web_docker_image.sh to build frontend web image
./tq_frontend/build_frontend_web_docker_image.sh

# call ./reverse-proxy/build_push_backend_docker_image.sh to build and push backend image
echo "Building reverse-proxy Docker image..."
if [ -d "reverse-proxy" ]; then
cd reverse-proxy
./build_reverse_proxy_docker_image.sh
cd ..
echo "Reverse proxy Docker image built."
else
echo "Error: reverse-proxy directory not found."
exit 1
fi
# call ./reverse_proxy/build_reverse_proxy_docker_image.sh to build reverse proxy image
./reverse_proxy/build_reverse_proxy_docker_image.sh
5 changes: 2 additions & 3 deletions push_docker_images.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#!/bin/bash

# Exit immediately if a command exits with a non-zero status
set -e

# Treat unset variables as an error
set -u

echo "Building all images..."
# call ./build_docker_images.sh to build all images
./build_docker_images.sh
echo "Images build completed."

# Docker login
docker login
echo "Docker login successful."

# fetch user name from docker login
export DOCKER_USERNAME=$(docker info | grep Username | awk '{print $2}')
Expand Down
2 changes: 1 addition & 1 deletion tq_frontend
Submodule tq_frontend updated 1 files
+3 −0 README.md
2 changes: 1 addition & 1 deletion tq_sdk
Submodule tq_sdk updated 2 files
+0 −0 CONTRIBUTING.md
+0 −7 README.md

0 comments on commit 7c4c384

Please sign in to comment.