How to deploy mkdocs on common platforms
There are web services that you can quickly build and deploy with MkDocs.Do you know of web services that have not been added here? Please add!
Cloudflare Pages
Cloudflare Pages includes Mkdocs
in their Build configuration:\ https://developers.cloudflare.com/pages/platform/build-configuration
Add the following files to your MkDocs:
requirements.txt:\ Please include the required pip package
1mkdocs
2mkdocs-bootswatch
3mkdocs-minify-plugin
runtime.txt:
You can also refer to this:\ https://github.com/fu-sen/CloudflarePages-MkDocs
Cloudflare Workers (Workers Site)
https://developers.cloudflare.com/workers/platform/sites
Edit wrangler.toml
:
After that:
1mkdocs build
2wrangler publish
Docker-based web service (Google Cloud Run, Fly.io, etc.)
- Google Cloud Run: https://cloud.google.com/run
- Fly (fly.io): https://fly.io/
Caddy is adopted as the Web server on the assumption that the Web will be open to the public.\ You should not use mkdocs serve
for public release!
Dockerfile:
1FROM python:3-slim as mkdocs
2COPY . .
3RUN pip install --no-cache-dir -r requirements.txt
4RUN mkdocs build
5FROM caddy:alpine
6COPY --from=mkdocs ./site/ /usr/share/caddy/
7#COPY ./Caddyfile /etc/caddy/Caddyfile
If you want to include a Caddyfile
, remove #
on the last line.
requirements.txt:\ Please include the required pip package
1mkdocs
2mkdocs-bootswatch
3mkdocs-minify-plugin
This port uses 80. For example, when using fly.io, fly.toml
:
1[[services]]
2 internal_port = 80
3 protocol = "tcp"
DOM Cloud Hosting
As of April 2021, the server is DigitalOcean (New York, Singapore and Japan).\ This service has a template function, you can transfer files by extracting git clone
or .zip files, and you can build MkDocs:
https://github.com/domcloud/dom-templates
1source: .zip file URL or git repository
2directory: extract directory
3root: public_html/site
4features:
5- ssl
6- firewall: off
7nginx:
8 ssl: enforce
9 error_pages:
10 - 404 /404.html
11 fastcgi: off
12commands:
13- pip install --user -r requirements.txt
14- mkdocs build
Firebase Hosting
https://firebase.google.com/docs/hosting
Set to firebase.json
:
1"hosting": {
2 "public": "site"
3}
Firebase Hosting only publishes static files. Therefore:
1mkdocs build
2firebase deploy
GitHub Pages
https://www.mkdocs.org/user-guide/deploying-your-docs/
mkdocs has great commands for publishing on GitHub Pages:
GitLab Pages
https://docs.gitlab.com/ee/user/project/pages/
There is a minimal project for that:
https://gitlab.com/pages/mkdocs
Glitch
Sites built from April 2021 can be treated as static sites. This is also possible with MkDocs.
package.json:
1{
2 "glitch": {
3 "projectType": "generated_static"
4 }
5}
When you add requirements.txt
, Glitch will no longer handle Static Sites
.
So include the pip install
command in your package.json
.
and you need to build using mkdocs build
and refer to it using Python http server etc.
The mkdocs serve
is very heavy and this is not for public use!
Note that Glitch is also involved in changing files.
package.json:
1{
2 "scripts": {
3 "start": "pip3 install --user mkdocs && mkdocs build && cd site && python3 -m http.server"
4 }
5}
A project that reflects these: https://glitch.com/edit/#!/mkdocs-p
There are other MkDocs projects, but they don’t reflect the latest specs.
Google App Engine
https://cloud.google.com/appengine
You will need this app.yaml
:
1runtime: python39
2
3handlers:
4- url: /
5 static_files: site/index.html
6 upload: site/index.html
7
8- url: /(.*)
9 static_files: site/\1
10 upload: site/(.*)
Older runtimes may need to go into a little more detail:
1runtime: python27
2api_version: 1
3threadsafe: true
4
5handlers:
6- url: /
7 static_files: site/index.html
8 upload: site/index.html
9
10- url: /(.*\.css)$
11 static_files: site/\1
12 upload: site/css/.*\.css$
13
14- url: /(.*\.js)$
15 static_files: site/\1
16 upload: site/js/.*\.js$
17
18- url: /(.*\.ico)$
19 static_files: site/\1
20 upload: site/img/.*\.ico$
21
22- url: /(.*\.(ttf|woff|woff2))$
23 static_files: site/\1
24 upload: site/fonts/.*\.ico$
25
26
27- url: /(.*)/
28 static_files: site/\1/index.html
29 upload: site/(.*)
It does not include build behavior. Just deploy static files. Therefore:
1mkdocs build
2gcloud app deploy
Netlify
Mentioned in the official documentation:
https://docs.netlify.com/configure-builds/common-configurations/#mkdocs
requirements.txt:\ Please include the required pip package
1mkdocs
2mkdocs-bootswatch
3mkdocs-minify-plugin
Build settings:
- Build command:
mkdocs build
- Publish directory:
site
Render (render.com)
Render can also use Dockerfile
, but you can use MkDocs on Static Sites. The cost is free!
Add the following files to your MkDocs:
requirements.txt:\ Please include the required pip package
1mkdocs
2mkdocs-bootswatch
3mkdocs-minify-plugin
Select Add + - Static Site and add the following settings:
- Build Command:
mkdocs build
- Publish directory:
site
Replit
old name: Repl.it
https://replit.com/
Supports many languages. Perhaps you would choose “Python”.
You can also select Bash instead. This is useful for listing commands side by side.
At a minimum, you need a web server other than MkDocs. Here we use Python http server.
main.sh (Bash):
This is done in Run ▶.
1pip3 install --upgrade pip
2pip3 install -r requirements.txt
3mkdocs build
4cd site
5python3 -m http.server
Note the command name for python3
and pip3
.
.replit (Python)
This is an alternative to main.sh
.
1run = "mkdocs build && cd site && python3 -m http.server"
requirements.txt (Bash)
Please include the required pip package. This can be useful if you want to install many packages.
1mkdocs
2mkdocs-bootswatch
3mkdocs-minify-plugin
If you select Python as the Repl language, you can install it from Package in the sidebar instead.
You can also refer to this (Bash):
https://replit.com/@balloonvendor/mkdocs-e
Vercel
In the past it was the name ZEIT Now
(old domain: now.sh
, Currently unavailable). You may have known.
Add the following files to your MkDocs:
package.json:
1{
2 "name": "mkdocs",
3 "version": "1.0.0",
4 "private": true,
5 "scripts": {
6 "dev": "mkdocs serve",
7 "build": "mkdocs build -d public"
8 }
9}
dev
runs on vercel dev
. Please change if necessary.
requirements.txt:\ Please include the required pip package
1mkdocs
2mkdocs-bootswatch
3mkdocs-minify-plugin
You do not have to change the build settings from the initial state. Vercel will refer to package.json instead.\ Now vercel dev
, vercel
and vercel --prod
will work.
You can also refer to this:\ https://github.com/fu-sen/Vercel-MkDocs
Servers that can publish Static Sites
In addition to the ones listed here,
you can also upload (deploy) the inside of site/
built with mkdocs build
to publish the site,
The choices are huge!
Neocities
There is an Neocities official CLI:
Therefore:
1mkdocs build
2neocities push site
.github/workflows/deploy.yaml (use GitHub Actions):
There are several other CLIs. Use neocel as an example
Neocities official CLI is recommended for Windows.
1name: Deploy Website
2on: [push]
3jobs:
4 deploy:
5 runs-on: macos-latest
6 steps:
7 - uses: actions/checkout@v2
8 - uses: actions/setup-python@v2
9 with:
10 python-version: 3.x
11 - run: pip install -r requirements.txt
12 - run: mkdocs build
13 - uses: actions/setup-node@v2-beta
14 with:
15 node-version: 14
16 - run: npm install -g neocel
17 - run: neocel -d site -t ${{ secrets.NEOCITIES_API_KEY }} -y
Surge (surge.sh)
Direct command:
.github/workflows/deploy.yaml (use GitHub Actions):
1name: Deploy Website
2on: [push]
3jobs:
4 deploy:
5 runs-on: windows-latest
6 steps:
7 - uses: actions/checkout@v2
8 - uses: actions/setup-python@v2
9 with:
10 python-version: 3.x
11 - run: pip install -r requirements.txt
12 - run: mkdocs build
13 - uses: actions/setup-node@v2-beta
14 with:
15 node-version: 14
16 - run: npm i -g surge
17 - run: surge site --token ${{ secrets.SURGE_TOKEN }}
References
捐赠本站(Donate)
如您感觉文章有用,可扫码捐赠本站!(If the article useful, you can scan the QR code to donate))
- Author: shisekong
- Link: https://blog.361way.com/2023/10/mkdocs-deployment.html
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.