Hugo博客配置Drone CI + Gitea

迁移博客

受不了node啦

换Hugo

硬件

回不了学校。。。临时搞了套nas

前一段矿难,有一批矿机被便宜挂到某鱼了

底板9个PCI-E,其中最右边那个插块cpu卡,其他8个显卡

右边那个CPU卡实测可以单板开机,配置还不错,比普通ITX主板便宜多了

于是买了两块,魔改了下供电

左边那个是3215U,右边是A6-3420m,都是千兆口,两块板一共花了180,顺便搞了个矿难路由器,30包邮

于是把Nextcloud Gitea 某ray 等等服务全部丢上去

gitea + drone server

没啥计算负载的丢到左边那块板子上

version: '3'

services:
    gitea:
        image: gitea/gitea
        container_name: gitea
        restart: always
        volumes:
          - ./gitea:/data
          - /etc/timezone:/etc/timezone:ro
          - /etc/localtime:/etc/localtime:ro
        extra_hosts:
          - "drone.naivekun.home:192.168.2.233"
          
networks:
    default:
        external:
            name: docker-br

version: '3'

services:
    drone:
        image: drone/drone:1
        container_name: drone
        volumes:
          - ./drone:/data
          - /etc/localtime:/etc/localtime
        environment:
          - DRONE_SERVER_HOST=drone.naivekun.home
          - DRONE_SERVER_PROTO=http
          - DRONE_GIT_ALWAYS_AUTH=true
          - DRONE_RPC_SECRET=<REDACTED>
          - DRONE_GITEA_SERVER=http://git.naivekun.home
          - DRONE_GITEA_CLIENT_ID=<REDACTED>
          - DRONE_GITEA_CLIENT_SECRET=<REDACTED>
        restart: always
        extra_hosts:
          - "git.naivekun.home:192.168.2.233"
          - "drone.naivekun.home:192.168.2.233"
networks:
    default:
        external:
            name: docker-br

参考文档随便配配就行了

drone runner

runner支持很多种,包括SSH DigitalOcean Docker等等,这里用Docker,每次Build的时候会开个docker跑东西

version: '3'

services:
    drone_runner:
       image: drone/drone-runner-docker:1
       container_name: drone_runner
       environment:
         - DRONE_LOGS_DEBUG=true
         - DRONE_RPC_HOST=drone.naivekun.home
         - DRONE_RPC_PROTO=http
         - DRONE_RPC_SECRET=<REDACTED>
         - DRONE_RUNNER_NAME=drone_runner
       volumes:
         - /var/run/docker.sock:/var/run/docker.sock
         - /etc/localtime:/etc/localtime
       restart: always

networks:
    default:
        external:
            name: docker-br

然后全部up,环境就配完了

写pipeline

.drone.yml用来配置CI的动作

kind: pipeline
type: docker
name: default

platform:
  os: linux
  arch: amd64

steps:
  - name: build
    image: plugins/hugo
    settings:
      pull: never
      url: https://naivekun.com
      validate: true

  - name: publish
    image: plugins/gh-pages
    commands:
    - mkdir ~/.ssh
    - echo -e 'Host github.com\n    HostName github.com\n    StrictHostKeyChecking no\n    IdentityFile /tmp/id_rsa\n    User git\n' > ~/.ssh/config
    - cp id_rsa /tmp
    - chmod 600 /tmp/id_rsa
    - mv public /tmp
    - rm -rf *
    - rm -rf .git
    - rm -rf .drone.yml
    - rm -rf .gitignore
    - git init
    - git remote add origin git@github.com:naivekun/naivekun.github.io.git
    - mv /tmp/public/* .
    - git add .
    - git commit -m "update blog"
    - git config user.email naiveku0817@gmail.com
    - git config user.name naivekun
    - git push origin HEAD:master --force

放个写的很蛇皮的脚本

那个plugins/gh-pages T M D是坏的!!!没办法自己写commands吧

为了免密登录Github,可以ssh-keygen一下,把id_rsa.pub导入仓库,仓库根目录放个id_rsa,具体看上面那个脚本

PUSH!

都配好之后,就很方便辣

本地仓库写完文章,git push

触发CI,自动build然后上传到Github Pages

彩蛋

这玩意就是配的麻烦。。。