pull file
Some checks failed
CodeQL / Analyze (csharp) (push) Has been cancelled
Close Stale Issues / close_stale_issues (push) Has been cancelled
repo-sync / repo-sync (push) Has been cancelled
auto-deploy-tencent-scf / pre-check (push) Has been cancelled
auto-deploy-tencent-scf / deploy serverless (push) Has been cancelled
Some checks failed
CodeQL / Analyze (csharp) (push) Has been cancelled
Close Stale Issues / close_stale_issues (push) Has been cancelled
repo-sync / repo-sync (push) Has been cancelled
auto-deploy-tencent-scf / pre-check (push) Has been cancelled
auto-deploy-tencent-scf / deploy serverless (push) Has been cancelled
This commit is contained in:
139
helm/README.md
Normal file
139
helm/README.md
Normal file
@@ -0,0 +1,139 @@
|
||||
<!--- app-name: 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
|
||||
[optional]$ vim values.yaml # provides your own settings like cookies
|
||||
$ helm install <my_release_name> .
|
||||
```
|
||||
|
||||
如果没有在values.yaml中提供cookie,那么需要手动扫描日志中的二维码进行登录
|
||||
|
||||
```console
|
||||
$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
|
||||
|
||||
或者
|
||||
|
||||
- Kind
|
||||
- Helm
|
||||
|
||||
## 安装Chart
|
||||
|
||||
安装Chart并命名为 `my-release`:
|
||||
|
||||
```console
|
||||
$helm repo add my-repo <my_chart_repo>
|
||||
$helm install my-release my-repo/bilibili-tool(:1.0.1)
|
||||
```
|
||||
|
||||
上述命令需要用户在values.yaml里提供cookie等必须信息
|
||||
[Parameters](#parameters) 部分列出了所有可供自定义的值
|
||||
|
||||
> **Tip**: `helm list` 可以列出当前已经列出的所有的release
|
||||
|
||||
## 卸载 Chart
|
||||
|
||||
卸载 `my-release` deployment:
|
||||
|
||||
```console
|
||||
$helm delete my-release
|
||||
```
|
||||
|
||||
上述命令卸载掉所有的release相关资源
|
||||
|
||||
## Parameters
|
||||
|
||||
| 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 | `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.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 |
|
||||
| `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.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]`, 比如
|
||||
|
||||
```console
|
||||
$ helm install my-release \
|
||||
--set \
|
||||
relicas=1
|
||||
```
|
||||
|
||||
也可以通过指定一个YAML格式的values文件来配置以上参数,比如
|
||||
|
||||
```console
|
||||
$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 ...>
|
||||
```
|
||||
|
||||
## Upgrade
|
||||
|
||||
建议重新装release
|
||||
|
||||
## [Optional]本地Cluster运行
|
||||
|
||||
通过安装[kind](https://kind.sigs.k8s.io/docs/user/quick-start/)工具在本地运行一个Kubernetes Cluster
|
||||
|
||||
go 1.17+ and Docker installed
|
||||
|
||||
```console
|
||||
$ go install sigs.k8s.io/kind@v0.17.0 && kind create cluster <--config kind_config_file>
|
||||
$ cat <kind_config_file>
|
||||
$ kind: Cluster
|
||||
apiVersion: kind.x-k8s.io/v1alpha4
|
||||
nodes:
|
||||
- role: control-plane
|
||||
- role: worker
|
||||
$ EOF
|
||||
```
|
||||
|
||||
at least one worker node otherwise you have to provides tolerations in the values.yaml to schedule on master node
|
||||
24
helm/bilibili-tool/Chart.yaml
Normal file
24
helm/bilibili-tool/Chart.yaml
Normal file
@@ -0,0 +1,24 @@
|
||||
apiVersion: v2
|
||||
name: bilibili-tool
|
||||
description: A Helm chart for running bilibili tool in Kubernetes
|
||||
|
||||
# A chart can be either an 'application' or a 'library' chart.
|
||||
#
|
||||
# Application charts are a collection of templates that can be packaged into versioned archives
|
||||
# to be deployed.
|
||||
#
|
||||
# Library charts provide useful utilities or functions for the chart developer. They're included as
|
||||
# a dependency of application charts to inject those utilities and functions into the rendering
|
||||
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
|
||||
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: 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: "1.0.1"
|
||||
0
helm/bilibili-tool/templates/NOTES.txt
Normal file
0
helm/bilibili-tool/templates/NOTES.txt
Normal file
62
helm/bilibili-tool/templates/_helpers.tpl
Normal file
62
helm/bilibili-tool/templates/_helpers.tpl
Normal file
@@ -0,0 +1,62 @@
|
||||
{{/*
|
||||
Expand the name of the chart.
|
||||
*/}}
|
||||
{{- define "bilibili_tool.name" -}}
|
||||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Create a default fully qualified app name.
|
||||
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
|
||||
If release name contains chart name it will be used as a full name.
|
||||
*/}}
|
||||
{{- define "bilibili_tool.fullname" -}}
|
||||
{{- if .Values.fullnameOverride }}
|
||||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
|
||||
{{- else }}
|
||||
{{- $name := default .Chart.Name .Values.nameOverride }}
|
||||
{{- if contains $name .Release.Name }}
|
||||
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
|
||||
{{- else }}
|
||||
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Create chart name and version as used by the chart label.
|
||||
*/}}
|
||||
{{- define "bilibili_tool.chart" -}}
|
||||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Common labels
|
||||
*/}}
|
||||
{{- define "bilibili_tool.labels" -}}
|
||||
helm.sh/chart: {{ include "bilibili_tool.chart" . }}
|
||||
{{ include "bilibili_tool.selectorLabels" . }}
|
||||
{{- if .Chart.AppVersion }}
|
||||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
|
||||
{{- end }}
|
||||
app.kubernetes.io/managed-by: {{ .Release.Service }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Selector labels
|
||||
*/}}
|
||||
{{- define "bilibili_tool.selectorLabels" -}}
|
||||
app.kubernetes.io/name: {{ include "bilibili_tool.name" . }}
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Create the name of the service account to use
|
||||
*/}}
|
||||
{{- define "bilibili_tool.serviceAccountName" -}}
|
||||
{{- if .Values.serviceAccount.create }}
|
||||
{{- default (include "bilibili_tool.fullname" .) .Values.serviceAccount.name }}
|
||||
{{- else }}
|
||||
{{- default "default" .Values.serviceAccount.name }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
83
helm/bilibili-tool/templates/configmap.yaml
Normal file
83
helm/bilibili-tool/templates/configmap.yaml
Normal file
@@ -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日志,避免当前脚本终止导致容器终止
|
||||
78
helm/bilibili-tool/templates/deployment.yaml
Normal file
78
helm/bilibili-tool/templates/deployment.yaml
Normal file
@@ -0,0 +1,78 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: {{ include "bilibili_tool.fullname" . }}
|
||||
namespace: {{ .Values.namespace }}
|
||||
labels:
|
||||
{{- include "bilibili_tool.labels" . | nindent 4 }}
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
{{- include "bilibili_tool.selectorLabels" . | nindent 6 }}
|
||||
template:
|
||||
metadata:
|
||||
{{- with .Values.podAnnotations }}
|
||||
annotations:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
labels:
|
||||
{{- include "bilibili_tool.selectorLabels" . | nindent 8 }}
|
||||
spec:
|
||||
{{- if or (eq .Values.volumes.log.enabled true) (eq .Values.volumes.login.enabled true) }}
|
||||
volumes:
|
||||
{{- if .Values.volumes.log.enabled }}
|
||||
- name: {{ .Values.volumes.log.name }}
|
||||
hostPath:
|
||||
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:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
containers:
|
||||
- name: {{ .Chart.Name }}
|
||||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
|
||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||
env:
|
||||
{{- toYaml .Values.env | nindent 12 }}
|
||||
{{- 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.log.name }}
|
||||
{{- end }}
|
||||
{{- if .Values.volumes.login.enabled }}
|
||||
- mountPath: "/app/scripts"
|
||||
name: {{ .Values.volumes.login.name }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
resources:
|
||||
{{- toYaml .Values.resources | nindent 12 }}
|
||||
{{- with .Values.nodeSelector }}
|
||||
nodeSelector:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.affinity }}
|
||||
affinity:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.tolerations }}
|
||||
tolerations:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
68
helm/bilibili-tool/values.yaml
Normal file
68
helm/bilibili-tool/values.yaml
Normal file
@@ -0,0 +1,68 @@
|
||||
# Default values for bilibili_tool.
|
||||
# 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: "1.0.1"
|
||||
|
||||
imagePullSecrets: []
|
||||
nameOverride: ""
|
||||
fullnameOverride: ""
|
||||
|
||||
# For more envs pls take a view at https://github.com/RayWangQvQ/BiliBiliToolPro/blob/main/docs/configuration.md
|
||||
env:
|
||||
# cookie - required
|
||||
- name: Ray_BiliBiliCookies__1
|
||||
# past your cookie value
|
||||
value: ""
|
||||
# DailyTrigger - required
|
||||
- name: Ray_DailyTaskConfig__Cron
|
||||
# This means BiliBili Toll triggers at every day's 08:10 AM
|
||||
value: "10 8 * * *"
|
||||
|
||||
# Add your custom env vars like
|
||||
# - name: Ray_Security__IntervalSecondsBetweenRequestApi
|
||||
# value: "20"
|
||||
# - name: Ray_Security__RandomSleepMaxMin
|
||||
# value: "20"
|
||||
# - name: Ray_LiveLotteryTaskConfig__Cron
|
||||
# value: ""
|
||||
|
||||
volumes:
|
||||
# if `enabled=true`, then path and name is required
|
||||
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: 120Mi
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 120Mi
|
||||
|
||||
nodeSelector: {}
|
||||
|
||||
tolerations: []
|
||||
|
||||
affinity: {}
|
||||
Reference in New Issue
Block a user