Skip to content

Commit

Permalink
Merge branch 'release/1.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
RayWangQvQ committed Mar 7, 2023
2 parents fd1cf6a + d7a7571 commit a7621b6
Show file tree
Hide file tree
Showing 17 changed files with 201 additions and 69 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@
- Feature #460 : publish single file when release
- Feature: use new scripts for gh actions's release
- Feature #473 : let user input when there is no target task in configs
## 1.0.2
- Fix #484 : fix read dic config error
- Merge PR #472 : add reverse proxy host for telegram notification
- Merge PR #483 : update login field for entrypoint
2 changes: 1 addition & 1 deletion common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Authors>Ray</Authors>
<Version>1.0.1</Version>
<Version>1.0.2</Version>
<NoWarn>$(NoWarn);CS1591;CS0436</NoWarn>
</PropertyGroup>
</Project>
62 changes: 29 additions & 33 deletions helm/README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,38 @@
<!--- app-name: bilibili-tool -->

# BiliBili Tool
# BiliBili Tool

BiliBiliTool 是一个自动执行任务的工具,当我们忘记做某项任务时,它会像一个贴心小助手,按照我们预先吩咐它的命令,在指定频率、时间范围内帮助我们完成计划的任务。

[Overview of BiliBili Tool](https://github.com/RayWangQvQ/BiliBiliToolPro)

## TL;DR

### 在集群中通过本地代码直接部署
### 在集群中通过chart部署

```console
$ git clone https://github.com/RayWangQvQ/BiliBiliToolPro.git
$ cd ${local_code_repo}/helm/bilibili-tool
$ vim values.yaml # provides your cookie and cron
[optional]$ vim values.yaml # provides your own settings like cookies
$ helm install <my_release_name> .
```

### 在集群中通过chart部署
如果没有在values.yaml中提供cookie,那么需要手动扫描日志中的二维码进行登录

```console
$ git clone https://github.com/RayWangQvQ/BiliBiliToolPro.git
$ cd ${local_code_repo}/helm/bilibili-tool
$ helm cm-push . <your_chart_repo>
```
Then on the cluster control plane
```console
$ mkdir /tmp/bilibili-tool && cd /tmp/bilibili-tool
$ helm repo add <your_chart_repo> <your_chart_repo_url>
$ helm update && helm pull <your_chart_repo>/bilibili-tool
$ tar -zvxf <tar> -C . && cd <chart_name>
$ vim values.yaml # provides your cookie and cron
$ helm install <my_release_name> .
$kubectl logs -f <pod_name>
```

如果在values.yaml中提供了cookie,那么可以不扫描也可以扫描进行登录,上面的步骤可以暂时不执行

## Introduction

这个chart通过[Helm](https://helm.sh)[Kubernetes](https://kubernetes.io)集群上拉起一个[BiliBiliToolPro](https://github.com/RayWangQvQ/BiliBiliToolPro)deployment


## Prerequisites

- Kubernetes
- Helm
- Helm

或者

Expand All @@ -54,8 +44,8 @@ $ helm install <my_release_name> .
安装Chart并命名为 `my-release`:

```console
$ helm repo add my-repo <my_chart_repo>
$ helm install my-release my-repo/bilibili-tool(:0.2.1)
$helm repo add my-repo <my_chart_repo>
$helm install my-release my-repo/bilibili-tool(:1.0.1)
```

上述命令需要用户在values.yaml里提供cookie等必须信息
Expand All @@ -68,7 +58,7 @@ $ helm install my-release my-repo/bilibili-tool(:0.2.1)
卸载 `my-release` deployment:

```console
$ helm delete my-release
$helm delete my-release
```

上述命令卸载掉所有的release相关资源
Expand All @@ -78,25 +68,29 @@ $ helm delete my-release
| Name | Description | Value | Required |
| ------------------------- | ----------------------------------------------- | ----- | -------- |
| `replicaCount` | Deployment Relicas Count | `1` | true |
| `namespace` | Deployment and ConfigMap deployed namespace | `default` | true |
| `configmap.name` | ConfigMap name contains the entry files | `entry` | true |
| `image.repository` | Global Dockevr registry | `zai7lou/bilibili_tool_pro` | true |
| `image.tag` | Image Tag | `0.2.1` | true |
| `image.tag` | Image Tag | `1.0.1` | true |
| `image.pullPolicy` | Image Pull Policy | `IfNotPresent` | true |
| `imagePullSecrets` | Image Pull Secrets | `[]` | false |
| `nameOverride` | Deployment name in the Chart | `""` | false |
| `fullnameOverride` | Release name when set | `""` | false |
| `resources.limits` | The resources limits for the BiliBili Tool containers | `{}` | true |
| `resources.limits.memory` | The limited memory for the BiliBili Tool containers | `180Mi` | true |
| `resources.limits.cpu` | The limited cpu for the BiliBili Tool containers | `100m` | true |
| `resources.limits.cpu` | The limited cpu for the BiliBili Tool containers | `100m` | true |
| `resources.requests` | The resources requests for the BiliBili Tool containers | `{}` | true |
| `resources.requests.memory` | The requested memory for the BiliBili Tool containers | `180Mi` | true |
| `resources.requests.cpu` | The requested cpu for the BiliBili Tool containers | `100m` | true |
| `resources.requests.cpu` | The requested cpu for the BiliBili Tool containers | `100m` | true |
| `affinity` | Affinity for pod assignment | `{}` | false |
| `nodeSelector` | Node labels for pod assignment | `{}` | false |
| `tolerations` | Tolerations for pod assignment | `[]` | false |
| `env` | Environment variables for the BiliBili Tool container, Ray_BiliBiliCookies__1 and Ray_DailyTaskConfig__Cron are required, others vars pls take a look at [supported envvars](https://github.com/RayWangQvQ/BiliBiliToolPro/blob/main/docs/configuration.md) | `[]` | true |
| `volumes.enabled` | Enable persistent log volume for BiliBili Tool or not | `"false"` | true |
| `volumes.path` | The host path mounted into pod | `"/tmp/Logs"` | false |
| `volumes.name` | The volume name | `"bili-tool-vol"` | false |
| `volumes.log.enabled` | Enable persistent log volume for BiliBili Tool or not | `"false"` | true |
| `volumes.log.path` | The host path mounted into pod | `"/tmp/Logs"` | false |
| `volumes.log.name` | The volume name | `"bili-tool-vol"` | false |
| `volumes.login.enabled` | Enable persistent log volume contains the entries for BiliBili Tool or not | `"false"` | true |
| `volumes.login.name` | The volume name | `"entry"` | false |
| `podAnnotations` | The annotations for the BiliBili Tool pod | `{}` | false |

可以用指定helm install命令行参数 `--set key=value[,key=value]`, 比如
Expand All @@ -110,24 +104,25 @@ $ helm install my-release \
也可以通过指定一个YAML格式的values文件来配置以上参数,比如

```console
$ helm install my-release -f values.yaml my_chart_repo/bilibili-tool
$helm install my-release -f values.yaml my_chart_repo/bilibili-tool
```

> **Tip**: 你可以使用默认的 [values.yaml](bilibili-tool/values.yaml)进行配置

当想更新一些变量时,可以通过指定参数或者直接修改YAML的values文件进行更新

```console
$ helm upgrade my-release my_chart_repo/bilibili-tool <-f values> or <--set-file ...>
$helm upgrade my-release my_chart_repo/bilibili-tool <-f values> or <--set-file ...>
```

## Upgrade

建议重新装release

## [Optional]本地Cluster运行

通过安装[kind](https://kind.sigs.k8s.io/docs/user/quick-start/)工具在本地运行一个Kubernetes Cluster

### Prerequisites

go 1.17+ and Docker installed

```console
Expand All @@ -140,4 +135,5 @@ nodes:
- role: worker
$ EOF
```

at least one worker node otherwise you have to provides tolerations in the values.yaml to schedule on master node
4 changes: 2 additions & 2 deletions helm/bilibili-tool/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0
version: 1.0.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.2.1"
appVersion: "1.0.1"
83 changes: 83 additions & 0 deletions helm/bilibili-tool/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.configmap.name }}
namespace: {{ .Values.namespace }}
data:
entry_before.sh: |
#!/bin/bash
set -e
echo -e "entry_before\n"
entry_after.sh: |
#!/bin/bash
set -e
echo -e "entry_after\n"
entry.sh: |
#!/bin/bash
set -e
. /app/scripts/entry_before.sh
CONSOLE_DLL="Ray.BiliBiliTool.Console.dll"
CRON_FILE="/etc/cron.d/bilicron"
# https://stackoverflow.com/questions/27771781/how-can-i-access-docker-set-environment-variables-from-a-cron-job
echo "[step 1/5]导入环境变量"
printenv | grep -v "no_proxy" >/etc/environment
declare -p | grep -v "no_proxy" >/etc/cron.env
echo -e "=>完成\n"
echo "[step 2/5]配置cron定时任务"
echo "SHELL=/bin/bash" >$CRON_FILE
echo "BASH_ENV=/etc/cron.env" >>$CRON_FILE
if [ -z "$Ray_DailyTaskConfig__Cron$Ray_LiveLotteryTaskConfig__Cron$Ray_UnfollowBatchedTaskConfig__Cron$Ray_VipBigPointConfig__Cron$Ray_LiveFansMedalTaskConfig__Cron" ]; then
echo "=>使用默认的定时任务配置"
cat /app/scripts/crontab >>$CRON_FILE
else
echo "=>使用用户指定的定时任务配置"
if ! [ -z "$Ray_DailyTaskConfig__Cron" ]; then
echo "$Ray_DailyTaskConfig__Cron cd /app && dotnet $CONSOLE_DLL --runTasks=Daily" >>$CRON_FILE
fi
if ! [ -z "$Ray_LiveLotteryTaskConfig__Cron" ]; then
echo "$Ray_LiveLotteryTaskConfig__Cron cd /app && dotnet $CONSOLE_DLL --runTasks=LiveLottery" >>$CRON_FILE
fi
if ! [ -z "$Ray_UnfollowBatchedTaskConfig__Cron" ]; then
echo "$Ray_UnfollowBatchedTaskConfig__Cron cd /app && dotnet $CONSOLE_DLL --runTasks=UnfollowBatched" >>$CRON_FILE
fi
if ! [ -z "$Ray_VipBigPointConfig__Cron" ]; then
echo "$Ray_VipBigPointConfig__Cron cd /app && dotnet $CONSOLE_DLL --runTasks=VipBigPoint" >>$CRON_FILE
fi
if ! [ -z "$Ray_LiveFansMedalTaskConfig__Cron" ]; then
echo "$Ray_LiveFansMedalTaskConfig__Cron cd /app && dotnet $CONSOLE_DLL --runTasks=LiveFansMedal" >>$CRON_FILE
fi
fi
if ! [ -z "$Ray_Crontab" ]; then
echo "=>检测到自定义定时任务"
echo "$Ray_Crontab" >>$CRON_FILE
fi
cat $CRON_FILE
chmod 0644 $CRON_FILE
crontab $CRON_FILE # 指定定时列表文件
echo -e "=>完成\n"
echo "[step 3/5]启动定时任务,开启每日定时运行"
cron
echo -e "=>完成\n"
echo "[step 4/5]初始运行,进行Login"
cd /app && dotnet Ray.BiliBiliTool.Console.dll --runTasks=Login
echo -e "=>完成Login\n"
echo "[step 5/5]初始运行,尝试测试Cookie"
dotnet Ray.BiliBiliTool.Console.dll --runTasks=Test
echo -e "=>完成\n"
echo -e "[step 全部已完成]\n"
. /app/scripts/entry_after.sh
touch /var/log/cron.log #todo:debian似乎并没有记录cron的日志。。。
tail -f /var/log/cron.log # 追踪cron日志,避免当前脚本终止导致容器终止
34 changes: 29 additions & 5 deletions helm/bilibili-tool/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "bilibili_tool.fullname" . }}
namespace: {{ .Values.namespace }}
labels:
{{- include "bilibili_tool.labels" . | nindent 4 }}
spec:
Expand All @@ -17,11 +18,28 @@ spec:
labels:
{{- include "bilibili_tool.selectorLabels" . | nindent 8 }}
spec:
{{- if .Values.volumes.enabled }}
{{- if or (eq .Values.volumes.log.enabled true) (eq .Values.volumes.login.enabled true) }}
volumes:
- name: {{ .Values.volumes.name }}
{{- if .Values.volumes.log.enabled }}
- name: {{ .Values.volumes.log.name }}
hostPath:
path: {{ .Values.volumes.path }}
path: {{ .Values.volumes.log.path }}
{{- end }}
{{- if .Values.volumes.login.enabled }}
- name: {{ .Values.volumes.login.name }}
configMap:
name: {{ .Values.configmap.name }}
items:
- key: "entry.sh"
path: "entry.sh"
mode: 0755
- key: "entry_before.sh"
path: "entry_before.sh"
mode: 0755
- key: "entry_after.sh"
path: "entry_after.sh"
mode: 0755
{{- end }}
{{- end }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
Expand All @@ -33,10 +51,16 @@ spec:
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
{{- toYaml .Values.env | nindent 12 }}
{{- if .Values.volumes.enabled }}
{{- if or (eq .Values.volumes.log.enabled true) (eq .Values.volumes.login.enabled true) }}
volumeMounts:
{{- if .Values.volumes.log.enabled }}
- mountPath: "/bilibili_tool/Logs"
name: {{ .Values.volumes.name }}
name: {{ .Values.volumes.log.name }}
{{- end }}
{{- if .Values.volumes.login.enabled }}
- mountPath: "/app/scripts"
name: {{ .Values.volumes.login.name }}
{{- end }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
Expand Down
23 changes: 17 additions & 6 deletions helm/bilibili-tool/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.


namespace: default
replicaCount: 1

configmap:
name: entry

image:
repository: zai7lou/bilibili_tool_pro
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "0.2.1"
tag: "1.0.1"

imagePullSecrets: []
nameOverride: ""
Expand All @@ -34,21 +39,27 @@ env:
# value: ""

volumes:
enabled: false
# if `enabled=true`, then path and name is required
path: "/tmp/Logs"
name: "bili-tool-vol"
log:
enabled: true
path: "/tmp/logs"
name: "bili-tool-vol"
login:
enabled: true
name: "entry"



podAnnotations: {}

resources:
# Recommended to set this resources field
limits:
cpu: 100m
memory: 180Mi
memory: 120Mi
requests:
cpu: 100m
memory: 180Mi
memory: 120Mi

nodeSelector: {}

Expand Down
Loading

0 comments on commit a7621b6

Please sign in to comment.