From 6037be5cbe01db89db11cfd201b6a661c7b417c2 Mon Sep 17 00:00:00 2001 From: Alie Date: Sat, 24 Feb 2024 11:38:56 +0100 Subject: [PATCH] Added example config files to run the bot --- README.md | 7 +++ bot-api.yaml | 54 ++++++++++++++++++++++ bot-cron.yaml | 31 +++++++++++++ bot-mongo.yaml | 100 +++++++++++++++++++++++++++++++++++++++++ bot/config.toml | 17 +++++++ bot/mastodon-data.toml | 1 + compose.yaml | 37 +++++++++++++++ 7 files changed, 247 insertions(+) create mode 100644 bot-api.yaml create mode 100644 bot-cron.yaml create mode 100644 bot-mongo.yaml create mode 100644 bot/config.toml create mode 100644 bot/mastodon-data.toml create mode 100644 compose.yaml diff --git a/README.md b/README.md index e69de29..22b78a6 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file diff --git a/bot-api.yaml b/bot-api.yaml new file mode 100644 index 0000000..b658a26 --- /dev/null +++ b/bot-api.yaml @@ -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 diff --git a/bot-cron.yaml b/bot-cron.yaml new file mode 100644 index 0000000..6642a5c --- /dev/null +++ b/bot-cron.yaml @@ -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 diff --git a/bot-mongo.yaml b/bot-mongo.yaml new file mode 100644 index 0000000..ef68407 --- /dev/null +++ b/bot-mongo.yaml @@ -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 diff --git a/bot/config.toml b/bot/config.toml new file mode 100644 index 0000000..f3823a1 --- /dev/null +++ b/bot/config.toml @@ -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 diff --git a/bot/mastodon-data.toml b/bot/mastodon-data.toml new file mode 100644 index 0000000..abf45f3 --- /dev/null +++ b/bot/mastodon-data.toml @@ -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 \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..2d9fd26 --- /dev/null +++ b/compose.yaml @@ -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: