move gotd fork into repo. (#111)
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
connclose
|
||||
secret.yml
|
||||
@@ -0,0 +1,3 @@
|
||||
FROM ubuntu:latest
|
||||
COPY connclose /usr/sbin/connclose
|
||||
ENTRYPOINT ["/usr/sbin/connclose"]
|
||||
@@ -0,0 +1,42 @@
|
||||
all: connclose
|
||||
|
||||
connclose:
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -buildvcs=false -o connclose .
|
||||
.PHONY: connclose
|
||||
|
||||
image: connclose
|
||||
docker build -t connclose:latest .
|
||||
|
||||
image-load:
|
||||
kind load docker-image connclose:latest
|
||||
|
||||
deploy:
|
||||
kubectl apply -f secret.yml -f deployment.yml -f network.yml -f network.allow.yml
|
||||
|
||||
start:
|
||||
bash start.sh
|
||||
|
||||
down:
|
||||
kind delete cluster
|
||||
|
||||
restart:
|
||||
kubectl rollout restart deployment bot
|
||||
|
||||
update: image image-load restart
|
||||
|
||||
allow:
|
||||
kubectl apply -f network.allow.yml
|
||||
|
||||
deny:
|
||||
kubectl apply -f network.deny.yml
|
||||
|
||||
wait:
|
||||
kubectl rollout status deployment bot
|
||||
|
||||
logs:
|
||||
kubectl logs -l app=bot
|
||||
|
||||
follow:
|
||||
kubectl logs -f -l app=bot
|
||||
|
||||
up: start image image-load deploy wait
|
||||
@@ -0,0 +1,56 @@
|
||||
This project is an attempt to reproduce connection timeout that causes gotd to hang.
|
||||
|
||||
> [!WARNING]
|
||||
> Currently I'm unable to reproduce the issue.
|
||||
|
||||
Referenced issue: https://github.com/gotd/td/issues/1030
|
||||
|
||||
Dependencies:
|
||||
- docker
|
||||
- kind
|
||||
- helm
|
||||
- cilium cli
|
||||
- go
|
||||
|
||||
## Preparation
|
||||
|
||||
```bash
|
||||
cp secret.example.yml secret.yml
|
||||
```
|
||||
|
||||
Edit `secret.yml` and put there your bot and application credentials.
|
||||
|
||||
## Running
|
||||
|
||||
Start cluster:
|
||||
|
||||
```bash
|
||||
make up
|
||||
```
|
||||
|
||||
Deny connections to telegram:
|
||||
```bash
|
||||
make deny
|
||||
```
|
||||
|
||||
Update binary
|
||||
```bash
|
||||
make update
|
||||
```
|
||||
|
||||
Restore connections
|
||||
```bash
|
||||
make allow
|
||||
```
|
||||
|
||||
## Logs
|
||||
|
||||
```bash
|
||||
make logs
|
||||
```
|
||||
|
||||
## Cleanup
|
||||
|
||||
```bash
|
||||
make down
|
||||
```
|
||||
@@ -0,0 +1,65 @@
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: bot
|
||||
labels:
|
||||
app.kubernetes.io/name: bot
|
||||
spec:
|
||||
strategy:
|
||||
type: Recreate
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/name: bot
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: bot
|
||||
app.kubernetes.io/name: bot
|
||||
spec:
|
||||
containers:
|
||||
- name: bot
|
||||
image: connclose:latest
|
||||
imagePullPolicy: Never
|
||||
resources:
|
||||
requests:
|
||||
cpu: 500m
|
||||
memory: 128M
|
||||
limits:
|
||||
cpu: 1000m
|
||||
memory: 256M
|
||||
env:
|
||||
- name: GOMEMLIMIT
|
||||
value: "128MiB"
|
||||
- name: GOMAXPROCS
|
||||
value: "2"
|
||||
- name: OTEL_METRICS_EXPORTER
|
||||
value: "prometheus"
|
||||
- name: OTEL_EXPORTER_PROMETHEUS_PORT
|
||||
value: "8090"
|
||||
- name: OTEL_EXPORTER_PROMETHEUS_HOST
|
||||
value: "0.0.0.0"
|
||||
- name: PPROF_ADDR
|
||||
value: "0.0.0.0:8090"
|
||||
- name: OTEL_RESOURCE_ATTRIBUTES
|
||||
value: "service.name=connclose"
|
||||
- name: OTEL_LOG_LEVEL
|
||||
value: "DEBUG"
|
||||
- name: OTEL_TRACES_EXPORTER
|
||||
value: "none"
|
||||
- name: BOT_TOKEN
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: config
|
||||
key: BOT_TOKEN
|
||||
- name: APP_ID
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: config
|
||||
key: APP_ID
|
||||
- name: APP_HASH
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: config
|
||||
key: APP_HASH
|
||||
@@ -0,0 +1,7 @@
|
||||
kind: Cluster
|
||||
apiVersion: kind.x-k8s.io/v1alpha4
|
||||
nodes:
|
||||
- role: control-plane
|
||||
- role: worker
|
||||
networking:
|
||||
disableDefaultCNI: true
|
||||
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/telegram"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/telegram/message"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
||||
)
|
||||
|
||||
func run(ctx context.Context) error {
|
||||
logger, _ := zap.NewDevelopment(zap.IncreaseLevel(zapcore.DebugLevel))
|
||||
defer func() { _ = logger.Sync() }()
|
||||
|
||||
dispatcher := tg.NewUpdateDispatcher()
|
||||
return telegram.BotFromEnvironment(ctx, telegram.Options{
|
||||
Logger: logger,
|
||||
UpdateHandler: dispatcher,
|
||||
}, func(ctx context.Context, client *telegram.Client) error {
|
||||
sender := message.NewSender(tg.NewClient(client))
|
||||
dispatcher.OnNewMessage(func(ctx context.Context, entities tg.Entities, u *tg.UpdateNewMessage) error {
|
||||
m, ok := u.Message.(*tg.Message)
|
||||
if !ok || m.Out {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := sender.Reply(entities, u).Text(ctx, m.Message)
|
||||
return err
|
||||
})
|
||||
return nil
|
||||
}, telegram.RunUntilCanceled)
|
||||
}
|
||||
|
||||
func main() {
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||
defer cancel()
|
||||
|
||||
if err := run(ctx); err != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "%+v\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
apiVersion: cilium.io/v2
|
||||
kind: CiliumNetworkPolicy
|
||||
metadata:
|
||||
name: telegram
|
||||
spec:
|
||||
endpointSelector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/name: bot
|
||||
egress:
|
||||
- # telegram datacenters list
|
||||
# generated by cmd/dcsidr
|
||||
toCIDRSet:
|
||||
- cidr: 149.154.175.59/32
|
||||
- cidr: 149.154.175.53/32
|
||||
- cidr: 2001:b28:f23d:f001::a/128
|
||||
- cidr: 149.154.167.50/32
|
||||
- cidr: 149.154.167.51/32
|
||||
- cidr: 149.154.167.151/32
|
||||
- cidr: 2001:67c:4e8:f002::a/128
|
||||
- cidr: 2001:67c:4e8:f002::b/128
|
||||
- cidr: 149.154.175.100/32
|
||||
- cidr: 2001:b28:f23d:f003::a/128
|
||||
- cidr: 149.154.167.91/32
|
||||
- cidr: 2001:67c:4e8:f004::a/128
|
||||
- cidr: 149.154.166.120/32
|
||||
- cidr: 2001:67c:4e8:f004::b/128
|
||||
- cidr: 2001:b28:f23f:f005::a/128
|
||||
- cidr: 91.108.56.173/32
|
||||
toPorts:
|
||||
- ports:
|
||||
- port: "443"
|
||||
@@ -0,0 +1,10 @@
|
||||
apiVersion: cilium.io/v2
|
||||
kind: CiliumNetworkPolicy
|
||||
metadata:
|
||||
name: telegram
|
||||
spec:
|
||||
endpointSelector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/name: bot
|
||||
# None.
|
||||
egress: []
|
||||
@@ -0,0 +1,20 @@
|
||||
apiVersion: cilium.io/v2
|
||||
kind: CiliumNetworkPolicy
|
||||
metadata:
|
||||
name: dns
|
||||
spec:
|
||||
endpointSelector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/name: bot
|
||||
egress:
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
io.kubernetes.pod.namespace: kube-system
|
||||
k8s-app: kube-dns
|
||||
toPorts:
|
||||
- ports:
|
||||
- port: "53"
|
||||
protocol: UDP
|
||||
rules:
|
||||
dns:
|
||||
- matchPattern: "*"
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
type: Opaque
|
||||
metadata:
|
||||
name: config
|
||||
stringData:
|
||||
BOT_TOKEN: "1111111111:AAG1SomeBotTokenFromBotFather-1337a"
|
||||
APP_ID: "0123456"
|
||||
APP_HASH: "0123456789abcdef0123456789abcdef"
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
kind create cluster --config kind.yml
|
||||
docker pull quay.io/cilium/cilium:v1.14.6
|
||||
kind load docker-image quay.io/cilium/cilium:v1.14.6
|
||||
|
||||
helm install cilium cilium/cilium --version 1.14.6 \
|
||||
--namespace kube-system \
|
||||
--set image.pullPolicy=IfNotPresent \
|
||||
--set ipam.mode=kubernetes
|
||||
|
||||
cilium status --wait
|
||||
Reference in New Issue
Block a user