Deploy Mkdocs page on Azure Web App

  • Thread starter Thread starter theringe
  • Start date Start date
T

theringe

MkDocs is a simple static site generator that's geared towards building project documentation. Documentation source files are written in Markdown, and configured with a single YAML configuration file.



This tutorial will demonstrate how to host an Mkdocs project dynamically or statically. You can choose either method to publish your project based on your needs, and the two approaches are independent of each other.



TOC:


  • Dynamic Hosting in Development Environment
  • Static Hosting in Development Environment
  • Dynamic Method: Using Python Web App
  • Static Method: Using Node Web App

  • Static Method: Using Static Web App

  • References





Dynamic Hosting in Development Environment

STEP 1:

Use VSCode to open an empty folder. Start a terminal and input the following commands to create a Python virtual environment and switch the current session to this environment.


theringe_0-1729159497211.png



Windows



Code:
python -m venv .venv
.\.venv\Scripts\Activate.ps1





Linux



Code:
python -m venv .venv
source .venv/Scripts/activate





STEP 2:

Enter the following commands to create an Mkdocs project (for example, my-project), switch to the project directory, and start the project. You will then be able to visit the project page in your browser at http://127.0.0.1:8000.




Code:
pip install mkdocs
mkdocs new my-project
cd my-project
mkdocs serve



theringe_1-1729159581417.png




Static Hosting in Development Environment

STEP 1:

Once the project is created in the development environment, the pages originally displayed must be rendered using Python and the Mkdocs package. We can run the following commands to build these pages into pure static HTML, making them deployable to any static website hosting service, such as Azure Static Website or the Azure Web App introduced here.

After the project is built, you will find the corresponding static web pages in the newly created site subfolder. You can open index.html in your browser to see the project page.


theringe_2-1729159601830.png



mkdocs build




Dynamic Method: Using Python Web App

STEP 1:

Create a Linux Python Web App on Azure.


theringe_4-1729159692922.png



STEP 2:

Using VSCode, add two files, "mkdocs.sh" and ".deployment", to the root directory of your project.


theringe_6-1729159824329.png

mkdocs.sh



Code:
pip install mkdocs
cd /home/site/wwwroot/my-project/
mkdocs serve -a 0.0.0.0:8000





.deployment



Code:
[config]
SCM_DO_BUILD_DURING_DEPLOYMENT=false





STEP 3:

Deploy the root directory of the project to the Python app you just created using VSCode.


theringe_9-1729159911835.png



STEP 4:

On Azure, find the Python app and modify the startup command as follows, then restart the app.


theringe_11-1729159972203.png



bash /home/site/wwwroot/mkdocs.sh





theringe_12-1729159972204.png



STEP 5:

Check if your project is running correctly.


theringe_15-1729160040411.png


Static Method: Using Node Web App

STEP 1:

Create a Linux Node Web App on Azure.


theringe_5-1729159716245.png



STEP 2:

In the Mkdocs subfolder of your project, find the site folder, and add a .deployment file inside it.


theringe_7-1729159849251.png

.deployment



Code:
[config]
SCM_DO_BUILD_DURING_DEPLOYMENT=false





STEP 3:

Deploy the "site" subdirectory of your project to the Node app you just created using VSCode.


theringe_10-1729159931507.png



STEP 4:

On Azure, find the Node app, modify the startup command, and restart the app.


theringe_13-1729160009129.png



pm2 serve /home/site/wwwroot --no-daemon





theringe_14-1729160009130.png



STEP 5:

Check if your project is running correctly.


theringe_16-1729160056176.png



Static Method: Using Static Web App

STEP 0:

You can create a GitHub repository for the entire project folder (for example, I've named it mkdocs-app), or you may choose to only upload the "site" subdirectory, depending on your needs. In this example, I'll use the entire project folder.


theringe_0-1729218289813.png



STEP 1:

Create a Static Web App on Azure and specify your project's GitHub repository and the corresponding branch during the process. Please note that you'll also need to set your App Location/Output Location as follows, adjusting the name to your "mkdocs project" (for example, my-project).




./my-project/site



theringe_1-1729218307095.png



STEP 2:

Once the SWA is created, you can check the deployment status in the GitHub repository. After the deployment is complete, you'll be able to see the actual page.


theringe_2-1729218359079.png



STEP 3:

Verify that your project is running properly.


theringe_3-1729218371692.png



References

MkDocs

Azure Linux Web App and http server - Microsoft Community Hub

Quickstart: Build your first static web app | Microsoft Learn


Continue reading...
 
Back
Top