From 468591c84cf00d1e6d9c947e68d0ddb8c28be3cf Mon Sep 17 00:00:00 2001 From: Nyan404 Date: Tue, 25 Aug 2026 12:25:28 +0300 Subject: [PATCH] fix: enforce amd64 container deployment --- .gitlab-ci.yml | 6 ++++-- AGENTS.md | 1 + Dockerfile | 14 +++++++++++++- Dockerfile.base | 2 +- Dockerfile.gateway | 2 +- MEMORY.md | 3 +++ deploy/k8s/app.yaml | 4 ++++ deploy/k8s/gateway.yaml | 2 ++ deploy/k8s/production.yaml | 6 ++++++ structure_and_data.md | 1 + 10 files changed, 36 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5d25674..eb9abd4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,6 +11,8 @@ variables: DOCKER_BUILDKIT: "1" DOCKER_TLS_CERTDIR: "" DOCKER_DRIVER: overlay2 + # The registry images and production Kubernetes nodes are amd64-only. + DOCKER_DEFAULT_PLATFORM: linux/amd64 # The runner fetches the repository before any job script runs. Retry transient # GitLab connectivity failures at that stage instead of failing the pipeline. GET_SOURCES_ATTEMPTS: "3" @@ -54,8 +56,8 @@ build: - echo "$DOCKER_PASSWORD" | docker login $DOCKER_REGISTRY -u "$DOCKER_USERNAME" --password-stdin - export IMAGE_TAG="$CI_COMMIT_SHORT_SHA" - - 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 build --platform linux/amd64 --pull -t "$DOCKER_IMAGE_REPOSITORY:$IMAGE_TAG" -t "$DOCKER_IMAGE_REPOSITORY:latest" . + - docker build --platform linux/amd64 --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:latest" - docker push "$GATEWAY_IMAGE_REPOSITORY:$IMAGE_TAG" diff --git a/AGENTS.md b/AGENTS.md index cae06a4..e9877ea 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -9,6 +9,7 @@ - Keep VK tokens and group IDs out of the repository; use environment variables or Kubernetes Secrets. - Production manifests are already applied in namespace `belki`; CI deploys them from `main` using the namespace-scoped RBAC in [`deploy/k8s/rbac.yaml`](./deploy/k8s/rbac.yaml). - The production build uses the GitLab runner tag `fast`, a privileged Docker executor, and an explicit `docker:29.6.1-dind` service alias over TCP. +- Production images and Kubernetes workloads are amd64-only. Preserve `linux/amd64` in Dockerfiles, CI build commands, and workload node selectors; do not reintroduce the arm64-only Python base tag. - When adding, removing, or updating a runtime dependency, rebuild and push the matching immutable base image to `reg.nyan404.ru`, then update its tag in the final Dockerfile before running CI. `requirements.txt` maps to `Dockerfile.base`; `nginx.conf` maps to `Dockerfile.gateway-base`. - Use Context7 for current official documentation when implementing or changing an external API, framework, or library integration. - Before adding or updating any dependency, use `prevent-eol` to check lifecycle support; do not treat its results as a vulnerability assessment. diff --git a/Dockerfile b/Dockerfile index c7fd18f..0c68209 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,16 @@ -FROM reg.nyan404.ru/cwshed-clone/belki-base:py312-d6c42c4497ce +# Production is deployed to amd64 nodes. Build dependencies from the official +# base here because the previous private tag was published arm64-only. +FROM --platform=linux/amd64 python:3.12-slim + +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + LANG=C.UTF-8 \ + LC_ALL=C.UTF-8 + +WORKDIR /app +COPY requirements.txt ./requirements.txt +RUN python -m pip install --no-cache-dir --upgrade "pip==26.2.1" \ + && python -m pip install --no-cache-dir -r requirements.txt COPY app ./app COPY web ./web diff --git a/Dockerfile.base b/Dockerfile.base index 39cfe7b..4f76b8d 100644 --- a/Dockerfile.base +++ b/Dockerfile.base @@ -1,4 +1,4 @@ -FROM python:3.12-slim +FROM --platform=linux/amd64 python:3.12-slim ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ diff --git a/Dockerfile.gateway b/Dockerfile.gateway index e1523e8..34b32d7 100644 --- a/Dockerfile.gateway +++ b/Dockerfile.gateway @@ -1,4 +1,4 @@ -FROM reg.nyan404.ru/cwshed/cwshed-base:nginx-c2431df29ccc +FROM --platform=linux/amd64 reg.nyan404.ru/cwshed/cwshed-base:nginx-c2431df29ccc COPY web /usr/share/nginx/html diff --git a/MEMORY.md b/MEMORY.md index 0c98d6c..d15ed83 100644 --- a/MEMORY.md +++ b/MEMORY.md @@ -56,3 +56,6 @@ # 2026-08-16 — несколько котят в прокачке `CoachingSession.extra_kittens` теперь влияет на баллы сопровождающего через количество подопечных: 1-й ×1, 2-й ×1,5, каждый последующий ×1,15 (коэффициенты перемножаются), вместо сложения полной прибыли. Базовый коэффициент самостоятельности основного котёнка сохраняется. Веб-форма отправляет список `extra_kittens`; VK принимает `доп. котята: ...` в pipe-команде. +# 2026-08-25: production container architecture + +Production Belki images and Kubernetes workloads require `linux/amd64`. CI sets `DOCKER_DEFAULT_PLATFORM` and passes `--platform linux/amd64`; Dockerfiles and workload node selectors carry the same constraint. The previous private Python base tag `py312-d6c42c4497ce` was published only for arm64 and must not be used for the application image. diff --git a/deploy/k8s/app.yaml b/deploy/k8s/app.yaml index 4ec7e2c..134e08a 100644 --- a/deploy/k8s/app.yaml +++ b/deploy/k8s/app.yaml @@ -17,6 +17,8 @@ spec: app.kubernetes.io/name: belki-web app.kubernetes.io/part-of: belki-calculator spec: + nodeSelector: + kubernetes.io/arch: amd64 containers: - name: web image: reg.nyan404.ru/cwshed-clone/belki:latest @@ -91,6 +93,8 @@ spec: app.kubernetes.io/name: belki-bot app.kubernetes.io/part-of: belki-calculator spec: + nodeSelector: + kubernetes.io/arch: amd64 containers: - name: bot image: reg.nyan404.ru/cwshed-clone/belki:latest diff --git a/deploy/k8s/gateway.yaml b/deploy/k8s/gateway.yaml index 7e6b19c..6fd2018 100644 --- a/deploy/k8s/gateway.yaml +++ b/deploy/k8s/gateway.yaml @@ -17,6 +17,8 @@ spec: app.kubernetes.io/name: cwshed app.kubernetes.io/part-of: belki-calculator spec: + nodeSelector: + kubernetes.io/arch: amd64 imagePullSecrets: - name: reg-nyan404 containers: diff --git a/deploy/k8s/production.yaml b/deploy/k8s/production.yaml index f0721bf..1788fc8 100644 --- a/deploy/k8s/production.yaml +++ b/deploy/k8s/production.yaml @@ -29,6 +29,8 @@ spec: app.kubernetes.io/name: belki-postgres app.kubernetes.io/part-of: belki-calculator spec: + nodeSelector: + kubernetes.io/arch: amd64 imagePullSecrets: - name: reg-nyan404 containers: @@ -96,6 +98,8 @@ spec: app.kubernetes.io/name: belki-web app.kubernetes.io/part-of: belki-calculator spec: + nodeSelector: + kubernetes.io/arch: amd64 imagePullSecrets: - name: reg-nyan404 containers: @@ -170,6 +174,8 @@ spec: app.kubernetes.io/name: belki-bot app.kubernetes.io/part-of: belki-calculator spec: + nodeSelector: + kubernetes.io/arch: amd64 imagePullSecrets: - name: reg-nyan404 containers: diff --git a/structure_and_data.md b/structure_and_data.md index 7933727..c26cc5a 100644 --- a/structure_and_data.md +++ b/structure_and_data.md @@ -16,6 +16,7 @@ ## Runtime / Deployment - GitLab CI runs the build job. +- Production container architecture is explicitly `linux/amd64`: CI sets `DOCKER_DEFAULT_PLATFORM` and passes `--platform linux/amd64`, Dockerfiles pin the platform, and Kubernetes workloads select nodes labeled `kubernetes.io/arch: amd64`. The former private Python base tag was arm64-only and is no longer used by the application image. - The job targets GitLab runner tag `fast` and builds through a privileged `docker:29.6.1-dind` service at `DOCKER_HOST=tcp://docker:2375`, with an explicit `alias: docker` and `DOCKER_TLS_CERTDIR=""`. - Runtime dependency layers are prebuilt and stored in the private registry: `reg.nyan404.ru/cwshed-clone/belki-base:py312-d6c42c4497ce` contains Python 3.12, `pip 26.2.1`, and the current `requirements.txt`; `reg.nyan404.ru/cwshed/cwshed-base:nginx-c2431df29ccc` contains Nginx plus `nginx.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-dind` service on `root@10.3.1.168` has a valid Runner registration and its helper container can reach `https://git.nyan404.ru/`. On 2026-08-21 its malformed `DOCKER_AUTH_CONFIG` was removed and the pre-change configuration was backed up on the host as `/etc/gitlab-runner/config.toml.bak-20260821-1334`.