|
1 | 1 | # End-to-End-DevOps-GCP-PHP-MySQL
|
| 2 | + |
| 3 | +<img src=cover.png> |
| 4 | + |
| 5 | +This repository contains the source code and configuration files for the "Task Management System" application, a PHP application with MySQL backend. The application is deployed on Google Kubernetes Engine (GKE) and uses Cloud SQL for the database. The repository is organized into multiple directories, each serving a specific purpose in the deployment and management of the application. |
| 6 | + |
| 7 | +## Directory Structure |
| 8 | + |
| 9 | +- `task-management-system/`: Contains the source code of the Task Management System. |
| 10 | +- `k8s/`: Kubernetes manifest files for each service. |
| 11 | + - `frontend-service/` |
| 12 | + - `logout-service/` |
| 13 | + - `users-service/` |
| 14 | + - `ingress/`: Manifests for ingress to navigate between service containers. |
| 15 | + - `mysql-job/`: A Kubernetes job to connect to Cloud SQL and create tables for the application. |
| 16 | +- `terraform/`: Terraform configuration files for infrastructure as code. |
| 17 | +- `.github/`: GitHub workflows for Continuous Integration (CI) and Continuous Deployment (CD). |
| 18 | + |
| 19 | +## Scripts |
| 20 | + |
| 21 | +- `build.sh`: Script to build and deploy the entire project. |
| 22 | +- `destroy.sh`: Script to tear down the entire environment. |
| 23 | +- `github_secrets.sh`: Script to automate storing secrets in GitHub Secrets. |
| 24 | + |
| 25 | +## Getting Started |
| 26 | + |
| 27 | +### Prerequisites |
| 28 | + |
| 29 | +- Google Cloud SDK |
| 30 | +- Docker |
| 31 | +- kubectl |
| 32 | +- Terraform |
| 33 | +- jq |
| 34 | +- GitHub CLI (gh) |
| 35 | + |
| 36 | +### Installation |
| 37 | + |
| 38 | +1. **Clone the Repository** |
| 39 | + |
| 40 | + ```sh |
| 41 | + git clone https://github.com/johnbedeir/End-to-End-DevOps-GCP-Python-MySQL.git |
| 42 | + cd End-to-End-DevOps-GCP-Python-MySQL |
| 43 | + ``` |
| 44 | + |
| 45 | +2. **Set Up Google Cloud Credentials** |
| 46 | + |
| 47 | + Make sure you have the appropriate IAM roles and the service account key file. |
| 48 | + |
| 49 | +3. **Build and Deploy the Project** |
| 50 | + |
| 51 | + ```sh |
| 52 | + ./build.sh |
| 53 | + ``` |
| 54 | + |
| 55 | +### Build Script (`build.sh`) |
| 56 | + |
| 57 | +The `build.sh` script performs the following steps: |
| 58 | + |
| 59 | +1. Authenticate with Google Cloud. |
| 60 | +2. Delete existing service account keys. |
| 61 | +3. Create new service account keys. |
| 62 | +4. Initialize and apply Terraform configurations to set up GKE and other resources. |
| 63 | +5. Update kubeconfig to interact with the GKE cluster. |
| 64 | +6. Build Docker images for each service and push them to Google Container Registry (GCR). |
| 65 | +7. Create necessary Kubernetes secrets. |
| 66 | +8. Deploy Kubernetes manifests to the cluster. |
| 67 | +9. Output the URLs for various services (application, Prometheus, Grafana, etc.). |
| 68 | + |
| 69 | +### Destroy Script (`destroy.sh`) |
| 70 | + |
| 71 | +The `destroy.sh` script performs the following steps: |
| 72 | + |
| 73 | +1. Authenticate with Google Cloud. |
| 74 | +2. Delete Docker images from Google Container Registry. |
| 75 | +3. Destroy all GCP resources using Terraform. |
| 76 | + |
| 77 | +### GitHub Secrets Script (`github_secrets.sh`) |
| 78 | + |
| 79 | +The `github_secrets.sh` script performs the following steps: |
| 80 | + |
| 81 | +1. Delete existing service account keys. |
| 82 | +2. Create new service account keys. |
| 83 | +3. Base64 encode the credentials and environment variables. |
| 84 | +4. Store the encoded values as GitHub Secrets. |
| 85 | + |
| 86 | +## GitHub Workflows |
| 87 | + |
| 88 | +- **CI Workflows**: Defined for each service in `.github/workflows/service-ci-workflow`. |
| 89 | +- **CD Workflows**: Defined for each service in `.github/workflows/service-cd-workflow`. |
| 90 | + |
| 91 | +## Infrastructure as Code |
| 92 | + |
| 93 | +The `terraform/` directory contains Terraform configuration files to provision the following resources: |
| 94 | + |
| 95 | +- Google Kubernetes Engine (GKE) cluster. |
| 96 | +- Google Cloud SQL instance. |
| 97 | +- Networking and IAM configurations. |
| 98 | + |
| 99 | +## Deployment |
| 100 | + |
| 101 | +The deployment process is managed using Kubernetes and involves the following steps: |
| 102 | + |
| 103 | +1. Deploy the frontend, logout, and users services. |
| 104 | +2. Set up ingress for routing traffic between service containers. |
| 105 | +3. Run the `mysql-job` to set up the database schema in Cloud SQL. |
| 106 | + |
| 107 | +## Monitoring and Logging |
| 108 | + |
| 109 | +- Prometheus and Grafana are deployed for monitoring. |
| 110 | +- ArgoCD are used for Continuous Deployment. |
| 111 | + |
| 112 | +## Secrets Management |
| 113 | + |
| 114 | +Secrets are managed using Kubernetes secrets and GitHub Secrets. The `github_secrets.sh` script automates the process of storing secrets in GitHub. |
| 115 | + |
| 116 | +## Cleanup |
| 117 | + |
| 118 | +To clean up all resources, run the `destroy.sh` script: |
| 119 | + |
| 120 | +```sh |
| 121 | +./destroy.sh |
| 122 | +``` |
0 commit comments