Added example config files to run the bot

This commit is contained in:
Alie 2024-02-24 11:38:56 +01:00
parent 5d4888dc1b
commit 6037be5cbe
7 changed files with 247 additions and 0 deletions

View File

@ -0,0 +1,7 @@
This is an example configuration for deployin in k8s and docker compose,
DISCLAIMER
The docker compose one is not so good because since i used k8s i didnt want to figure out how to tun it on a cron
NOTE
This apps can be run nativelly but it has not been tested outside of containers.

54
bot-api.yaml Normal file
View File

@ -0,0 +1,54 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: bot-api
spec:
replicas: 1
selector:
matchLabels:
app: bot-api
template:
metadata:
labels:
app: bot-api
spec:
containers:
- name: bot-api
image: git.fai.st/fedi-image-bot/bot-api:v1.0.0
resources:
limits:
cpu: "500m" # 500 milliCPU
memory: "512Mi" # 512 Mebibytes
ports:
- containerPort: 3000 # Port your Express app is running on
env:
- name: PORT
value: "3000"
- name: MONGODB_URI
value: "mongodb://mongo.svc:27017/bot" # Replace with your DB URL
- name: MONGODB_USER
valueFrom:
secretKeyRef:
name: mongo-creds
key: username
- name: MONGODB_PASS
valueFrom:
secretKeyRef:
name: mongo-creds
key: password
- name: JWTSECRET
value: ""
---
apiVersion: v1
kind: Service
metadata:
name: bot-api-service
spec:
type: NodePort
selector:
app: bot-api
ports:
- protocol: TCP
port: 3000 # Port you want to expose externally
targetPort: 3000 # Port your Express app is running on inside the container
nodePort: 30000

31
bot-cron.yaml Normal file
View File

@ -0,0 +1,31 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: bot-cronjob
spec:
schedule: "* */6 * * *" # Runs every 6 hours
jobTemplate:
spec:
backoffLimit: 0
template:
spec:
containers:
- name: bot-job
image: git.fai.st/fedi-image-bot/mastodon-image-uploader-bot:v1.0.1
volumeMounts:
- name: config-toml
mountPath: /app/config.toml
subPath: config.toml
readOnly: true
- name: mastodon-token
mountPath: /app/mastodon-data.toml
subPath: mastodon-data.toml
readOnly: true
restartPolicy: Never
volumes:
- name: config-toml
configMap:
name: bot-config-toml
- name: mastodon-token
configMap:
name: mastodon-data

100
bot-mongo.yaml Normal file
View File

@ -0,0 +1,100 @@
apiVersion: v1
data:
password: YWRtaW4K #admin this is base64 encoded, change with your choosing
username: YWRtaW4K #admin
kind: Secret
metadata:
name: mongo-creds
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mongo-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: mongo
name: mongo
spec:
replicas: 1
selector:
matchLabels:
app: mongo
strategy: {}
template:
metadata:
labels:
app: mongo
spec:
containers:
- image: mongo:bionic
name: mongo
resources:
limits:
cpu: "500m" # 500 milliCPU
memory: "512Mi" # 512 Mebibytes
args: ["--dbpath","/data/db"]
livenessProbe:
exec:
command:
- mongo
- --disableImplicitSessions
- --eval
- "db.adminCommand('ping')"
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 6
readinessProbe:
exec:
command:
- mongo
- --disableImplicitSessions
- --eval
- "db.adminCommand('ping')"
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 6
env:
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: mongo-creds
key: username
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mongo-creds
key: password
volumeMounts:
- name: "mongo-data-dir"
mountPath: "/data/db"
volumes:
- name: "mongo-data-dir"
persistentVolumeClaim:
claimName: "mongo-data"
---
apiVersion: v1
kind: Service
metadata:
labels:
app: mongo
name: mongo-service
spec:
ports:
- port: 27017
protocol: TCP
targetPort: 27017
selector:
app: mongo

17
bot/config.toml Normal file
View File

@ -0,0 +1,17 @@
[bot]
name = "example-sleeping-girls-bot"
instance = "https://instanceURL"
bio = "Bot who posts images of sleeping girls every 6 hours."
[files]
tempfile = "/tmp/botimage.png"
[backend]
url = "http://backend"
app = "tester"
secret = "test"
[errors]
maintainers = "@example@example.com"
out_of_images = "me quedé sin chicas"
retry = 10

1
bot/mastodon-data.toml Normal file
View File

@ -0,0 +1 @@
YOU SHOULD RUN ONCE THE BOT NATIVELY IN THIS DIRECTORY TO GENERATE THIS FILE AND MAKE SURE TO DELETE IT SO IT GENERATES IT

37
compose.yaml Normal file
View File

@ -0,0 +1,37 @@
version: "3.8"
services:
bot:
image: git.fai.st/fedi-image-bot/mastodon-image-uploader-bot:latest
volumes:
- ./bot:/app/
bot-front:
image: git.fai.st/fedi-image-bot/bot-image-moderation-fe:latest
ports:
- "8081:8081"
environment:
- BACKEND_URL=http://bot-api/
bot-api:
image: git.fai.st/fedi-image-bot/bot-api:latest
ports:
- "8080:8080" # Map container port to host port
depends_on:
- mongodb
environment:
MONGODB_URI: "mongodb://mongodb:27017/bot"
MONGODB_USER: "admin"
MONGODB_PASS: "password"
JWTSECRET: "cooljwtsecret"
mongodb:
image: mongo:bionic
container_name: mongodb
ports:
- "27017:27017"
volumes:
- mongodb_data:/data/db
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: password
MONGO_INITDB_DATABASE: bot
volumes:
mongodb_data: