Deploy only what changed; pages notice a new version; home page: personal analyses
- CI: ci/changed-services.sh compares HEAD with the last deployment's v* tag: the Rust tests run only when a Rust service changed, only the changed images are built, and the server's .env gets a tag per built service (TAG_FRONTEND, TAG_BACKEND, ...; TAG stays the fallback), so only their containers restart. Everything when in doubt. - The frontend image knows its version (APP_VERSION, the commit): Next's deploymentId (a page from an older version reloads on navigation) and /api/version. VersionWatcher checks every 5 minutes and when the tab comes to the front: idle with nothing typed, the page reloads; otherwise a "Frissült az oldal" notice offers it. - Home page: "Nem sablonszöveg, hanem a te elemzésed" in the hero, the "Miért más?" section now about analyses written for each chart; the two hero buttons side by side on phones. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
+40
-12
@@ -2,6 +2,11 @@
|
||||
# prod: tests, image build (tags: commit hash, `prod`, `latest`), then
|
||||
# deployment to the server.
|
||||
#
|
||||
# Only what changed since the last deployment (ci/changed-services.sh): the
|
||||
# Rust tests run when a Rust service changed, only the changed images are
|
||||
# built, and only their containers restart (each service has its own tag on
|
||||
# the server: TAG_BACKEND, TAG_FRONTEND, ...; TAG is the fallback).
|
||||
#
|
||||
# Runs on the self-hosted runner in ci/runner (label `linux`), one job at a
|
||||
# time; building on main too would build every deployed commit twice. Jobs use
|
||||
# the host's Docker daemon, so image builds share its BuildKit cache.
|
||||
@@ -53,14 +58,23 @@ jobs:
|
||||
apk add --no-cache -q git musl-dev
|
||||
git init -q . && git remote add origin "${{ github.server_url }}/${{ github.repository }}.git"
|
||||
git fetch -q --depth 1 origin "${{ github.sha }}" && git checkout -q FETCH_HEAD
|
||||
git fetch -q --unshallow --tags origin
|
||||
- name: Wait for Postgres
|
||||
run: |
|
||||
for i in $(seq 30); do nc -z postgres 5432 && exit 0; sleep 1; done
|
||||
echo "postgres did not start" >&2; exit 1
|
||||
# astro-engine and horoscope-api need the Swiss Ephemeris sources and
|
||||
# data (scripts/fetch-deps.sh); their tests run locally.
|
||||
# data (scripts/fetch-deps.sh); their tests run locally. Skipped when
|
||||
# only the frontend (or nothing built) changed since the last deployment.
|
||||
- name: Test
|
||||
run: cargo test --locked -p backend -p worker -p forum -p object-storage -p db -p horoscope-client -p service-kit -p analysis-prompt -p email-templates
|
||||
run: |
|
||||
services=$(sh ci/changed-services.sh)
|
||||
echo "changed since the last deployment: ${services:-nothing}"
|
||||
case " $services " in
|
||||
*" backend "*|*" worker "*|*" forum "*|*" horoscope-api "*) ;;
|
||||
*) echo "no Rust service changed: tests skipped"; exit 0 ;;
|
||||
esac
|
||||
cargo test --locked -p backend -p worker -p forum -p object-storage -p db -p horoscope-client -p service-kit -p analysis-prompt -p email-templates
|
||||
|
||||
build:
|
||||
needs: test
|
||||
@@ -72,6 +86,7 @@ jobs:
|
||||
apk add --no-cache -q git
|
||||
git init -q . && git remote add origin "${{ github.server_url }}/${{ github.repository }}.git"
|
||||
git fetch -q --depth 1 origin "${{ github.sha }}" && git checkout -q FETCH_HEAD
|
||||
git fetch -q --unshallow --tags origin
|
||||
- name: Log in to the registry
|
||||
env:
|
||||
TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||
@@ -92,11 +107,15 @@ jobs:
|
||||
docker push -q "$image:$t"
|
||||
done
|
||||
}
|
||||
build horoscope-api -f services/horoscope-api/Dockerfile .
|
||||
build backend -f services/backend/Dockerfile .
|
||||
build worker -f services/worker/Dockerfile .
|
||||
build forum -f services/forum/Dockerfile .
|
||||
build frontend services/frontend
|
||||
services=$(sh ci/changed-services.sh)
|
||||
echo "building: ${services:-nothing}"
|
||||
for svc in $services; do
|
||||
case "$svc" in
|
||||
# The frontend knows its version (the page's new-version notice, Next's skew protection).
|
||||
frontend) build frontend --build-arg APP_VERSION="$tag" services/frontend ;;
|
||||
*) build "$svc" -f "services/$svc/Dockerfile" . ;;
|
||||
esac
|
||||
done
|
||||
# Only the last 5 commit images of each service stay in the registry,
|
||||
# plus `main`, `prod`, `latest` and the commit running in production
|
||||
# (the server pulls it by its commit tag).
|
||||
@@ -156,6 +175,7 @@ jobs:
|
||||
apk add --no-cache -q git openssh-client
|
||||
git init -q . && git remote add origin "${{ github.server_url }}/${{ github.repository }}.git"
|
||||
git fetch -q --depth 1 origin "${{ github.sha }}" && git checkout -q FETCH_HEAD
|
||||
git fetch -q --unshallow --tags origin
|
||||
- name: SSH key
|
||||
env:
|
||||
KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
@@ -164,8 +184,9 @@ jobs:
|
||||
mkdir -p ~/.ssh && chmod 700 ~/.ssh
|
||||
(umask 077 && printf '%s\n' "$KEY" > ~/.ssh/id_ed25519)
|
||||
printf '%s\n' "$KNOWN_HOSTS" > ~/.ssh/known_hosts
|
||||
# Copies the compose files, pins TAG in the server's .env and restarts
|
||||
# the changed services. The database migrations run when the backend starts.
|
||||
# Copies the compose files, pins the built services' tags (TAG_<SERVICE>)
|
||||
# in the server's .env and restarts the changed services only. The
|
||||
# database migrations run when the backend (or the forum) starts.
|
||||
- name: Deploy
|
||||
env:
|
||||
HOST: ${{ vars.DEPLOY_HOST }}
|
||||
@@ -173,9 +194,15 @@ jobs:
|
||||
run: |
|
||||
set -eu
|
||||
tag=$(echo "${{ github.sha }}" | cut -c1-12)
|
||||
services=$(sh ci/changed-services.sh)
|
||||
echo "deploying: ${services:-nothing new}"
|
||||
pin=""
|
||||
for svc in $services; do
|
||||
var="TAG_$(echo "$svc" | tr 'a-z-' 'A-Z_')"
|
||||
pin="$pin (grep -q '^$var=' .env && sed -i 's/^$var=.*/$var=$tag/' .env || echo '$var=$tag' >> .env) &&"
|
||||
done
|
||||
scp -q deploy/docker-compose.yml deploy/Caddyfile "$HOST:$DIR/"
|
||||
ssh "$HOST" "cd '$DIR' && \
|
||||
(grep -q '^TAG=' .env && sed -i 's/^TAG=.*/TAG=$tag/' .env || echo 'TAG=$tag' >> .env) && \
|
||||
ssh "$HOST" "cd '$DIR' && $pin \
|
||||
docker compose pull -q && docker compose up -d --remove-orphans --wait && \
|
||||
docker compose exec -T caddy caddy reload --config /etc/caddy/Caddyfile --adapter caddyfile && \
|
||||
docker image prune -af >/dev/null"
|
||||
@@ -188,7 +215,8 @@ jobs:
|
||||
run: |
|
||||
set -eu
|
||||
apk add --no-cache -q curl jq
|
||||
git fetch -q --unshallow --tags origin
|
||||
# The checkout above already has the whole history.
|
||||
git fetch -q --tags origin
|
||||
short=$(echo "${{ github.sha }}" | cut -c1-7)
|
||||
name="v$(date -u +%Y.%m.%d)-$short"
|
||||
if curl -fsS -o /dev/null -H "Authorization: token $TOKEN" "$API/releases/tags/$name" 2>/dev/null; then
|
||||
|
||||
Reference in New Issue
Block a user