Located here: https://github.com/microsoft/azure-dev-day/tree/main/4-devops-lab
In this lab we're going to see how easy it is to create a functional Azure Web App with its source code stored in GitHub and a GitHub CI/CD workflow that builds and deploys the web app. . . in just a matter of minutes.
Note: in this location (https://github.com/microsoft/azure-dev-day/tree/main/4-devops-lab) there is a lab-code-snippets.yml file that you can use to copy / paste updates into your repository's workflow file instead of having to manually type the the updates.
-
Open a browser and sign into the Microsoft Azure Portal at https://portal.azure.com
-
In the search bar, type DevOps Starter and then either press Return or click on DevOps Starter under Services
-
Click on + Create
-
On the next screen, make sure that the DevOps Starter is going to use GitHub. If it isn't, click on the change settings here link.
-
For this lab, create a Node.js web app that uses Express.js, and runs as a Windows Web App.
-
Select the Node.js box.
-
Select the Express.js box. There's no need to add a database.
-
Select the Windows Web App box.
-
Click Authorize to allow Azure to access your GitHub account & create the workflow.
-
If prompted, enter your GitHub username or email address, and password, then click Sign in.
-
Enter your GitHub Organization, Repository, Azure SubScription, Web app name, and Location.
Note: It will take a few minutes to create the Azure and GitHub resources. Go grab a soda or some coffee.
-
-
Once the deployment completes, click on Go to resource to view the deployment.
- Click on Authorize to allow Azure to access your GitHub account to view the latest workflow execution and status of jobs
- Cick on Authorize to finish connecting your GitHub account.
- At this point you can see the GitHub workflow and the Azure resources that were created.
- Click on your App Service name to go to the App Service definition in the Azure portal.
- To create the deployment slot,
- Click on Deployment slots
- Click on + Add Slot
- Name the slot "pre-prod" NOTE: You'll use the slot name later on when you update your CI/CD pipeline.
- Choose Clone settings from: {your production slot name}
- Click Add.
- It will take a minute or so to create the pre-prod slot. Once it finishes, click Close at the boottom of that window.
-
Open a new tab and go to your GitHub account. https://github.com/{your-gh-account}
-
Navigate to the repository that the DevOps Starter created for you by clicking on its name. It's name is the same as the name of the App Service you created.
-
While on the <> Code tab, open the lightweight web editor in GitHub by pressing the period key on your keybaord, then open the devops-starter-workflow.yml file
- Click on .github/workflows
- Click on devops-starter-workflow.yml to see the CI/CD pipeline that was created by the DevOps Starter project.
The workflow contains three jobs. build, Deploy, and FunctionalTests. We're going to update the workflow to add a slot swap action.
-
Add an environment variable called SLOT_NAME: with the value of "pre-prod" by pasting Snippet 1 from the lab-code-snippets.yml file. Be sure the variable is indented the same as the other enviromnent variables.
-
Modify the web app deploy action so it deploys to the pre-prod slot instead of the production slot.
-
To save time with the rest of the lab, delete the FunctionalTests job.
-
Save the changes to the devops-starter-workflow.yml file.
-
Click on the source control icon (1) then click the plus sign (2) to stage the changes you've made. Click in the Message box (3) and type a commit message. Then click on the check mark (4) to commit the change to the master branch. Your workflow will immediately start running since it's configured to run anytime anything is pushed to the master branch.
-
Return to the traditional GitHub UI by.... (1) In the address bar in your browser, (2) change the "dev" in the URL to "com" and then (3) press enter.
-
Click on Actions to go to the Actions tab, then click on the latest workflow to watch it run / view the results. It will take several minutes to complete. Note: In this view, the workflow run name will be whatever you typed for your commit message ("deploy and test pre-prod slot" in this case).
-
You'll see the current state of the two jobs that are in the workflow. You can click on each job name within the run to see the log messages for it. (If the job is still running you'll be able to see the log messages update in real time.)
-
Once the workflow completes, switch back to the Azure Portal tab and from the Deployment slots view, click on the pre-prod slot link, then click on the URL for the pre-prod website.
You should see the Success message on the pre-prod site.
Update the workflow to do a slot swap, and swap the production and pre-prod slots, then in the source code make a change to the website. Here's the basic outline:
-
Remember: to return to the lightweight web-based editor in GitHub, make sure you're on the <> Code tab, then press the period key on your keyboard. (You could also replace ".com" in the URL with ".dev" and vice-versa to switch views.)
-
Add new job to the end of the workflow. Be sure to add "needs: FunctionalTests" to make sure it runs after the FunctionalTests job completes.
-
Add a login to Azure action
-
Add a swap slots action (you'll need to use the Azure CLI to run the command).
The newly added job should look similar to this (remember -- in .yml files, column alignment is crucial):
-
In the file Application/views/index.pug change the .success-text message to something such as p Success is fun!!!!
-
Commit the changes.
-
Watch the workflow run.
-
Once the workflow completes, check the pre-prod website and the production website. The pre-prod website should have the old success message, and the production slot will have the new "Success is fun!!!!" message.