Refactor Discord bot to use dedicated service with profiles#34
Merged
Conversation
The bot was launched via `docker compose run -d --rm`, which strips the service-level restart policy and removes the container on exit. When the host hits memory pressure and the OOM killer takes the bot, it stays gone. Promote it to a real compose service (gated behind the `bot` profile so it doesn't start with `dcp-up-all`) and switch the justfile recipes to `up -d` / `stop` so Docker actually restarts it.
It was only needed because the old run-based launch produced an unlabeled container that had to be matched by inspecting Cmd. Now that the bot is a managed compose service, `docker compose stop bot` does the job directly.
Container names default to <project>-<service>-N, where the project defaults to the parent directory (`django-app`). Pinning it to `oscarr` produces `oscarr-bot-1` etc. without redundant service prefixes. Migration: existing containers/networks under the old `django-app` project are orphaned. Run `docker compose down` against them once, then bring services back up under the new project. The `oscarr_postgres` volume is external and named, so data is unaffected.
Mirrors the brainspread deploy pattern: a workflow_run trigger waits for the CI workflow to finish on main, and on success SSHes into the VPS and runs `just update-oscarr`. Requires the following to be configured on the repo's `ci` environment: - secret DO_SSH_HOST: VPS hostname - secret DO_SSH_USER: SSH user - secret DO_SSH_KEY: SSH private key - variable DO_PROD_DIR: absolute path to the oscarr checkout on the VPS
Restructures CI to mirror brainspread's two-phase pattern: 1. Native fast-fail: ruff format check, ruff lint, pyright type check. 2. Docker-based: bake build with GHA layer cache, migrate, `manage.py check --deploy`, run tests inside the web container. Also: - renames the workflow to "Lint and Test" so deploy.yml's workflow_run reference matches brainspread byte-for-byte - adds a concurrency group so superseded runs cancel - pins python via `python-version-file` rather than a hardcoded 3.12 - drops the GH Actions postgres service in favor of compose's db - adds a `copy-env` justfile recipe so the CI step matches brainspread Kept oscarr-specific bits: ruff format (not Black), pyright type check (brainspread has none), no Node/Prettier (no JS to lint here).
`Prepare .env for CI` becomes `Copy environment file` + `Generate secret key`. `Create volumes and bring up db` becomes `Create volumes` + `Start database`. The DB-up step is unique to oscarr's flow (brainspread folds it into its just recipes); the rest now mirror brainspread byte-for-byte.
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactored the Discord bot deployment to use a dedicated Docker Compose service with profiles instead of running it as a command on the web container. This improves service isolation, management, and enables independent scaling.
Key Changes
docker-compose.yml: Added a new
botservice with profile["bot"]that:start_discord_botmanagement commandrestart: unless-stoppedfor automatic recoveryjustfile: Simplified bot management commands:
stop-discord-bot: Changed from container inspection logic todocker compose --profile bot stop botstart-discord-bot: Changed fromdocker compose runtodocker compose --profile bot up -d botwith auto-restart capabilityrestart-discord-bot: Simplified to usedocker compose --profile bot up -d --force-recreate botupdate-oscarr: Updated build command to include both web and bot services with profile flagImplementation Details
docker compose --profile botsyntaxhttps://claude.ai/code/session_01RJrZb4X5Ywuzq2SjeFXgN1