feat: unify cwshed gateway with Belki pipeline

This commit is contained in:
nyan404 committed 2026-08-16 17:23:53 +03:00
1 parent 3abc291795
commit 6656484e4b
6 files changed
+83 -5

No files matched your search

+6
View File
@@ -4,6 +4,7 @@ stages:
variables: variables:
DOCKER_IMAGE_REPOSITORY: $DOCKER_REGISTRY/cwshed-clone/belki DOCKER_IMAGE_REPOSITORY: $DOCKER_REGISTRY/cwshed-clone/belki
GATEWAY_IMAGE_REPOSITORY: $DOCKER_REGISTRY/cwshed
KUBE_NAMESPACE: belki KUBE_NAMESPACE: belki
DOCKER_HOST: tcp://docker:2375 DOCKER_HOST: tcp://docker:2375
build: build:
@@ -22,8 +23,11 @@ build:
- export IMAGE_TAG="$CI_COMMIT_SHORT_SHA" - export IMAGE_TAG="$CI_COMMIT_SHORT_SHA"
- docker build --pull -t "$DOCKER_IMAGE_REPOSITORY:$IMAGE_TAG" -t "$DOCKER_IMAGE_REPOSITORY:latest" . - docker build --pull -t "$DOCKER_IMAGE_REPOSITORY:$IMAGE_TAG" -t "$DOCKER_IMAGE_REPOSITORY:latest" .
- docker build --pull -f Dockerfile.gateway -t "$GATEWAY_IMAGE_REPOSITORY:$IMAGE_TAG" -t "$GATEWAY_IMAGE_REPOSITORY:latest" .
- docker push "$DOCKER_IMAGE_REPOSITORY:$IMAGE_TAG" - docker push "$DOCKER_IMAGE_REPOSITORY:$IMAGE_TAG"
- docker push "$DOCKER_IMAGE_REPOSITORY:latest" - docker push "$DOCKER_IMAGE_REPOSITORY:latest"
- docker push "$GATEWAY_IMAGE_REPOSITORY:$IMAGE_TAG"
- docker push "$GATEWAY_IMAGE_REPOSITORY:latest"
rules: rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
@@ -55,9 +59,11 @@ deploy:
--from-literal=BELKI_ADMIN_PASSWORD="$BELKI_ADMIN_PASSWORD" --from-literal=BELKI_ADMIN_PASSWORD="$BELKI_ADMIN_PASSWORD"
--dry-run=client -o yaml | kubectl apply -f - --dry-run=client -o yaml | kubectl apply -f -
- sed "s#reg.nyan404.ru/cwshed-clone/belki:6b74dfa#$DOCKER_IMAGE_REPOSITORY:$CI_COMMIT_SHORT_SHA#g" deploy/k8s/production.yaml | kubectl apply -f - - sed "s#reg.nyan404.ru/cwshed-clone/belki:6b74dfa#$DOCKER_IMAGE_REPOSITORY:$CI_COMMIT_SHORT_SHA#g" deploy/k8s/production.yaml | kubectl apply -f -
- sed "s#reg.nyan404.ru/cwshed:6b74dfa#$GATEWAY_IMAGE_REPOSITORY:$CI_COMMIT_SHORT_SHA#g" deploy/k8s/gateway.yaml | kubectl apply -f -
- kubectl -n "$KUBE_NAMESPACE" rollout status deployment/belki-postgres --timeout=180s - kubectl -n "$KUBE_NAMESPACE" rollout status deployment/belki-postgres --timeout=180s
- kubectl -n "$KUBE_NAMESPACE" rollout status deployment/belki-web --timeout=180s - kubectl -n "$KUBE_NAMESPACE" rollout status deployment/belki-web --timeout=180s
- kubectl -n "$KUBE_NAMESPACE" rollout status deployment/belki-bot --timeout=180s - kubectl -n "$KUBE_NAMESPACE" rollout status deployment/belki-bot --timeout=180s
- kubectl -n "$KUBE_NAMESPACE" rollout status deployment/cwshed --timeout=180s
- kubectl -n "$KUBE_NAMESPACE" get pods,svc - kubectl -n "$KUBE_NAMESPACE" get pods,svc
after_script: after_script:
- rm -rf "$CI_PROJECT_DIR/.kube" - rm -rf "$CI_PROJECT_DIR/.kube"
+13
View File
@@ -0,0 +1,13 @@
FROM nginx:alpine
ENV LANG=C.UTF-8 \
LC_ALL=C.UTF-8
COPY web /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
RUN chmod -R 755 /usr/share/nginx/html \
&& chown -R nginx:nginx /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
+1 -1
View File
@@ -19,5 +19,5 @@
- Confirmed calculations are persisted through `BELKI_DATABASE_URL` by `app/belki/history.py`; PostgreSQL is the intended production store and SQLite is only a local fallback. - Confirmed calculations are persisted through `BELKI_DATABASE_URL` by `app/belki/history.py`; PostgreSQL is the intended production store and SQLite is only a local fallback.
- The admin history is served at `/admin`; `/api/admin/calculations` requires `BELKI_ADMIN_PASSWORD` via `X-Admin-Password` and supports sorting by kitten ID/name. The password is configured out-of-band and is not stored in browser localStorage. - The admin history is served at `/admin`; `/api/admin/calculations` requires `BELKI_ADMIN_PASSWORD` via `X-Admin-Password` and supports sorting by kitten ID/name. The password is configured out-of-band and is not stored in browser localStorage.
- The new domain uses 5 minutes = 1 adult point and 5 minutes = 2 kitten points; a non-self-sufficient main kitten gives the adult a 1.5x multiplier and each additional non-self-sufficient kitten adds 0.5x, matching the inspected Google Sheet formulas. - The new domain uses 5 minutes = 1 adult point and 5 minutes = 2 kitten points; a non-self-sufficient main kitten gives the adult a 1.5x multiplier and each additional non-self-sufficient kitten adds 0.5x, matching the inspected Google Sheet formulas.
- 2026-08-16 production deployment: namespace `belki` is live in k3s. Web and bot use `reg.nyan404.ru/cwshed-clone/belki:6b74dfa`; PostgreSQL uses the amd64 mirror `reg.nyan404.ru/library/postgres:16-alpine-amd64` on Longhorn. The web LoadBalancer is MetalLB `10.12.0.212`; the legacy cwshed Nginx gateway is intended to route `/belki`, `/admin`, and `/api/*` there. Runtime credentials remain only in the cluster Secret `belki-runtime`. - 2026-08-16 production deployment: namespace `belki` is live in k3s. Web and bot use `reg.nyan404.ru/cwshed-clone/belki:6b74dfa`; the migrated cwshed Nginx gateway keeps MetalLB `10.12.0.204` and routes `/belki`, `/admin`, and `/api/*` to web `10.12.0.212`; PostgreSQL uses the amd64 mirror `reg.nyan404.ru/library/postgres:16-alpine-amd64` on Longhorn. Runtime credentials remain only in the cluster Secret `belki-runtime`.
- GitLab CI/CD now builds SHA/latest tags and deploys `deploy/k8s/production.yaml` from `main`. The ignored `.gitlab.variables.env` is a local handoff for GitLab Variables; CI uses namespace-scoped ServiceAccount `belki/gitlab-deploy`, not cluster-admin credentials. - GitLab CI/CD now builds SHA/latest tags and deploys `deploy/k8s/production.yaml` from `main`. The ignored `.gitlab.variables.env` is a local handoff for GitLab Variables; CI uses namespace-scoped ServiceAccount `belki/gitlab-deploy`, not cluster-admin credentials.
+58
View File
@@ -0,0 +1,58 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: cwshed
namespace: belki
labels:
app.kubernetes.io/name: cwshed
app.kubernetes.io/part-of: belki-calculator
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: cwshed
template:
metadata:
labels:
app.kubernetes.io/name: cwshed
app.kubernetes.io/part-of: belki-calculator
spec:
imagePullSecrets:
- name: reg-nyan404
containers:
- name: cwshed
image: reg.nyan404.ru/cwshed:6b74dfa
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
readinessProbe:
httpGet:
path: /
port: http
initialDelaySeconds: 3
periodSeconds: 10
livenessProbe:
httpGet:
path: /
port: http
initialDelaySeconds: 10
periodSeconds: 20
---
apiVersion: v1
kind: Service
metadata:
name: cwshed
namespace: belki
labels:
app.kubernetes.io/part-of: belki-calculator
spec:
type: LoadBalancer
loadBalancerIP: 10.12.0.204
selector:
app.kubernetes.io/name: cwshed
ports:
- name: http
port: 8998
protocol: TCP
targetPort: http
+4 -3
View File
@@ -2,8 +2,8 @@
`.gitlab-ci.yml` выполняет два шага на `main`: `.gitlab-ci.yml` выполняет два шага на `main`:
1. Собирает образ и публикует его в `reg.nyan404.ru/cwshed-clone/belki` с тегами короткого SHA и `latest`. 1. Собирает и публикует Belki-образ в `reg.nyan404.ru/cwshed-clone/belki` и Nginx-шлюз в `reg.nyan404.ru/cwshed` с тегами короткого SHA и `latest`.
2. Подключается к k3s namespace `belki`, обновляет runtime Secret, применяет `deploy/k8s/production.yaml` и ждёт готовности web, bot и PostgreSQL. 2. Подключается к k3s namespace `belki`, обновляет runtime Secret, применяет `deploy/k8s/production.yaml` и `deploy/k8s/gateway.yaml`, затем ждёт готовности web, bot, PostgreSQL и шлюза.
## Переменные GitLab ## Переменные GitLab
@@ -17,6 +17,7 @@
| `DOCKER_USERNAME` | пользователь registry | masked, protected | | `DOCKER_USERNAME` | пользователь registry | masked, protected |
| `DOCKER_PASSWORD` | пароль registry | masked, protected | | `DOCKER_PASSWORD` | пароль registry | masked, protected |
| `DOCKER_IMAGE_REPOSITORY` | `reg.nyan404.ru/cwshed-clone/belki` | protected | | `DOCKER_IMAGE_REPOSITORY` | `reg.nyan404.ru/cwshed-clone/belki` | protected |
| `GATEWAY_IMAGE_REPOSITORY` | `reg.nyan404.ru/cwshed` | protected |
| `KUBE_NAMESPACE` | `belki` | protected | | `KUBE_NAMESPACE` | `belki` | protected |
| `KUBE_CONFIG_B64` | base64 kubeconfig для ServiceAccount `gitlab-deploy` | masked, protected | | `KUBE_CONFIG_B64` | base64 kubeconfig для ServiceAccount `gitlab-deploy` | masked, protected |
| `VK_GROUP_TOKEN` | токен VK-группы | masked, protected | | `VK_GROUP_TOKEN` | токен VK-группы | masked, protected |
@@ -41,4 +42,4 @@ kubectl -n belki apply -f deploy/k8s/production.yaml
kubectl -n belki rollout status deployment/belki-web --timeout=180s kubectl -n belki rollout status deployment/belki-web --timeout=180s
``` ```
MetalLB адрес web-сервиса — `10.12.0.212`; внешний Nginx проксирует на него путь `cat.nyan404.ru/belki`. MetalLB адрес шлюза — `10.12.0.204`; он раздаёт старый CatWar-сайт и проксирует `/belki`, `/admin` и `/api/*` на Belki web `10.12.0.212`.
+1 -1
View File
@@ -29,7 +29,7 @@
- VK photo attachments received during an active dialog are normalized into `input.attachments` and persisted with the calculation; `/admin` renders their thumbnails. With `BELKI_IMAGE_HOST_API_URL`, the bot mirrors each photo through image-hosting-web and stores `mirror_url`; Google Sheets export remains deferred. - VK photo attachments received during an active dialog are normalized into `input.attachments` and persisted with the calculation; `/admin` renders their thumbnails. With `BELKI_IMAGE_HOST_API_URL`, the bot mirrors each photo through image-hosting-web and stores `mirror_url`; Google Sheets export remains deferred.
- `/admin` and `/api/admin/calculations` expose the calculation history for review. The API requires `X-Admin-Password` matching `BELKI_ADMIN_PASSWORD`; the web page supports sorting by kitten ID or name and does not persist the password in browser storage. - `/admin` and `/api/admin/calculations` expose the calculation history for review. The API requires `X-Admin-Password` matching `BELKI_ADMIN_PASSWORD`; the web page supports sorting by kitten ID or name and does not persist the password in browser storage.
- VK `messages.send` responses include a serialized context-aware keyboard; button payloads are translated back into the same dialog commands, while text commands remain supported. - VK `messages.send` responses 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 `belki` runs the web calculator, VK bot, and PostgreSQL 16 on a Longhorn 2 GiB PVC. The web LoadBalancer has MetalLB IP `10.12.0.212`; the legacy cwshed Nginx gateway routes `/belki`, `/admin`, and `/api/*` to this address. The image is `reg.nyan404.ru/cwshed-clone/belki:6b74dfa` (pushed as `latest` too). PostgreSQL is mirrored as `reg.nyan404.ru/library/postgres:16-alpine-amd64` because cluster nodes cannot pull Docker Hub directly. Registry pull credentials and runtime secrets are created out-of-band in the `belki` namespace. - Production k3s deployment (2026-08-16): namespace `belki` runs the Belki web calculator, VK bot, PostgreSQL 16, and the migrated cwshed Nginx gateway. The gateway keeps MetalLB IP `10.12.0.204`, serves the legacy CatWar site, and routes `/belki`, `/admin`, and `/api/*` to Belki web on `10.12.0.212`. Belki images are `reg.nyan404.ru/cwshed-clone/belki` and `reg.nyan404.ru/cwshed`; PostgreSQL is mirrored as `reg.nyan404.ru/library/postgres:16-alpine-amd64` because cluster nodes cannot pull Docker Hub directly. Registry pull credentials and runtime secrets are created out-of-band in the `belki` namespace.
- Remote runner host: `root@10.3.1.236` (`docker-03.homelab.local`), GitLab Runner `stage-zone-runner`, Docker executor, privileged, with `docker:29.6.1-dind` as the service image. - Remote runner host: `root@10.3.1.236` (`docker-03.homelab.local`), GitLab Runner `stage-zone-runner`, Docker executor, privileged, with `docker:29.6.1-dind` as the service image.
- 2026-08-16 `prevent-eol` check: `python:3.12-slim` is currently maintained through 2028-10-31; Docker `29.6.1-cli` was `unknown` to the EOL catalog (no finding). Docker/CI references remain tag-pinned rather than digest-pinned. - 2026-08-16 `prevent-eol` check: `python:3.12-slim` is currently maintained through 2028-10-31; Docker `29.6.1-cli` was `unknown` to the EOL catalog (no finding). Docker/CI references remain tag-pinned rather than digest-pinned.