In the previous chapter, Documentation Setup, we learned how to turn our Markdown files into a beautiful website. We used docsify serve to see it on our own computer.
But here is the problem: "Localhost" only works for you. If you send the link http://localhost:3000 to a friend, it won't work for them. Your computer is the server, and unless they are sitting in your room, they can't connect to it.
This chapter is about Deployment. This is the process of moving your application from your private laptop to a public server on the internet so the whole world can see it.
Imagine you have spent months building a beautiful model train set in your basement. It is amazing, but only people who visit your house can see it.
Deployment is like moving that train set to a public museum. Now, anyone with a ticket (or a web link) can visit it 24/7, even when you are asleep.
The Goal: You want your friend in another country to play the Quiz App you built in Quiz Application Development.
The Solution: You need to:
We will use Azure Static Web Apps (the space) and GitHub Actions (the shipping company) to do this.
Deployment can sound scary, but it is just moving files from Place A to Place B.
The "Cloud" is just a warehouse full of powerful computers that run 24/7. When we "deploy to Azure," we are simply copying our files onto one of Microsoft's computers. This computer serves our website to anyone who asks for it.
Our Quiz App and Documentation site are Static.
Azure Static Web Apps is a service designed specifically to host these types of files cheaply and quickly.
Continuous Integration / Continuous Deployment (CI/CD) is a fancy term for automation.
To solve our use case (Sharing the Quiz), we don't need to write code. We need to configure the connection between GitHub and Azure.
Azure needs permission to read your code.
ML-For-Beginners), and the branch (main).This is the most critical step. We need to tell Azure where our app lives.
/quiz-apppackage.json lives.distnpm run build creates a folder named dist. That is the folder we want the public to see.
Click Review + create. Azure will take a few minutes to set everything up. Once it is done, it will give you a URL like:
https://agreeable-meadow-0d.azurestaticapps.net
Click it. Your quiz is now on the internet!
How does Azure know when you change your code? It installs a "spy" (a Workflow file) in your repository.
.github/workflows folder.dist folder) and sends it to Azure.When you connected Azure to GitHub in Step 2, Azure automatically created a file in your repository. Let's look at it.
Location: .github/workflows/azure-static-web-apps-<random-name>.yml
# The Trigger
on:
push:
branches:
- main
jobs:
build_and_deploy_job:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# The Magic Step
- name: Build and Deploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_TOKEN }}
app_location: "/quiz-app" # Where is the code?
output_location: "dist" # Where is the built site?
Explanation:
on: push: This tells the robot to wake up every time you save changes to the main branch.app_location: Matches the setting we chose in the Azure Portal.output_location: Tells the robot to only upload the final, optimized version of the site.If your deployment fails, you can see exactly why.
You might see an error like:
App Directory Location: '/quiz-app' was not found.
Explanation: This means you typed the folder name wrong in the configuration. The robot couldn't find your code to build it.
You might notice this line in the code above:
azure_static_web_apps_api_token: ${{ secrets.AZURE_TOKEN }}
What is a Secret?
This is like a password. You never want to write your password directly in a file that is public on the internet. GitHub stores this password in a secure vault called "Secrets." The ${{ }} syntax tells the robot: "Go to the vault, get the token, and use it here."
Congratulations! You have reached the end of the ML-For-Beginners setup curriculum.
In this chapter, we learned:
Let's look back at what you have accomplished:
You are no longer just a student reading a book. You are a contributor with a fully functioning Development, Testing, and Deployment environment.
You are now ready to tackle the actual Machine Learning lessons in the numbered folders.
Happy Coding!
Generated by Code IQ