Skip to content

Commit

Permalink
Update login field for entrypoint
Browse files Browse the repository at this point in the history
Signed-off-by: chenliu1993 <[email protected]>
  • Loading branch information
chenliu1993 committed Mar 7, 2023
1 parent 7cbd2cf commit 20d1561
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 36 deletions.
42 changes: 19 additions & 23 deletions helm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,20 @@ BiliBiliTool 是一个自动执行任务的工具,当我们忘记做某项任

## TL;DR

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

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

### 在集群中通过chart部署

```console
$ git clone https://github.com/RayWangQvQ/BiliBiliToolPro.git
$ cd ${local_code_repo}/helm/bilibili-tool
$ helm cm-push . <your_chart_repo>
[optional]$ vim values.yaml # provides your own settings like cookies
$ helm install <my_release_name> .
```
Then on the cluster control plane
如果没有在values.yaml中提供cookie,那么需要手动扫描日志中的二维码进行登录
```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

Expand All @@ -55,7 +44,7 @@ $ helm install <my_release_name> .

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

上述命令需要用户在values.yaml里提供cookie等必须信息
Expand All @@ -78,8 +67,10 @@ $ 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 |
Expand All @@ -89,14 +80,16 @@ $ helm delete my-release
| `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 @@ -122,6 +115,9 @@ $ helm install my-release -f values.yaml my_chart_repo/bilibili-tool
$ 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
Expand Down
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

0 comments on commit 20d1561

Please sign in to comment.