Docker 搭建 GitHub Actions Runner 配置参考


我们相信您已经对 Docker 有了一定了解,如果没有,请自行百度。以下脚本为作者自用,仅供参考,不保证绝对的通用性

Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
FROM ubuntu:latest

# set the github runner version
ARG RUNNER_VERSION="2.309.0"

# update the base packages and add a non-sudo user
RUN apt-get update -y && apt-get upgrade -y && useradd -m docker &&\
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends curl libssl-dev python3 python3-pip\
&& cd /home/docker && mkdir actions-runner && cd actions-runner \
&& curl -O -L https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz \
&& tar xzf ./actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz \
&& rm ./actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz\
&& chown -R docker ~docker && /home/docker/actions-runner/bin/installdependencies.sh \
&& apt remove curl libssl-dev python3 python3-pip -y \
&& apt autoremove -y && apt clean\
&& apt-get update && apt-get install -y sudo lsb-release && apt-get clean all \
&& echo "docker ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers \
&& sudo -u docker ./config.sh --url https://github.com/<YOUR_ORG_OR_REPO_HERE> --token <YOUR_TOKEN_HERE>

# since the config and run script for actions are not allowed to be run by root,
# set the user to "docker" so all subsequent commands are run as the docker user
USER docker

WORKDIR /home/docker/actions-runner

COPY start.sh start.sh

# set the entrypoint to the start.sh script
CMD ["/home/docker/actions-runner/start.sh"]

start.sh

请在构建前确保此脚本有执行权限

1
2
3
#!/bin/sh

./run.sh

reset.sh

请在开启自动重置前确认此脚本有执行权限

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/sh

# 定义容器和镜像的名称
CONTAINER_NAME="actions-runner"
IMAGE_NAME="actions-runner"

# 停止并删除容器(如果存在)
docker stop $CONTAINER_NAME
docker rm $CONTAINER_NAME

# 创建并启动新容器
docker run --name $CONTAINER_NAME -d $IMAGE_NAME

# 输出提示信息
echo "The container $CONTAINER_NAME has been reset."

auto_reset.sh

自动重置脚本,需要 root 权限

1
2
3
4
5
while (true);
do
./reset.sh
sleep 86400
done

Hexo部署指南及踩坑记录


为什么选择 Hexo

Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页。

从上面的介绍我们可以注意到这个东西:

即可利用靓丽的主题生成静态网页。

也就是说,我们可以很容易的将基于 Hexo 搭建的博客系统运行在 Github Pages 上

这意味着:能白嫖!能白嫖!(参见:《如何用最少的钱开一个网站?》

初始化 Hexo

您需要先准备以下环境:

  1. Node.js(>=12)
  2. Git

使用 npm 安装 hexo

1
2
3
4
# Windows
npm install -g hexo-cli
# Linux
sudo npm install -g hexo-cli

之后,使用 hexo init 命令初始化您的博客

1
hexo init [目录名称]

如果不传入[目录名称]参数,hexo-cli 在当前目录下初始化博客

创建完成后,目标目录看起来像这样

1
2
3
4
5
6
7
8
.
├── _config.yml
├── package.json
├── scaffolds
├── source
| ├── _drafts
| └── _posts
└── themes

您需要按自己需求修改 hexo 站点配置(_config.yml)文件,参考 配置 | Hexo

一般来说,您只需要修改以下配置项:

  1. title:站点标题
  2. subtitle:站点副标题
  3. author:作者名,也就是您的名字
  4. language:语言,可直接设为zh-CN
  5. timezone:时区,可直接设为Asia/Shanghai
  6. url:站点网址
测试您的配置

您可以在站点根目录使用hexo server指令启动 hexo 自带的服务器,之后使用浏览器访问 127.0.0.1:4000 查看您的更改

修改主题

您可以前往这里选择您的主题

部分主题可以直接用 npm 安装

部分主题需要您下载压缩包并解压到themes目录下

随后,修改 hexo 站点配置,将them项改为您的主题

部分主题可能会拥有自己的配置文件,主题配置在博客根目录下的_config.主题名.yml内(可能需要您手动复制/创建),具体参见主题的 README.md 文件

部署到 github

具体部署方法详见在 Github 上部署 Hexo

注意事项

如果您是使用 git 创建仓库或您修改了设置,您的仓库的默认分支名称可能为master或其他而不是main

请修推送改指令为:

1
git push -u origin 您分支的名称,如master

.github/workflows/pages.ymlon.push.branches

1
2
3
4
5

on:
push:
branches:
- 您的分支名称,如master # default branch

在每次推送后,github 会自动执行编译任务

如果您的仓库名不是用户名.github.io,默认请在用户名.github.io/仓库名访问您的博客

配置评论

因为 Hexo 是静态,所以 Hexo 默认不带有评论

可以使用gitalkgitment等将issue作为您博客的评论,具体参考其项目主页

但是此处有大坑需要注意

上文提到的两个评论插件会要求您申请 OAuth APP以登录github帐号,进入 Strring>Developer strring 创建

  • Application name:您的站点名
  • Homepage URL:您的博客首页URL
  • Authorization callback URL:回调URL

回调URL 需要填您的博客所使用的协议(一般是https://)+所在的域名(一般不含二级域名)

比如本博客的主页地址为:https://blog.thisisxd.top/index.html

则 回调URL 为:https://thisisxd.top

如果 回调URL 错误,登录就会返回error

具体多试试,不成功可以在下面发评论问

常见异常

Error: Not Found

此错误可能是由于以下原因引起的:

  1. 仓库未公开
  2. 仓库未开启issue
  3. 仓库未初始化issue

初始化 issue

  1. 在仓库设置中,勾选Issue,保存并刷新页面
  2. 打开仓库Issues,点击New Issue,编辑内容并提交,即可初始化Issue

Error: Validation Failed.

此错误可能是由于以下原因引起的

  1. 文章标题过长导致url过长

您可以 [修改][8] 文章 [永久链接][7] 以消除此错误

建议阅读

Hexo官方文档

如何用最少的钱开一个网站?


目录

  1. 主机
  2. 域名
  3. CDN
  4. 备注

主机

Github Page

优点

  1. 免费
  2. 支持使用 MarkDown 写网页
  3. 送二级域名

缺点

  1. 速度比较玄学,有时候可能会超时
  2. 不支持PHP
  3. 免费单个文件最大不超过 100MB,仓库最大不超过 1GB

使用方法

参考 https://github.io/

  1. 注册 GitHub 账户
  2. 创建一个名为 用户名.github.io 的公开仓库
  3. 在仓库内上传网站源代码

绑定域名方法

请先将域名解析到 用户名.github.io!

  1. 进入仓库,点击【Settings】
  2. 点击【Pages】
  3. 在【Custom domain】的输入框填入域名后点击【Save】

详见:https://docs.github.com/articles/using-a-custom-domain-with-github-pages/

Gitee Page

优点

  1. 免费
  2. 支持使用 MarkDown 写网页
  3. 送二级域名
  4. 速度比 GitHub Page 好

缺点

  1. 需要实名(就因为这个让我放弃了Gitee Page)
  2. 不支持PHP
  3. 免费单个文件最大不超过 50MB,仓库最大不超过 500MB

使用方法

和 github page 差不多

Freehost(http://www.freehost.cc/)

优点

  1. 免费
  2. 支持 PHP+MySQL
  3. 支持 FTP
  4. 免费 10GB 空间
  5. 似乎可以无限注册

缺点

  1. 速度稍慢
  2. 管理面板广告多

雨云

优点

  1. 价格低
  2. 免费域名
  3. 可自定义错误页、PHP版本(虚拟主机,如果是云服务器能干的更多)

缺点

  1. 性能较差,不稳定
  2. 付费

域名

Freenom(不推荐:免费域名无法重复注册)

优点

  1. 提供免费域名

缺点

  1. 访问速度慢
  2. DNS、NameServer绑定速度慢
  3. 免费域名无法重复注册

CDN

CloudFlare

优点

  1. 免费
  2. 支持直接在上面搭建网站(Worker和Pages)
  3. 解析速度快
  4. 安全可靠

缺点

  1. 免费计划开启 CloudFlare 代理后速度稍慢

备注

这些资源其中大部分是我自己正在用的,就拿我自己网站来说吧

kod.thisisxd.top云盘FTP储存:freehost

blog.thisisxd.top、cloud.thisisxd.top主机:雨云

CDN:CloudFlare

域名:阿里云

pay.thisisxd.top、www.thisisxd.top:Github Page>

XAPI-Group V1 文档


温馨提示:本文可能已经过时

  • 更新日期:June 21st 2022, Tuesday
  • API版本: V1
  • 运行状态:正常
接口名称请求方式URL参数说明
Cave Json DataGEThttp://124.222.63.135:8000//将ITCraft cave数据(ini)使用JSON格式输出
源数据由 xxtg666 提供
随机回声洞数据GEThttp://124.222.63.135:8001//从Cave Json Data中随机选取一项回声洞数据返回
已屏蔽所有数据删除及图片
镜像GEThttp://124.222.63.135:8002/<url>/<url>:原网页一个没有任何用处的镜像站, 一般人访问不了的这玩意也访问不了
随机回声洞文本GEThttp://124.222.63.135:8192//在 随机回声洞数据 的基础上只返回回声洞的内容

备注:所有接口服务器编码默认采用 UTF-8

Python3 PIP 安装


pip is the package installer for Python. You can use it to install packages from the Python Package Index and other indexes.

——pip.pypa.io

鲁迅先生曾经说过这样一句话:“没有pip的Python是没有灵魂的(是不是有点过了)。”

但是,很多人在使用pip的时候,或多或少会遇到这种情况:

[xiaodeng@xd-pc ~]$ python3 -m pip
/usr/bin/python3: No module named pip

如果你遇到了这个提示,那么恭喜你,你 的 Python 没 装 pip!

其实,这种情况很好解决,但是我曾经也被整的晕头转向,话不多说,上解决方案!

解决方案

通用

  1. 下载https://bootstrap.pypa.io/get-pip.py;
  2. 执行

Linux

可以吧这一段代码复制到终端执行:

wget https://bootstrap.pypa.io/get-pip.py
python3 ./get-pip.py
rm ./get-pip.py

输出(因人而异):

[xiaodeng@xd-pc ~]$ wget https://bootstrap.pypa.io/get-pip.py
--2021-12-11 15:07:06--  https://bootstrap.pypa.io/get-pip.py
SSL_INIT
已载入 CA 证书“/etc/ssl/certs/ca-certificates.crt”
正在解析主机 bootstrap.pypa.io (bootstrap.pypa.io)... 151.101.76.175, 2a04:4e42:12::175
正在连接 bootstrap.pypa.io (bootstrap.pypa.io)|151.101.76.175|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2159352 (2.1M) [text/x-python]
正在保存至: “get-pip.py”

get-pip.py          100%[===================>]   2.06M  3.34MB/s  用时 0.6s    

2021-12-11 15:07:07 (3.34 MB/s) - 已保存 “get-pip.py” [2159352/2159352])

[xiaodeng@xd-pc ~]$ python3 ./get-pip.py
Defaulting to user installation because normal site-packages is not writeable
Collecting pip
  Downloading pip-21.3.1-py3-none-any.whl (1.7 MB)
     |████████████████████████████████| 1.7 MB 1.7 MB/s            
Collecting wheel
  Downloading wheel-0.37.0-py2.py3-none-any.whl (35 kB)
Installing collected packages: wheel, pip
Successfully installed pip-21.3.1 wheel-0.37.0
[xiaodeng@xd-pc ~]$ rm ./get-pip.py
[xiaodeng@xd-pc ~]$ 

验证安装

[xiaodeng@xd-pc ~]$ python3 -m pip

Usage:   
  /usr/bin/python3 -m pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  cache                       Inspect and manage pip's wheel cache.
  index                       Inspect information available from package indexes.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  debug                       Show information useful for debugging.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --debug                     Let unhandled exceptions propagate outside the
                              main subroutine, instead of logging them to
                              stderr.
  --isolated                  Run pip in an isolated mode, ignoring
                              environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be
                              used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be
                              used up to 3 times (corresponding to WARNING,
                              ERROR, and CRITICAL logging levels).
  --log <path>                Path to a verbose appending log.
  --no-input                  Disable prompting for input.
  --proxy <proxy>             Specify a proxy in the form
                              [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should
                              attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists:
                              (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
  --trusted-host <hostname>   Mark this host or host:port pair as trusted,
                              even though it does not have valid or any HTTPS.
  --cert <path>               Path to PEM-encoded CA certificate bundle. If
                              provided, overrides the default. See 'SSL
                              Certificate Verification' in pip documentation
                              for more information.
  --client-cert <path>        Path to SSL client certificate, a single file
                              containing the private key and the certificate
                              in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine
                              whether a new version of pip is available for
                              download. Implied with --no-index.
  --no-color                  Suppress colored output.
  --no-python-version-warning
                              Silence deprecation warnings for upcoming
                              unsupported Pythons.
  --use-feature <feature>     Enable new functionality, that may be backward
                              incompatible.
  --use-deprecated <feature>  Enable deprecated functionality, that will be
                              removed in the future.
[xiaodeng@xd-pc ~]$