12 KiB
12 KiB
Structure and Data
Repository Layout
.gitlab-ci.yml: existing single-stage GitLab pipeline targeting the Belki image.Dockerfile: Python 3.12 runtime image for the calculator web service and shared static assets.app/: calculation domain, report templates, JSON API, HTTP server, and VK Bots Long Poll adapter.web/: calculator frontend plus legacy CatWar userscript assets.deploy/k8s/: namespace, production web/bot/PostgreSQL manifests, and namespace-scoped CI deploy RBAC.docs/GITLAB_CI_CD.md: GitLab variables and CI/CD handoff.tests/: standard-library unit tests for calculation, reports, API, and VK parsing.docs/staging/: working specification and implementation plan for the Belki calculator.AGENTS.md: repo-specific instructions for future coding agents..gitignore: ignores Python bytecode/caches, virtual environments, test output, and local editor noise.MEMORY.md: durable notes about the current CI/runtime decision.
Runtime / Deployment
- GitLab CI runs the build job.
- The job targets GitLab runner tag
fastand builds through a privilegeddocker:29.6.1-dindservice atDOCKER_HOST=tcp://docker:2375, with an explicitalias: dockerandDOCKER_TLS_CERTDIR="". - Runtime dependency layers are prebuilt and stored in the private registry:
reg.nyan404.ru/cwshed-clone/belki-base:py312-d375af9a0f80contains Python 3.12 plus the currentrequirements.txt;reg.nyan404.ru/cwshed/cwshed-base:nginx-c2431df29ccccontains Nginx plusnginx.conf. Adding, removing, or updating a runtime dependency requires rebuilding/pushing and retagging the matching base image before CI; ordinary CI builds only copy application or static files. - The
ryzen-runner-dindservice onroot@10.3.1.168has a valid Runner registration and its helper container can reachhttps://git.nyan404.ru/. On 2026-08-21 its malformedDOCKER_AUTH_CONFIGwas removed and the pre-change configuration was backed up on the host as/etc/gitlab-runner/config.toml.bak-20260821-1334. - The Belki deploy job copies
BELKI_WEB_PASSWORDintoSecret/belki-runtime; if that optional CI variable is absent, it falls back to the already requiredBELKI_ADMIN_PASSWORDso the web Deployment can start. ConfigureBELKI_WEB_PASSWORDseparately when a distinct web password is needed. - The job waits for the DinD daemon and runs
docker infobefore starting the build. - GitLab Runner retries source checkout up to three times (
GET_SOURCES_ATTEMPTS=3) to absorb transient connectivity failures before the job script starts. A persistent inability to reachgit.nyan404.ru:443still requires repair on the selected runner host. - The local image is currently
belki-calculator:test; the CI target is now$DOCKER_REGISTRY/belki:latest. - GitLab CI runs
python -m compileall -q app testsandpython -m unittest discover -s tests -qin a dedicatedteststage before build/deploy. The job explicitly clearsBELKI_DATABASE_URLand uses/tmp/belki-test-identities.sqlite3, preventing unit tests from reaching the Kubernetes PostgreSQL service. Local validation was performed with the same tests, JavaScript syntax check, a local browser/API smoke test, and container health/API smoke. /belkiis the single public workspace: the “Отчёты” tab creates reports and uploads their screenshots without a web-password session; the “Заявки” tab contains the four typed application forms and requestsBELKI_WEB_PASSWORDonly when a user sends an application./applicationsis kept as a legacy direct route./adminremains password-protected.- The VK dialog layer is covered by tests for step-by-step entry, bulk detection, clarification, confirmation, and cancellation.
- Bulk input accepts a natural one-line format without pipes, e.g.
15.08 11:00 11:20 Дикая Вишня 1604614 Серолап 1617140; the web form calls/api/inspect-bulkand fills recognized fields. - Training and inspection have the same stepwise/bulk flow. Character identity can be resolved through
/api/resolve-identityand the persistent SQLite directory; missing pairs produce an explicit prompt instead of guessed data. - Character name/ID pairs are persisted automatically in the SQLite file from
BELKI_IDENTITIES_DB(defaultdata/belki.sqlite3); the database is local runtime data and ignored by Git. - The VK dialog onboards each author once, stores their profile by
from_id, greets them by name, and keeps the profile in the same SQLite database across bot restarts. - Every confirmed calculation is persisted by
app/belki/history.pyto PostgreSQL fromBELKI_DATABASE_URL; SQLite is only a local fallback. Records include actor, source, mode, input, result, rendered message, and timestamp. - VK photo attachments received during an active dialog are normalized into
input.attachmentsand persisted with the calculation; active reports attach photos immediately and deduplicate repeated VK events./adminrenders all thumbnails in a wrapped gallery. WithBELKI_IMAGE_HOST_API_URL, the bot mirrors each photo through image-hosting-web and storesmirror_url; Google Sheets export remains deferred. /adminand/api/admin/calculationsexpose the calculation history for review. The table shows both the reporting cat (escort) and kitten; default sorting is by the reporting cat, with optional kitten sorting. The API requiresX-Admin-PasswordmatchingBELKI_ADMIN_PASSWORD; the web page supports deleting individual records through authenticatedDELETE /api/admin/calculations/{id}, with confirmation in the UI.- Applications are stored independently of calculation history by
app/belki/applications.py:belki_applicationsin PostgreSQL andapplicationsin SQLite. The “Заявки” tab within/belkireuses the existing password-gated web session and upload endpoint;/applicationsremains a legacy direct page./api/applicationscreates web applications, while/api/admin/applicationslists them andPATCH /api/admin/applications/{id}/acceptaccepts one. - Typed flows are: feather donation (amount/color/source rows), kitten (activity screenshot), flying squirrel (past practice and a review link when applicable), and curator (LU screenshot with fraction). VK uses
/заявка,/перо,/бельчонок,/летяга, and/куратор; its context keyboard drives every selectable application branch, while users type only free-form values. The bot polls accepted VK applications every 15 seconds and notifies the original peer; web applications have no inferred VK recipient. - Google Sheets export is pre-wired but disabled by
BELKI_GOOGLE_EXPORT_ENABLED=0.ApplicationStorerecordsapplication_createdandapplication_acceptedsnapshots in the PostgreSQLbelki_application_export_eventsor SQLiteapplication_export_eventsoutbox.GoogleSheetsExportServicesends FIFO JSON events only to an explicitly configured Google Apps Script Web App URL, retains failed events for retry, and is polled by the bot every 15 seconds when enabled. - The admin page uses a restrained light editorial table layout with a separate password gate, category tabs (all, осмотры, ЛУ, ЗУ, ПУ/уроки), responsive filters, client-side sorting across every visible column, cat/kitten selectors, sticky headings, and a keyboard-navigable photo gallery; behavior remains backed by the existing history API.
- VK
messages.sendresponses include a serialized context-aware keyboard; button payloads are translated back into the same dialog commands, while text commands remain supported. - Production k3s deployment (2026-08-16): namespace
belkiruns the Belki web calculator, VK bot, PostgreSQL 16, and the migrated cwshed Nginx gateway. The gateway keeps MetalLB IP10.12.0.204, serves the legacy CatWar site, and routes/belki,/admin, and/api/*to Belki web on10.12.0.212. Belki images arereg.nyan404.ru/cwshed-clone/belkiandreg.nyan404.ru/cwshed; PostgreSQL is mirrored asreg.nyan404.ru/library/postgres:16-alpine-amd64because cluster nodes cannot pull Docker Hub directly. Registry pull credentials and runtime secrets are created out-of-band in thebelkinamespace. - The previously inspected
stage-zone-runnerat10.3.1.236is not the runner used by the current pipeline. Runner#2(Ryzen-builder) at10.3.1.168is a privileged Docker executor and supports the DinD service used by.gitlab-ci.yml. - 2026-08-16
prevent-eolcheck:python:3.12-slimis currently maintained through 2028-10-31; Docker29.6.1-cliwasunknownto the EOL catalog (no finding). Docker/CI references remain tag-pinned rather than digest-pinned.
Change Log
- 2026-06-27: updated the Docker CI image to
docker:29.6.1-cliand aligned the pipeline todocker:dindwithDOCKER_HOST=tcp://docker:2375. - 2026-06-27: verified the working runner on
docker-03.homelab.localand confirmeddocker:29.6.1-dindis reachable from the job network. - 2026-08-16: added the Belki calculator domain, report templates, local web form, VK Long Poll adapter, and draft k3s manifests. Deployment remains intentionally deferred.
- 2026-08-16: made bulk entry conversational and separator-free; added API/web inspection and clarification flow.
- 2026-08-16: rewrote VK help, welcome, and web hints as a concise neutral FAQ; command behavior is unchanged.
- 2026-08-16: added the calculator/VK links to the CatWar home page and deployed the calculator stack to k3s; MetalLB assigned
10.12.0.212. - 2026-08-16: added GitLab build/deploy stages, namespace-scoped
gitlab-deployRBAC, and the ignored local variables handoff.gitlab.variables.env. - 2026-08-16: switched the image build back to explicit aliased DinD after confirming runner
#2has no host socket but can startdocker:29.6.1-dindsuccessfully. - 2026-08-16: replaced the unavailable
bitnami/kubectl:1.34CI image withalpine/k8s:1.36.2, which matches the cluster minor version and includes the shell required by GitLab Runner. - 2026-08-16: corrected coaching payout direction for non-self-sufficient kittens. The escort receives the 1-per-5-minutes base rate or 1.5x for non-self-sufficient ЛУ; kitten points are not reported. Added a 30-minute regression case.
- 2026-08-16: adopted
2026-08-16-krylany-calculator-rules.md: Krylan is the Belka/escort role, kittens always receive 1 point per 5 minutes, non-self-sufficient ЛУ multiplies escort points by 1.5, and ZU forces self-sufficient calculation. - 2026-08-17: aligned
web/calculator.htmlstatus controls with the VK bot and shared domain: LU allows at most one non-self-sufficient kitten, while ZU forces all kittens to self-sufficient; extra-kitten status controls are synchronized and validated before submission. - 2026-08-17: added password-gated web sessions via
BELKI_WEB_PASSWORDand/api/web/auth; web-selected screenshots are sent through/api/web/uploadtoBELKI_IMAGE_HOST_API_URL(productionhttps://img.nyan404.ru) and persisted as report attachments. - 2026-08-21: added structured community applications for feathers, kitten, flying-squirrel, and curator roles across VK,
/applications, and the top-level/admin"Заявки" tab; acceptance is a status transition, not a generated forum post. - 2026-08-21: added a disabled durable Google Sheets export outbox for application-created and application-accepted events; no external request is attempted until an approved Apps Script URL and
BELKI_GOOGLE_EXPORT_ENABLED=1are configured.
Обновление 2026-08-16: несколько котят
Калькулятор прокачки принимает extra_kittens из веб-формы, API и VK-команды. Общая выплата сопровождающему не суммирует полную ставку на каждого котёнка: первый подопечный использует базовый коэффициент, второй — множитель 1,5, каждый следующий — дополнительный множитель 1,15. Сайт добавляет строки дополнительных котят динамически; VK поддерживает сегмент доп. котята: Имя [ID], Имя2 [ID].