Skip to content

Latest commit

 

History

History

README.md

Welcome to Spring Petclinic Serverless CI/CD Project!

This is a project for Python development with CDK to build Spring Petlinic Serverles CI/CD process and infrastructure. You will use four CI/CD processes to demo deploy Static web resource, Customer service, Vet service and Visit service separately. You must have meet requirement before to start below.

Deploy Static Resource CI/CD Infrastructure

First of all we must deploy Web Static and some common resources like API Gateway. We manually create a virtualenv on MacOS and Linux in this project root folder:

cd static-service-cicd && python3 -m venv .env

After the init process completes and the virtualenv is created, you can use the following step to activate your virtualenv.

source .env/bin/activate

Once the virtualenv is activated, you can install the required dependencies.

pip install -r requirements.txt

At this point you can now synthesize the CloudFormation template for this code.

cdk synth

After review the CloudFormation template you deploy all the Infracture codes using:

cdk deploy

When the CDK deploy completed you should go to CodeCommit console and if you select the right AWS Region then you can get the spring-petclinic-static-resource repository HTTPS url address like https://git-codecommit.<REGION>.amazonaws.com/v1/repos/spring-petclinic-static-resource

To complete your code submit to the repository, run these command bellow:

cd static-resource && git init
git remote add origin *REPO_URL*
git add .
git commit -m "init commit"
git push --set-upstream origin master

When you push your code to the CodeCommit Repository, the Git tool will ask Username and Password, pelase follow this Guide the get the yours.

After all the codes commit to the repository, you can login the CodePipeline console to check the CI/CD process and the process will automatically start.

Finally, the CI/CD process will deploy the Petclinic static web resource to the Web bucket.

Deploy Customer Service CI/CD Infrastructure

Deploy Customer, Vet and Visit microservices will more complicated than Static project. We will first deploy CI/CD infrastructure with CDK and then build microservice infrastructure and itself in our CodePipline. Pelase reference the detail information in this guid.

Deploy the CI/CD Infra:

cd customer-service-cicd && python3 -m venv .env
source .env/bin/activate
pip install -r requirements.txt
cdk deploy customer-cicd-stack

When CDK deploy completed, you can find your CodeCommit repository HTTPS url for Customer service spring-petclinic-customers-serverless like https://git-codecommit.<REGION>.amazonaws.com/v1/repos/spring-petclinic-customers-serverless.

Submit the Customer service source code to this repository:

cd customer-service-cicd && git init
git remote add origin *REPO_URL*
git add .
git commit -m "init commit"
git push --set-upstream origin master

After all the source code push to the CodeCommit Repository, the CodePipeline will automatically start to build the serverless microservice infra and package and deploy them use another CloudFormation.

So when you have new version commit to the Repository this CI/CD process will automatically run and rebuild the Infra & Lambda Code and deploy the CloudFormation ChangeSet.

Next we will add this Lambda to our API Gateway endpoint. Go to API Gateway console. Find the API your created in the Static resource stack.

  1. Create a new resource named customer under the api resource.

  1. Create a proxy resource under customer and please Enable API Gateway CORS selected.

  1. Connect to your Lambda function.

  1. Add a CORS allow header for Web Broswer, click customer/+{proxy}/option and Integration Response, click the Pencil icon to modify the Access-Control-Allow-Headers Mapping value to 'cache-control,Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'

  1. Deploy the API the PROD stage

Finally, we will add our new Lambda function to Warmup CloudWatch Event we created in Static resource stack:

  1. Go to CloudWatch console, and click Events>Rules menu.

  2. Find the Static stack created Event:

  1. Click Action>Edit menu:

  1. Select the Customer service Lambda function and click Configure details and Update rule to save your Event rule.

Deploy Vet and Visit Services CI/CD Infrastructure

Use the same way to deploy Vet and Visit services just same as we have done and add the API Gateway endpoint resource for vet and visit to connect the Lambda functions we have created by CI/CD processes. Please don't forget to add both Vet and Visit Lambda function to Warmup CloudWatch Event Rule.

Test your CI/CD Processes Deployment

Connect to the Static stack created Web Bucket URL

Clean up all the AWS resources

cd static-service-cicd && cdk destroy
cd ../customer-service-cicd && cdk destroy customer-cicd-stack
cd ../vet-service-cicd && cdk destroy vet-cicd-stack
cd ../visit-service-cicd && cdk destroy visit-cicd-stack