ci: отдельная база для каждого стенда

deploy-staging создаёт роль и БД ветки через staging-db-postgres до
docker compose up, cleanup.yaml удаляет их при удалении ветки (гасит
стек раньше, иначе DROP DATABASE не пройдёт). POSTGRES_* в compose
читаются из .env, куда инструмент пишет доступы.

Попутно: DEPLOY_URL стенда из env и в summary, версия сборки — ветка и
короткий sha, в проде APP_VERSION берётся из VERSION, health в Caddyfile
одной строкой.
This commit is contained in:
arswarog committed 2026-10-29 14:59:51 +03:00
1 parent fc13c66b0d
commit ae812b0dfa
6 files changed
+63 -43

No files matched your search

+14 -3
View File
@@ -44,8 +44,16 @@ jobs:
- name: Check migrations list
run: yarn ts-node tools/buildDataSource.ts --check
- name: Compute version
id: version
env:
REF_NAME: ${{ github.head_ref || github.ref_name }}
run: echo "VERSION=$REF_NAME-$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
- name: Build
run: yarn build
env:
APP_VERSION: ${{ steps.version.outputs.VERSION }}
- name: Check data-source
run: yarn ts-node tools/checkDataSource.ts
@@ -79,6 +87,8 @@ jobs:
name: Деплой на стейджинг
runs-on: ubuntu-latest
needs: build
env:
DEPLOY_URL: https://${{ github.head_ref || github.ref_name }}.jt4d.jt4d.ru.net
steps:
- name: Checkout
uses: actions/checkout@v4
@@ -113,6 +123,7 @@ jobs:
# $BRANCH — имя ветки из окружения.
sed -i "s/\${BRANCH}/$BRANCH/g" docker-compose.yml
docker compose pull --quiet
staging-db-postgres create "${{ github.repository }}" "$BRANCH"
docker compose down
docker compose up -d
@@ -121,14 +132,11 @@ jobs:
# echo "Применение миграций"
# docker compose exec -T api node_modules/.bin/typeorm migration:run -t each -d data-source.js
# Если migration:run упадёт, prune под `set -e` не выполнится —
# почистится на следующем деплое.
docker system prune -f
- name: Set deployment status
env:
BRANCH: ${{ github.head_ref || github.ref_name }}
DEPLOY_URL: http://${{ github.head_ref || github.ref_name }}.geo-platform.geo-helm.jt4d.ru.net
run: |
curl -s -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
@@ -141,6 +149,9 @@ jobs:
}' \
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/statuses/${{ github.sha }}"
- name: Write stand URL to summary
run: echo "**Стенд:** $DEPLOY_URL" >> "$GITHUB_STEP_SUMMARY"
check:
name: Проверка кода
runs-on: ubuntu-latest
+19 -6
View File
@@ -2,12 +2,22 @@ name: Cleanup
on:
delete:
pull_request:
types: [closed]
workflow_dispatch:
concurrency:
group: cleanup-${{ github.event.pull_request.head.ref || github.event.ref || github.ref_name }}
jobs:
cleanup:
name: Удаление стенда
runs-on: ubuntu-latest
if: github.event.ref_type == 'branch'
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'delete' && github.event.ref_type == 'branch') ||
(github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository)
steps:
- name: Удаление стенда
uses: appleboy/ssh-action@v1
@@ -17,22 +27,25 @@ jobs:
key: ${{ secrets.STAGING_SSH_PRIVATE_KEY }}
port: ${{ vars.STAGING_PORT }}
script: |
BRANCH_NAME="${{ github.event.ref }}"
set -e
BRANCH_NAME="${{ github.event.ref || github.event.pull_request.head.ref || github.ref_name }}"
BRANCH_NAME="${BRANCH_NAME#refs/heads/}"
DEPLOY_DIR="/home/${{ vars.STAGING_USER }}/${{ github.event.repository.name }}_${BRANCH_NAME}"
echo "Deleting stand for branch: ${BRANCH_NAME}"
echo $DEPLOY_DIR
# Стек гасим до удаления базы: DROP DATABASE не пройдёт при живом подключении api.
if [ -d "$DEPLOY_DIR" ]; then
cd "$DEPLOY_DIR"
docker compose down --rmi all || true
cd ..
rm -rf "$DEPLOY_DIR"
docker system prune -f
fi
staging-db-postgres delete "${{ github.repository }}" "$BRANCH_NAME"
cd "$HOME"
rm -rf "$DEPLOY_DIR"
docker system prune -f
- name: Удаление docker образов
run: |
BRANCH_NAME="${{ github.event.ref }}"
BRANCH_NAME="${{ github.event.ref || github.event.pull_request.head.ref || github.ref_name }}"
BRANCH_NAME="${BRANCH_NAME#refs/heads/}"
OWNER="${{ github.repository_owner }}"
REPO_NAME="${{ github.event.repository.name }}"
+1 -1
View File
@@ -63,7 +63,7 @@ jobs:
- name: Build
run: yarn build
env:
APP_VERSION: ${{ steps.version.outputs.version }}
APP_VERSION: ${{ steps.version.outputs.VERSION }}
- name: Check data-source
run: yarn ts-node tools/checkDataSource.ts