According to Azure's official documenatation, "Microsoft Azure is the freedom to build, manage and deploy applications on a massive, global network using your favorite tools and frameworks."
Whether you are working on a side project or a startup, Azure can be the one destination for all your needs, including deployment, storage, scaling, security, and more.
This guide will walk you through the step-by-step process of deploying a React app to Azure App Service and streamline CI/CD using Azure DevOps. This guide uses a React app made with react-bootstrap
; you can read more about it here.
To deploy a React app, you first need to create an app service on Azure. As the name suggests, an app service is a platform for building, deploying, and scaling web apps.
Here are the steps:
If you haven't already created an account on Azure, you can opt for a free account to follow this guide.
For Subscription, choose your free subscription. Create a new Resource Group for this app. This guide uses the Resource Group named react-example-deploy.
Give a unique name to your app; this guide uses rbtutorial. For Publish choose Code.
Select Node 10.14 as Runtime Stack and Windows as Operating System.
Finally, please select the closest region to you or leave it at default.
After a few minutes, your new app service will be live, and you will see a message like this.
You can visit {yourAppServiceName}.azurewebsites.net
to see it in action. You can see a default page from Microsoft based on the Runtime Stack you chose. Your React app will be deployed on this same URL.
According to Azure's official docs, "Azure DevOps is a software as a service (SaaS) platform from Microsoft that provides an end-to-end DevOps toolchain for developing and deploying software."
Here, we will use Azure DevOps to streamline continuous integration and continuous deployment in our app.
If you have already created an Azure DevOps Organization, feel free to skip this subsection. Here are the steps you need to follow to create an Azure DevOps organization:
Sign in to Azure DevOps.
Your organization is now created and can be accessed at https://dev.azure.com/{yourorganization}
, where yourorganization
is your organization's name.
On your Azure DevOps organization dashboard, create a new project. Give a unique name to your project and then hit Create project.
With this, your project will be created.
You will now push the React app from your local machine to the project you just created via Command-Line.
Here are the steps you need to follow.
1git init
2git add .
3git commit -m "Initial Commit"
After running this command, you can see your React project under Repos → Files.
Now that you have pushed your app to the Azure DevOps project, the next step is to create a pipeline for building artifacts and a release pipeline to deploy the React app.
According to Azure's documentation, "Using Azure Pipelines you can run builds, perform tests, and deploy code (release) automatically to various development and production environments."
Here are the steps to create a build artifacts pipeline.
Search for "npm" and add the npm task twice.
You may ask, why twice? Because this task is for installing the packages, you need another task for building the project; there is no default task present, so you need to create a custom task for this.
Click on the second npm task and configure it as follows.
Click on Publish build artifacts and change Path to publish to build.
On the Run pipeline modal, leave everything at default and hit Save and run.
After a few minutes, the pipeline will finish running successfully. You can check under the Pipelines tab to verify it.
A release pipeline will deploy the artifacts that were built in the last section. You can read more about it here.
Here are the steps to create a release pipeline:
You will be asked to name the Stage. Enter Production and close the modal.
For Source, choose the pipeline you created in the last section, i.e., React Deploy Example-CI. Leave everything else at default and hit Add.
Enable the first disabled option, enter master in Build branch, and close the modal.
You will be asked to configure Deploy Azure App Service.
Choose the Azure subscription based on your subscription. You may need to click Authorize and authorize the subscription.
For App service name, choose the app service that you created in the first section, i.e., rbtutorial.
Click on Deploy Azure App Service, and under Package or folder enter:
$(System.DefaultWorkingDirectory)/_React Deploy Example-CI/drop
Leave the modal that appears at default and hit OK.
Now, click Create release, which will appear to the Save button's right side.
Another modal will appear. Leave it at default, and hit Create.
After a few minutes, your app will be deployed at {yourappservicename}.azurewebsites.net
, which in this case is https://rbtutorial.azurewebsites.net/.
Since you have configured CI/CD, you can update the app on your local machine and push the commit to the repo, which will trigger a new release, and your React app will be updated.
In this guide, we discussed the step by step process of deploying a React app to Azure streamlined with CI/CD.
As a next step, you should try to explore all the different features that Azure offers.
Here are some additional resources that can be helpful.
Happy coding!