Platform Engineering With Pulumi (Part 3): Platform and Application Deployment With GitOps Automation
In this blog, we will automatically deploy React JS and NodeJS application on AWS Landing Zone, and modify Pulumi code to create GitOps Infrastructure
Join the DZone community and get the full member experience.Join For Free
In Episode 1 of this blog series, we built an AWS landing zone for our React/Node.js application, using Pulumi. In Episode 2 we built a simple React app and an Express API server. We manually deployed the app on the landing zone. In this episode, we will automate it with GitActions and CodeDeploy.
For the sample application used in this blog, I have used Multi-repo. There is a huge debate on Mono vs Multi Repos. I might blog about that separately, but for now let's assume Multi repo is the best for this application and go ahead :-D.
Before we configure the GitActions, we have to modify the infrastructure code to include Infra code for the creation of code deploy configurations.
Modifying the Infra Code To Create CodeDeploy
In Episode 1, we did not create the CodeDeploy Configurations. Find below the modifications done in the Python code to create appropriate Roles and CodeDeploy configurations. Let's walk through the code (please refer to my GitHub for more latest code.)
In the above code, We are creating a Role, to allow the CodeDeploy service to have access, and attaching appropriate access policies (
Let's now create the CodeDeploy application
In the above code, we are creating a CodeDeploy application. Let's now create deployment groups.
In the above code, we are creating a CodeDeploy Deployment Group, with the Role that we created. This deployment group will be used to deploy API code (Node.js/Express). The below code created a CodeDeploy Deployment Group to deploy the React application. Both the deployment groups are created under the same CodeDeploy Application
Let's now run the code with
GitOps Deploying Node.js API Application
Now that we have all the infrastructure ready.
Lets first create a CodeDeploy Configuration file (
appspec.yml) in our Node.js application.
In the appspec.yml, we are configuring the source and destination (on EC2) folders. This configuration is used by CodeDeploy to deploy the application files in the appropriate folder (
We are also configuring 2 Hooks
Before Install Hook: This is a shell script that we are asking CodeDeploy to run, before deploying the application code. In this shell script, we will set up the environment required. The following is the code for
setup.sh. In this shell script, we are installing NVM and creating a directory for CodeDeploy to deploy the source files:
Application Start Hook: Which is another shell script that we are asking CodeDeploy to run to start the application after deploying the application code. The following is the code for
appStart.sh, where we are setting up the
nvm environment variables, running
npm installto install all the dependencies, and then running our application.
Published at DZone with permission of A B Vijay Kumar. See the original article here.
Opinions expressed by DZone contributors are their own.