Drop the container pipeline: the servers run the flake

asxpio-services runs the app from this flake (services.datacenterbingo)
and the container is gone. The Dockerfile, .dockerignore,
docker-compose.yml and the Kaniko and deploy jobs go; CI runs the tests
and builds the package on every push, main included. Settings and
secrets now live in iac, so the deploy and registry secrets here are
unused. Also drops b/asxpio-invoices/bingo/evil.jpg, a stray file nothing
references.

Assisted-by: Claude:opus-5-5
This commit is contained in:
Sergei Poljanski 2026-11-17 13:56:37 +04:00
commit 368ef60836
Signed by: asxpi
GPG key ID: 4F8851660FA4121B
7 changed files with 16 additions and 286 deletions

View file

@ -1,15 +0,0 @@
.env
.gems
.bundle
vendor/bundle
*.log
tmp
flake.nix
flake.lock
CLAUDE.md
README.md
test
Rakefile
bin
.forgejo
.git

View file

@ -0,0 +1,70 @@
name: Tests
# main is covered by the test job inside deploy.yaml (which gates the build);
# this workflow covers every other branch.
on:
push:
branches-ignore:
- main
jobs:
test:
runs-on: nix-latest
# Settings via env, not /etc/nix/nix.conf: in the image that is a
# symlink into /nix/store, which the runner's nix-store volume
# shadows, so it dangles once the image moves on.
env:
NIX_CONFIG: |
experimental-features = nix-command flakes
build-users-group =
sandbox = false
services:
# CI stand-in for bin/test's ephemeral Postgres: the nix container runs
# as root and initdb refuses to run as root, so the DB lives in a
# service container instead and the suite connects via TEST_DATABASE_URL.
# Job and service share the per-workflow bridge network (the runner's
# container.network must stay "" — with "host" the service network is
# never created and services fail to start).
postgres:
image: postgres:18.7-alpine
env:
POSTGRES_USER: postgres
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_DB: bingo_test
steps:
- name: Prepare container for actions
run: |
# node for JS actions (checkout); git-minimal is already in the image
nix-env -iA nixpkgs.nodejs_22
- name: Checkout
uses: actions/checkout@v7.0.1
# The nix closure persists in the runner's nix-store volume; gems live
# in the workspace (.gems via the flake's BUNDLE_PATH), so cache those.
- name: Cache gems
uses: actions/cache@v6.1.0
with:
path: .gems
key: gems-${{ hashFiles('Gemfile.lock') }}
- name: Wait for Postgres
run: |
for i in $(seq 1 30); do
nix develop -c pg_isready -h postgres -U postgres && exit 0
sleep 2
done
echo "Postgres service never became ready" >&2
exit 1
- name: Run test suite
env:
TEST_DATABASE_URL: postgres://postgres@postgres:5432/bingo_test
run: nix develop -c bundle exec rake test
# What the servers run: gemset.nix in step with Gemfile.lock, and
# the package builds
- name: Package
run: |
nix develop -c ruby bin/check-gemset
nix build .#default

View file

@ -1,188 +0,0 @@
name: Build and Deploy to Production
on:
push:
branches:
- main
jobs:
# Same job as in test.yaml (which covers non-main branches); duplicated here
# so a red suite blocks the build+deploy — Forgejo has no cross-workflow needs.
test:
runs-on: nix-latest
# Settings via env, not /etc/nix/nix.conf: in the image that is a
# symlink into /nix/store, which the runner's nix-store volume
# shadows, so it dangles once the image moves on.
env:
NIX_CONFIG: |
experimental-features = nix-command flakes
build-users-group =
sandbox = false
services:
postgres:
image: postgres:18.7-alpine
env:
POSTGRES_USER: postgres
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_DB: bingo_test
steps:
- name: Prepare container for actions
run: |
# node for JS actions (checkout); git-minimal is already in the image
nix-env -iA nixpkgs.nodejs_22
- name: Checkout
uses: actions/checkout@v7.0.1
- name: Cache gems
uses: actions/cache@v6.1.0
with:
path: .gems
key: gems-${{ hashFiles('Gemfile.lock') }}
- name: Wait for Postgres
run: |
for i in $(seq 1 30); do
nix develop -c pg_isready -h postgres -U postgres && exit 0
sleep 2
done
echo "Postgres service never became ready" >&2
exit 1
- name: Run test suite
env:
TEST_DATABASE_URL: postgres://postgres@postgres:5432/bingo_test
run: nix develop -c bundle exec rake test
# What the servers run: gemset.nix in step with Gemfile.lock, and
# the package builds
- name: Package
run: |
nix develop -c ruby bin/check-gemset
nix build .#default
build:
runs-on: arch-latest
needs: test
container:
image: gcr.io/kaniko-project/executor:v1.24.0-debug
outputs:
image_tag: ${{ steps.build_image.outputs.image_tag }}
steps:
- name: Build and push Docker Image using Kaniko
id: build_image
run: |
# Tags
SHORT_SHA=${GITHUB_SHA::8}
IMAGE_BASE=${{ secrets.FJ_REGISTRY }}/${{ secrets.FJ_USER }}/datacenterbingo
IMAGE_TAG=${IMAGE_BASE}:${SHORT_SHA}
IMAGE_LATEST=${IMAGE_BASE}:latest
# Auth Conf
mkdir -p /kaniko/.docker
echo "{\"auths\":{\"${{ secrets.FJ_REGISTRY }}\":{\"auth\":\"$(echo -n ${{ secrets.FJ_USER }}:${{ secrets.FJ_TOKEN }} | base64)\"}}}" > /kaniko/.docker/config.json
# Build & push
/kaniko/executor \
--context=git://${{ secrets.FJ_REGISTRY }}/${{ github.repository }}.git \
--git=branch=${{ github.ref_name }} \
--destination=$IMAGE_TAG \
--destination=$IMAGE_LATEST
# Output the specific tag for deployment
echo "image_tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT
deploy:
runs-on: arch-latest
needs: build
steps:
- name: Install dependencies
run: |
pacman -Syu --noconfirm nodejs openssh rsync
- name: Checkout code
uses: actions/checkout@v7.0.1
- name: Deploy docker-compose.yml
uses: easingthemes/ssh-deploy@v6.0.3
with:
SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
REMOTE_HOST: ${{ secrets.DEPLOY_IP }}
REMOTE_USER: ${{ secrets.DEPLOY_USER }}
SOURCE: "docker-compose.yml"
TARGET: "/opt/datacenterbingo/"
# Read-only DB role and S3 key (see CLAUDE.md); the asxp.io admin
# owns writes. BINGO_HOST also feeds the Traefik rule via compose.
- name: Deploy .env from secrets
uses: appleboy/ssh-action@v1.2.5
env:
BINGO_DB_PASSWORD: ${{ secrets.BINGO_DB_PASSWORD }}
BINGO_S3_ACCESS_KEY: ${{ secrets.BINGO_S3_ACCESS_KEY }}
BINGO_S3_SECRET_KEY: ${{ secrets.BINGO_S3_SECRET_KEY }}
INDEXNOW: ${{ secrets.INDEXNOW }}
with:
host: ${{ secrets.DEPLOY_IP }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
envs: BINGO_DB_PASSWORD,BINGO_S3_ACCESS_KEY,BINGO_S3_SECRET_KEY,INDEXNOW
script_stop: true
script: |
umask 077
mkdir -p /opt/datacenterbingo
# Garage only takes its own key format (id: GK + 24 hex digits,
# secret: 64 hex digits). Hash the MinIO-era secrets into it, as
# storage's init/garage-bootstrap.sh does; a pair already in
# Garage's format is used as it is.
garage_key_id() {
if printf '%s' "$1" | grep -Eq '^GK[0-9a-f]{24}$'; then printf '%s' "$1"
else printf 'GK%s' "$(printf '%s' "$1" | sha256sum | cut -c1-24)"; fi
}
garage_secret() {
if printf '%s' "$1" | grep -Eq '^[0-9a-f]{64}$'; then printf '%s' "$1"
else printf '%s' "$1" | sha256sum | cut -c1-64; fi
}
S3_ACCESS_KEY="$(garage_key_id "${BINGO_S3_ACCESS_KEY}")"
S3_SECRET_KEY="$(garage_secret "${BINGO_S3_SECRET_KEY}")"
cat > /opt/datacenterbingo/.env <<EOF
RACK_ENV=production
BINGO_HOST=datacenterbingo.xyz
DATABASE_URL=postgres://bingo:${BINGO_DB_PASSWORD}@postgres:5432/asxpio
S3_ENDPOINT=http://garage:3900
S3_REGION=us-east-1
S3_BUCKET=datacenterbingo-photos
S3_ACCESS_KEY=${S3_ACCESS_KEY}
S3_SECRET_KEY=${S3_SECRET_KEY}
INDEXNOW_KEY=${INDEXNOW}
EOF
chmod 600 /opt/datacenterbingo/.env
- name: Deploy and update container
uses: appleboy/ssh-action@v1.2.5
env:
NEW_IMAGE: ${{ needs.build.outputs.image_tag }}
with:
host: ${{ secrets.DEPLOY_IP }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
envs: NEW_IMAGE
script: |
cd /opt/datacenterbingo
sed -i "s|image:.*|image: $NEW_IMAGE|" docker-compose.yml
docker pull $NEW_IMAGE
docker compose up -d
for i in $(seq 1 18); do
status=$(docker inspect --format '{{.State.Health.Status}}' datacenterbingo 2>/dev/null || echo missing)
if [ "$status" = "healthy" ]; then
echo "Deployment successful!"
exit 0
fi
sleep 5
done
echo "datacenterbingo never became healthy (last status: $status)" >&2
docker logs --tail 50 datacenterbingo
exit 1

View file

@ -71,19 +71,21 @@ loads `test/schema.sql`. Run `cp .env.example .env` for a local server
## Deploy
On push to `main`, `.forgejo/workflows/deploy.yaml` tests, builds with kaniko
to `$FJ_REGISTRY/$FJ_USER/datacenterbingo`, then over SSH writes
`/opt/datacenterbingo/{docker-compose.yml,.env}` and runs
`docker compose up -d`. The container is on the `traefik` and `storage`
networks, and the Traefik router `datacenterbingo` takes `BINGO_HOST` and
`www.`.
`flake.nix` builds the app (`packages.default`: bundlerEnv from
`Gemfile.lock` and `gemset.nix`) and runs it (`nixosModules.default`,
`services.datacenterbingo`: Puma as a hardened systemd service) on
asxpio-services; Traefik on asxpio-ops routes `datacenterbingo.xyz` and
`www.` there. A push to `main` is picked up by Renovate in asxpi/iac (flake
input `datacenterbingo`) within about 15 minutes and deployed by comin; CI
here only tests (`.forgejo/workflows/ci.yaml`: tests, `bin/check-gemset`,
the package build).
Secrets:
After changing `Gemfile.lock`: `nix run nixpkgs#bundix` to refresh
`gemset.nix` (CI fails until they match). Puma starts through the
bundlerEnv's binstub with `BUNDLE_FORCE_RUBY_PLATFORM` (the lock lists
precompiled gems for other platforms; Nix builds the source gems).
| Secret | Purpose |
|---|---|
| `FJ_REGISTRY`, `FJ_USER`, `FJ_TOKEN` | kaniko clone + push (`write:package`, `read:repository`); Forgejo reserves the `FORGEJO_` prefix |
| `DEPLOY_IP`, `DEPLOY_USER`, `DEPLOY_SSH_KEY` | SSH to prod |
| `BINGO_DB_PASSWORD` | read-only Postgres role `bingo` |
| `BINGO_S3_ACCESS_KEY`, `BINGO_S3_SECRET_KEY` | read-only S3 key; the deploy hashes it into Garage's key format, as storage does |
| `INDEXNOW` | same key as asxpio's `INDEXNOW` (served here, pinged from there) |
Settings and secrets live in iac (`nixos/hosts/asxpio-services/apps.nix`,
sops key `datacenterbingo/env`: `DATABASE_URL` for the read-only role
`bingo`, the read-only S3 key in Garage's format, `INDEXNOW_KEY`, the same
key as asxpio's). This repository holds no deploy secrets.

View file

@ -1,33 +0,0 @@
FROM ruby:4.0.9-slim-bookworm
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
RUN groupadd -g 11000 bingo \
&& useradd -d /app -u 21000 -g 11000 -m -s /bin/bash bingo
WORKDIR /app
USER bingo
ENV GEM_HOME=/app/bundle
ENV PATH="${GEM_HOME}/bin:${PATH}"
COPY --chown=bingo Gemfile Gemfile.lock* ./
ENV BUNDLE_FROZEN=true
ENV BUNDLE_WITHOUT=development:test
RUN bundle install
COPY --chown=bingo . .
ENV PUMA_PORT=3000
ENV PUMA_THREADS="4:16"
ENV RACK_ENV=production
EXPOSE 3000
# Slim image has no curl; ruby is right there.
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
CMD ruby -rnet/http -e 'port = ENV.fetch("PUMA_PORT", "3000"); exit(Net::HTTP.get_response(URI("http://127.0.0.1:#{port}/healthz")).code == "200" ? 0 : 1)'
CMD ["sh", "-c", "exec bundle exec puma -b tcp://0.0.0.0:${PUMA_PORT} -t ${PUMA_THREADS} --preload"]

View file

@ -1 +0,0 @@
img

View file

@ -1,35 +0,0 @@
services:
bingo:
# Image is set by the deploy workflow (registry/user/datacenterbingo:sha).
build: .
image: datacenterbingo:latest
container_name: datacenterbingo
# Same as the image HEALTHCHECK. Podman ignores HEALTHCHECK in OCI-format
# images (what kaniko pushes), and the deploy waits for "healthy".
healthcheck:
test: ["CMD-SHELL","ruby -rnet/http -e 'port = ENV.fetch(\"PUMA_PORT\", \"3000\"); exit(Net::HTTP.get_response(URI(\"http://127.0.0.1:#{port}/healthz\")).code == \"200\" ? 0 : 1)'"]
interval: 30s
timeout: 5s
start_period: 20s
retries: 3
restart: unless-stopped
env_file: .env
networks:
- traefik
- storage # postgres + garage (S3)
labels:
- "traefik.enable=true"
# Priority beats the old asxpio-bingo router while both exist.
- "traefik.http.routers.datacenterbingo.rule=Host(`${BINGO_HOST}`) || Host(`www.${BINGO_HOST}`)"
- "traefik.http.routers.datacenterbingo.priority=1000"
- "traefik.http.routers.datacenterbingo.entrypoints=websecure"
- "traefik.http.routers.datacenterbingo.tls=true"
- "traefik.http.routers.datacenterbingo.tls.certresolver=letsencrypt"
- "traefik.http.routers.datacenterbingo.service=datacenterbingo"
- "traefik.http.services.datacenterbingo.loadbalancer.server.port=3000"
networks:
traefik:
external: true
storage:
external: true