Skip to content

Commit

Permalink
added readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kundan59 committed Sep 18, 2023
1 parent 5dd7327 commit 311a7a0
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 357 deletions.
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,53 @@
# Car Demo
# Car Demo

## To deploy the GCP infrastructure required, follow the steps in deployment readme:
[readme.md](deployment%2Fgcpresources%2Freadme.md)deployment/gcpresources/readme.md

Admin service use a cloud function result, so deploy the cloud function by following the step:

Deploy the cloud function (repo link provided): https://github.com/SahilBabbar12/googlecloudfunction.git
1. Clone the repository on your local.
2. Clean and install the application.
3. Navigate to the project in the terminal.
4. Deploy the cloud function using the specified Google Cloud command.
```
gcloud functions deploy cloud_function_name --gen2 --runtime=java17 --region=us-east1 --source=. --entry-point=com.knoldus.cloudfunction.PubSubDataHandler --memory=512MB --trigger-topic=Vehicle
```

## deploy services
add required secrets in https://github.com/NashTech-Labs/car-demo/settings/secrets/actions
a) GKE_KEY : the service account json key having these permission:
```
Cloud Datastore Owner
Cloud SQL Admin
Compute Admin
Container Registry Service Agent
Create Service Accounts
Kubernetes Engine Admin
Pub/Sub Admin
Secret Manager Admin
Secret Manager Secret Accessor
Security Reviewer
Service Account Admin
Service Account Key Admin
Service Account User
Storage Admin
Storage Object Admin
View Service Accounts
```
b) GKE_PROJECT: Project name
github workflow for ci cd can be found here:
[car-demo-pipeline.yml](.github%2Fworkflows%2Fcar-demo-pipeline.yml)

keep the projects name in [projects-changes-deploy.txt](projects-changes-deploy.txt) which you want to deploy.

when a commit push to main branch it will start the deployment of the services/project mentioned in
file projects-changes-deploy.txt.
deployments steps for each project are mentioned in [apps-deployment-script.sh](apps-deployment-script.sh)

### NOTE:
common : it consists of common utility, events, commands and models used across multiple projects.
you will find the deployment step of common in [apps-deployment-script.sh](apps-deployment-script.sh)
it will do clean package and push the package on github.
so, Each time you make the changes in common upgrade the version in its pom.xml and also
update same version of common in each projects pom.xml
34 changes: 0 additions & 34 deletions admin-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,40 +86,6 @@ If you don't have the JSON key for your Google Cloud service account, you can ge
- Get all unique brands from reactive firestore repository
- Endpoint: `/v1/data/cars/brands-sse`
- HTTP method: GET

## GCP Infrastructure setup

1. Execute GCP deployment script given in java-competency-demo/cloud/scripts/gcppowershellscript.ps

2. Update secrets on github repository. Following secrets are to be added in the secrets and variables.
Make sure you keep the key same as given in the gcp_pipeline.yml :
GCP_PROJECT_ID : <google_cloud_project_id>
GCP_USERNAME : <git_username>
GCP_PASSWORD : <git_token>
CLOUD_AUTH : <base-64 encoded service account key>
GCP_CLUSTER_NAME : <cluster_name>

3. Run the following kubectl command in the google cloud cli

kubectl create secret docker-registry dockerconfigjson-github-com \
--docker-server=https://ghcr.io \
--docker-username=<GITHUB_USERNAME> \
--docker-password=<GITHUB_TOKEN> \
--namespace=default

This secret is used for authenticating with a Docker registry at ghcr.io (GitHub Container Registry) using a Docker configuration JSON that includes the GitHub username and token (password).

4. Deploy the cloud function (repo link provided): https://github.com/SahilBabbar12/googlecloudfunction.git
1. Clone the repository on your local.
2. Clean and install the application.
3. Navigate to the project in the terminal.
4. Deploy the cloud function using the specified Google Cloud command.


gcloud functions deploy cloud_function_name --gen2 --runtime=java17 --region=us-central1 --source=. --entry-point=com.knoldus.cloudfunction.PubSubDataHandler --memory=512MB --trigger-topic=topic_name

5. Initiate the CI/CD pipeline from the Nashtech-labs-java-competency-demo repository.
6. Verify application endpoints using the Swagger endpoint.

## Dependencies
The main dependencies used in this application are:
Expand Down
36 changes: 0 additions & 36 deletions deployment/axonserver/cli/deployment.yaml

This file was deleted.

29 changes: 0 additions & 29 deletions deployment/axonserver/cli/service.yaml

This file was deleted.

42 changes: 0 additions & 42 deletions deployment/axonserver/readme.md

This file was deleted.

56 changes: 0 additions & 56 deletions deployment/gcpresources/cli/create_tables.py

This file was deleted.

105 changes: 32 additions & 73 deletions deployment/gcpresources/readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## deploy mysql on GCP using gcloud cli

## Deploy gcp resources through terraform

### 1. Authenticate gcloud
```
Expand All @@ -7,81 +8,39 @@ a) export GOOGLE_APPLICATION_CREDENTIALS=key.json
b) gcloud auth activate-service-account --key-file=$GOOGLE_APPLICATION_CREDENTIALS
```

### 2. Create cloud sql instance
```
gcloud sql instances create car-demo-dev-db \
--database-version=MYSQL_8_0 \
--tier=db-f1-micro \
--region=us-east1 \
--project=boreal-gravity-396810 \
--storage-type=SSD \
--storage-size=10 \
--storage-auto-increase \
--authorized-networks=0.0.0.0/0
```
#### To Stop the sql instance
```
gcloud sql instances patch car-demo-dev-db \
--project=boreal-gravity-396810 \
--activation-policy=NEVER
```

#### To start the sql instance
```
gcloud sql instances patch car-demo-dev-db \
--project=boreal-gravity-396810 \
--activation-policy=ALWAYS
```

#### To delete the sql instance
```gcloud sql instances delete car-demo-dev-db --project=boreal-gravity-396810```

### 3. Create mysql user to connect to instance

```
gcloud sql users create java_db_user \
--instance=car-demo-dev-db \
--project=boreal-gravity-396810 \
--password=JavaDBs#password2023
```

### 4. Create Databases
```
gcloud sql databases create order_db \
--instance=car-demo-dev-db \
--project=boreal-gravity-396810
gcloud sql databases create inventory_db \
--instance=car-demo-dev-db \
--project=boreal-gravity-396810
gcloud sql databases create payment_db, \
--instance=car-demo-dev-db \
--project=boreal-gravity-396810
gcloud sql databases create shipment_db \
--instance=car-demo-dev-db \
--project=boreal-gravity-396810
```

### 5. create tables if needed(table creatation is done by code so no need to create manually)
change the host name with yours mysql db instance host(public ip) user and password
install python 3.8 and
pip install mysql-connector-python
```
python create_tables.py --host 35.237.111.227 --user java_db_user --password JavaDBs#password2023 --databases order_db,inventory_db,payment_db,shipment_db
```

follow the link - https://cloud.google.com/sql/docs/mysql/create-instance

## Deploy gcp resources through terraform

install terraform in your local
### 2. install
a) terraform in your local
https://askubuntu.com/questions/983351/how-to-install-terraform-in-ubuntu
b) install gcloud kubectl
https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl#install_kubectl
c) install helm
```snap install helm --classic```
d) keep the service account json key (key.json) inside terraform directory and it should have the permission
```
Cloud Datastore Owner
Cloud SQL Admin
Compute Admin
Container Registry Service Agent
Create Service Accounts
Kubernetes Engine Admin
Pub/Sub Admin
Secret Manager Admin
Secret Manager Secret Accessor
Security Reviewer
Service Account Admin
Service Account Key Admin
Service Account User
Storage Admin
Storage Object Admin
View Service Accounts
```
e) check the [terraform.tfvars](terraform%2Fterraform.tfvars) file for the gcp project and credentials values and path.

### 3. run -

- terraform init
- terraform plan
- terraform apply

To destroy the mysql resources
To destroy the all gcp resources
- terraform destroy

Loading

0 comments on commit 311a7a0

Please sign in to comment.