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:
1 parent
fc13c66b0d
commit
ae812b0dfa
6 files changed
+63
-43
No files matched your search
@@ -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 }}"
|
||||
|
||||
Reference in new issue
Block a user