Compare commits
44 Commits
@@ -0,0 +1,32 @@
|
||||
name: build-docker
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- staging
|
||||
- dev
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Login to Docker Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ vars.DOCKER_REGISTRY_FQDN }}
|
||||
username: ${{ vars.DOCKER_REGISTRY_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
driver: docker
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
push: true
|
||||
tags: ${{ vars.DOCKER_REGISTRY_FQDN }}/${{ vars.DOCKER_IMAGE_USERNAME }}/${{ vars.DOCKER_IMAGE_NAME }}:${{ gitea.REF_NAME }}
|
||||
secrets: |
|
||||
GIT_AUTH_TOKEN=${{ secrets.DOCKER_REGISTRY_TOKEN }}
|
||||
@@ -0,0 +1,30 @@
|
||||
name: build-docker-release
|
||||
|
||||
on:
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Login to Docker Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ vars.DOCKER_REGISTRY_FQDN }}
|
||||
username: ${{ vars.DOCKER_REGISTRY_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
driver: docker
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
push: true
|
||||
tags: ${{ vars.DOCKER_REGISTRY_FQDN }}/${{ vars.DOCKER_IMAGE_USERNAME }}/${{ vars.DOCKER_IMAGE_NAME }}:${{ gitea.REF_NAME }},${{ vars.DOCKER_REGISTRY_FQDN }}/${{ vars.DOCKER_IMAGE_USERNAME }}/${{ vars.DOCKER_IMAGE_NAME }}:latest
|
||||
secrets: |
|
||||
GIT_AUTH_TOKEN=${{ secrets.DOCKER_REGISTRY_TOKEN }}
|
||||
@@ -0,0 +1,28 @@
|
||||
name: build-docker
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- dev
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Login to Docker Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ vars.DOCKER_REGISTRY_FQDN }}
|
||||
username: ${{ vars.DOCKER_REGISTRY_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
driver: docker
|
||||
- name: Build
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
push: false
|
||||
tags: ${{ vars.DOCKER_REGISTRY_FQDN }}/${{ vars.DOCKER_IMAGE_USERNAME }}/${{ vars.DOCKER_IMAGE_NAME }}:${{ gitea.REF_NAME }}
|
||||
@@ -105,6 +105,17 @@ contain data that shouldn't normally be logged.
|
||||
|
||||
As an experiment, Docker deployment option has been added.
|
||||
|
||||
### Starting the bot
|
||||
|
||||
1. Install MongoDB using the [official installation manual](https://www.mongodb.com/docs/manual/installation)
|
||||
2. Download
|
||||
the [configuration example file](https://git.end-play.xyz/HoloUA/Discord/src/branch/main/config_example.json) and
|
||||
store it somewhere you would like your bot to access it
|
||||
3. Complete the [configuration](#Configuration) step for this file
|
||||
4. `docker run -d -v /path/to/config.json:/app/config.json --name holoua-discord git.end-play.xyz/holoua/holoua-discord`
|
||||
|
||||
## Building Docker images [Experimental]
|
||||
|
||||
### Building the image
|
||||
|
||||
1. `git clone https://git.end-play.xyz/HoloUA/Discord.git`
|
||||
|
||||
+44
-2
@@ -1,6 +1,11 @@
|
||||
import logging
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from logging import Logger
|
||||
from typing import Literal
|
||||
|
||||
from aiohttp import ClientSession, ClientTimeout
|
||||
from apscheduler.triggers.cron import CronTrigger
|
||||
from apscheduler.triggers.date import DateTrigger
|
||||
from libbot.cache.classes import CacheMemcached, CacheRedis
|
||||
from libbot.cache.manager import create_cache_client
|
||||
from libbot.pycord.classes import PycordBot
|
||||
@@ -13,8 +18,45 @@ class HoloBot(PycordBot):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self._schedule_jobs()
|
||||
self._set_cache_engine()
|
||||
|
||||
def _set_cache_engine(self) -> None:
|
||||
if "cache" in self.config and self.config["cache"]["type"] is not None:
|
||||
self.cache = create_cache_client(self.config, self.config["cache"]["type"])
|
||||
cache_type: Literal["redis", "memcached"] | None = self.config["cache"]["type"]
|
||||
|
||||
if "cache" in self.config and cache_type is not None:
|
||||
self.cache = create_cache_client(
|
||||
self.config,
|
||||
cache_type,
|
||||
prefix=self.config["cache"][cache_type]["prefix"],
|
||||
default_ttl_seconds=3600,
|
||||
)
|
||||
|
||||
async def _send_heartbeat(self) -> None:
|
||||
if self.config["monitoring"]["enabled"] is False:
|
||||
return
|
||||
|
||||
async with ClientSession() as session:
|
||||
await session.post(
|
||||
self.config["monitoring"]["url"],
|
||||
headers={
|
||||
"Authorization": f"Bearer {self.config['monitoring']['token']}"
|
||||
},
|
||||
timeout=ClientTimeout(3.0),
|
||||
)
|
||||
|
||||
def _schedule_jobs(self) -> None:
|
||||
if self.scheduler is None:
|
||||
return
|
||||
|
||||
self.scheduler.add_job(
|
||||
self._send_heartbeat,
|
||||
trigger=DateTrigger(
|
||||
datetime.now(tz=timezone.utc) + timedelta(seconds=5),
|
||||
timezone=timezone.utc,
|
||||
),
|
||||
)
|
||||
self.scheduler.add_job(
|
||||
self._send_heartbeat,
|
||||
trigger=CronTrigger.from_crontab("* * * * *"),
|
||||
)
|
||||
|
||||
+9
-2
@@ -25,12 +25,19 @@
|
||||
"cache": {
|
||||
"type": null,
|
||||
"memcached": {
|
||||
"uri": "127.0.0.1:11211"
|
||||
"uri": "127.0.0.1:11211",
|
||||
"prefix": null
|
||||
},
|
||||
"redis": {
|
||||
"uri": "redis://127.0.0.1:6379/0"
|
||||
"uri": "redis://127.0.0.1:6379/0",
|
||||
"prefix": null
|
||||
}
|
||||
},
|
||||
"monitoring": {
|
||||
"enabled": false,
|
||||
"url": "https://status.example.org/api/v1/endpoints/my-group_my-service/external?success=true",
|
||||
"token": "12345678"
|
||||
},
|
||||
"logging": {
|
||||
"size": 512,
|
||||
"location": "logs"
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import logging
|
||||
from logging import Logger
|
||||
|
||||
from libbot.utils import config_set, config_delete
|
||||
from mongodb_migrations.base import BaseMigration
|
||||
|
||||
logger: Logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Migration(BaseMigration):
|
||||
def upgrade(self):
|
||||
try:
|
||||
config_set("prefix", None, "cache", "memcached")
|
||||
config_set("prefix", None, "cache", "redis")
|
||||
except Exception as exc:
|
||||
logger.error(
|
||||
"Could not upgrade the config during migration '%s' due to: %s",
|
||||
__name__,
|
||||
exc,
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
try:
|
||||
config_delete("prefix", "cache", "redis")
|
||||
config_delete("prefix", "cache", "memcached")
|
||||
except Exception as exc:
|
||||
logger.error(
|
||||
"Could not downgrade the config during migration '%s' due to: %s",
|
||||
__name__,
|
||||
exc,
|
||||
)
|
||||
@@ -0,0 +1,33 @@
|
||||
import logging
|
||||
from logging import Logger
|
||||
|
||||
from libbot.utils import config_set, config_delete
|
||||
from mongodb_migrations.base import BaseMigration
|
||||
|
||||
logger: Logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Migration(BaseMigration):
|
||||
def upgrade(self):
|
||||
try:
|
||||
config_set("enabled", False, "monitoring")
|
||||
config_set("url", "", "monitoring")
|
||||
config_set("token", "", "monitoring")
|
||||
except Exception as exc:
|
||||
logger.error(
|
||||
"Could not upgrade the config during migration '%s' due to: %s",
|
||||
__name__,
|
||||
exc,
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
try:
|
||||
config_delete("monitoring", "enabled")
|
||||
config_delete("monitoring", "url")
|
||||
config_delete("monitoring", "token")
|
||||
except Exception as exc:
|
||||
logger.error(
|
||||
"Could not downgrade the config during migration '%s' due to: %s",
|
||||
__name__,
|
||||
exc,
|
||||
)
|
||||
+8
-8
@@ -1,13 +1,13 @@
|
||||
# Waifu pics related dependencies (not listed directly by waifupics)
|
||||
aiohttp>=3.10.0
|
||||
requests>=2.32.2
|
||||
aiohttp>=3.10.0,<4.0.0
|
||||
requests>=2.32.2,<3.0.0
|
||||
|
||||
aiofiles~=24.1.0
|
||||
apscheduler>=3.10.0
|
||||
aiofiles>=23.0.0,<26.0.0
|
||||
apscheduler>=3.0.0,<4.0.0
|
||||
async_pymongo==0.1.11
|
||||
libbot[speed,pycord,cache]==4.1.0
|
||||
libbot[speed,pycord,cache]==4.5.0
|
||||
mongodb-migrations==1.3.1
|
||||
pymemcache~=4.0.0
|
||||
redis~=5.2.1
|
||||
ujson~=5.10.0
|
||||
pymemcache>=4.0.0,<5.0.0
|
||||
redis>=7.0.0,<8.0.0
|
||||
ujson>=5.0.0,<6.0.0
|
||||
WaifuPicsPython==0.2.0
|
||||
Reference in New Issue
Block a user