Skip to content

Commit a6f20d9

Browse files
committed
🐎 ci: 增加带redis的docker镜像
1 parent 9e7a688 commit a6f20d9

File tree

4 files changed

+114
-41
lines changed

4 files changed

+114
-41
lines changed
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Docker Build and Push
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
env:
9+
IMAGE_NAME: tianli0/tianli-cdn:redis
10+
11+
jobs:
12+
build-and-push:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Wait for Go build to finish
17+
run: sleep 240
18+
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
25+
- name: Log in to Docker Hub
26+
uses: docker/login-action@v3
27+
with:
28+
username: ${{ secrets.DOCKER_USERNAME }}
29+
password: ${{ secrets.DOCKER_PASSWORD }}
30+
31+
- name: Get version
32+
id: version
33+
run: echo "::set-output name=version::$(git describe --tags)"
34+
35+
- name: Build Docker image
36+
run: |
37+
apt-get update && apt-get install -y ca-certificates
38+
docker build -t ${{ env.IMAGE_NAME }} --build-arg VERSION=${{ steps.version.outputs.version }} -f ./docker/dockerfile_redis .
39+
40+
- name: Push Docker image
41+
if: success()
42+
run: docker push ${{ env.IMAGE_NAME }}

README.md

+56-41
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,90 @@
1010

1111
此项目为新手练手项目,欢迎各位大佬PR 批评指正。
1212

13+
## 默认返回
14+
15+
1. `/` 目录将会返回程序运行目录下的`source/index.html`,需自行配置并修改,包括`source/index.js` `source/index.css`
16+
2. `/favicon.ico` 图标,需放置在程序运行目录下。
17+
3. `/static` 目录下静态文件将映射至服务端。
18+
19+
## 图片处理
20+
21+
1. 图片压缩,图片可以转webp,需跟随参数`?webp=true`
22+
23+
2. 图片主色调获取,需跟随参数`?get=theme`
24+
25+
```json
26+
{
27+
"theme": "#eaeaed"
28+
}
29+
```
30+
31+
3. 图片高度宽度获取,需跟随参数`?get=size`
32+
33+
```json
34+
{
35+
"width": 1660,
36+
"height": 302
37+
}
38+
```
39+
1340
## 基础环境
1441

1542
1. 需要主机拥有redis环境
1643

44+
2. 可选部署NSFW鉴权,需要docker运行以下指令(注意:NSFW鉴权AI会严重加重服务器负载,请酌情使用)
45+
46+
```shell
47+
docker run -p 6012:3000 ghcr.io/arnidan/nsfw-api:latest
48+
```
49+
1750
## docker部署
1851

19-
适用于主机包含redis的服务器
52+
### 适用于主机包含redis的服务器
2053

2154
1. 拉取镜像
2255

2356
```shell
24-
docker pull tianli0/tianli-cdn
57+
docker pull tianli0/tianli-cdn:redis
2558
```
2659

27-
28-
29-
2. 1. 在你所需的文件目录新建`.env`文件,注意参考仓库内`.env`配置
30-
2. 创建`/source/index.html` `/source/index.js` `/source/index.css`
60+
2. 1. 在你所需的文件目录新建`.env`文件,注意参考仓库内`.env`配置(无需配置redis相关)
61+
2. 创建`/source/index.html` `/source/index.js` `/source/index.css`
3162
3. 如果您有需要,请参考仓库内并配置`whitelist.json` `advance.json` `blacklist.json`
3263

3364
3. 运行docker容器,注意将`/yourpath/`替换为你的文件目录。
3465

3566
```shell
36-
docker run -d --network=host -p 5012:5012 -v /yourpath/:/app/ tianli0/tianli-cdn
67+
docker run -d --network=host -p 5012:5012 -v /yourpath/:/app/ tianli0/tianli-cdn:redis
3768
```
3869

39-
40-
41-
## 二进制 部署
4270

43-
1. 确保安装redis
71+
### 适用于主机无redis的服务器
4472

45-
2. 可选启用NSFW-api
73+
1. 拉取镜像
4674

47-
```bash
48-
docker run -p 6012:3000 ghcr.io/arnidan/nsfw-api:latest
75+
```shell
76+
docker pull tianli0/tianli-cdn
4977
```
5078

51-
79+
2. 1. 在你所需的文件目录新建`.env`文件,注意参考仓库内`.env`配置()
80+
2. 创建`/source/index.html` `/source/index.js` `/source/index.css`
81+
3. 如果您有需要,请参考仓库内并配置`whitelist.json` `advance.json` `blacklist.json`
82+
83+
3. 运行docker容器,注意将`/yourpath/`替换为你的文件目录。
84+
85+
```shell
86+
docker run -d --network=host -p 5012:5012 -v /yourpath/:/app/ tianli0/tianli-cdn
87+
```
5288

53-
3. 前往release下载对应架构二进制文件
5489

55-
4. 运行可执行文件并配置保活进程,首次启动会自动创建`.env`配置文件,注意自行修改。
5690

57-
5. 配置保活进程,使程序运行在后台,Linux可使用例如`screen`
91+
## 二进制 部署
5892

93+
1. 确保安装redis
94+
2. 前往release下载对应架构二进制文件
95+
3. 运行可执行文件并配置保活进程,首次启动会自动创建`.env`配置文件,注意自行修改。
96+
4. 配置保活进程,使程序运行在后台,Linux可使用例如`screen`
5997
6. 程序会运行在`5012`端口,使用Nginx反向代理5012端口
6098

6199
## 文件清单
@@ -66,11 +104,7 @@
66104
4. `whitelist.json`:白名单信息(请参考仓库配置)
67105
5. `advance.json`:高级缓存配置项(请参考仓库配置)
68106

69-
## 默认返回
70107

71-
1. `/` 目录将会返回程序运行目录下的source/index.html,需自行配置并修改,包括`/index.js` `/index.css`
72-
2. `/favicon.ico` 图标,需放置在程序运行目录下。
73-
3. `/static` 目录下文件将对应服务端运行目录。
74108

75109
## `.env`配置说明
76110

@@ -92,25 +126,6 @@
92126
| REJECTION_METHOD | 403 | 拒绝方式:301或403,当填写301时还需要自行配置301_URL(比如该referer或者path不在白名单中或者处于黑名单中,将会以你设置的其中一种状态码作为处理) |
93127
| 301_URL | https://cdn.jsdelivr.net/ | 当REJECTION_METHOD=301时,将会把非白名单请求重定向至配置的url |
94128

95-
## 图片处理
96-
97-
1. 图片压缩,图片可以转webp,需跟随参数`?webp=true`
98-
2. 图片主色调获取,需跟随参数`?get=theme`
99-
```json
100-
{
101-
"theme": "#eaeaed"
102-
}
103-
```
104-
3. 图片高度宽度获取,需跟随参数`?get=size`
105-
```json
106-
{
107-
"width": 1660,
108-
"height": 302
109-
}
110-
```
111-
112-
113-
114129
## 高级配置
115130

116131
高级配置时不止可以缓存jsd资源,可以自行配置更多静态资源缓存

config.go

+3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func loadconfig() {
8484
ghrawPrefix = os.Getenv("GHRaw_PREFIX")
8585
npmPrefix = os.Getenv("NPMMirrow_PREFIX")
8686
Redis_addr = os.Getenv("REDIS_ADDR")
87+
if Redis_addr == "" {
88+
Redis_addr = "localhost:6379"
89+
}
8790
Redis_password = os.Getenv("REDIS_PASSWORD")
8891
Redis_DB = os.Getenv("REDIS_DB")
8992
Redis_DB_int, err = strconv.Atoi(Redis_DB)

docker/dockerfile_redis

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM ubuntu:latest
2+
3+
ARG VERSION
4+
5+
RUN apt-get update && apt-get install -y wget \
6+
&& wget -O /usr/local/bin/tianlicdn https://github.com/Tianli-CDN/cdn-server/releases/download/${VERSION}/tianlicdn-linux-amd64 \
7+
&& chmod +x /usr/local/bin/tianlicdn \
8+
&& apt-get install -y redis-server
9+
10+
WORKDIR /app
11+
12+
CMD sh -c "redis-server & sleep 10 && tianlicdn"
13+
EXPOSE 5012

0 commit comments

Comments
 (0)