跳转到内容

docsify部署

  1. 启动docsify,访问3000端口
  2. 为解决手动拉取仓库代码问题,配置webhook
  • docker-compose.yaml
yaml
services:
  docsify:
    image: docsify:latest
    build:
      context: ./dockerfile/docsify
      dockerfile: Dockerfile
    restart: unless-stopped
    ports:
      - 3000:3000
      - 35729:35729
    volumes:
      - ./data/docs:/docs
  webhook:
    image: webhook:latest
    user: root
    build:
      context: ./dockerfile/webhook
      dockerfile: Dockerfile
    restart: unless-stopped
    ports:
      - "9000:9000"
    command: -verbose -hooks=/etc/webhook/hooks.json -hotreload
    volumes:
      - ./data/webhook:/etc/webhook
      - ./data/docs:/docs
  • docsify的dockerfile
FROM hub.rat.dev/node:latest
LABEL description="A demo Dockerfile for build Docsify."
WORKDIR /docs
RUN npm install -g docsify-cli@latest
EXPOSE 3000/tcp
ENTRYPOINT ["docsify", "serve", "."]
  • webhook的dockerfile
FROM almir/webhook:latest
USER root
RUN apk add --no-cache git
USER webhook
  • hook.json
json
[
  {
    "id": "auto-pull-from-cnb",
    "execute-command": "/etc/webhook/pull.sh",
    "command-working-directory": "/docs",
    "response-message": "开始从CNB拉取更新...",
    "trigger-rule": {
      "match": {
        "type": "payload-hmac-sha256",
        "secret": "hua?lian8",
        "parameter": {
          "source": "header",
          "name": "X-CNB-Signature"
        }
      }
    }
  }
  • pull.sh
bash
#!/bin/sh
echo "=== Webhook强制同步触发 $(date) ==="
cd /docs

# 确保安全目录配置
git config --global --add safe.directory /docs 2>/dev/null
# 1. 获取远程所有更新
echo "获取远程更新..."
git fetch --all

# 2. 重置到远程main分支(完全一致)
echo "重置到远程版本..."
git reset --hard origin/main

# 3. 清理所有未跟踪的文件和目录(强制)
echo "清理未跟踪文件..."
git clean -fdx

# 4. 验证结果
echo "同步完成!"
echo "当前分支: $(git branch --show-current)"
echo "最新提交: $(git log -1 --oneline)"

基于 MIT 许可发布