ci: gitea workflows, prod deploy with rollback, vars guide
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
name: "Main: tests, deploy, autotests"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
java:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Setup JDK 21
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
java-version: '21'
|
||||
distribution: 'temurin'
|
||||
|
||||
- name: Cache Maven repository
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: maven-${{ hashFiles('pom.xml', 'wordpdf-core/pom.xml', 'wordpdf-app/pom.xml') }}
|
||||
restore-keys: maven-
|
||||
|
||||
- name: Setup Maven 3.9.16
|
||||
run: |
|
||||
curl -fsSL https://dlcdn.apache.org/maven/maven-3/3.9.16/binaries/apache-maven-3.9.16-bin.tar.gz | tar xz -C /opt
|
||||
echo "/opt/apache-maven-3.9.16/bin" >> "$GITHUB_PATH"
|
||||
|
||||
- name: Build and test (PMD gate included)
|
||||
run: mvn -B clean verify
|
||||
|
||||
web:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Cache npm
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.npm
|
||||
key: npm-${{ hashFiles('wordpdf-web/package-lock.json') }}
|
||||
restore-keys: npm-
|
||||
|
||||
- name: Install dependencies
|
||||
working-directory: wordpdf-web
|
||||
run: npm ci
|
||||
|
||||
- name: Build SPA
|
||||
working-directory: wordpdf-web
|
||||
run: npm run build
|
||||
|
||||
- name: Lint SPA
|
||||
working-directory: wordpdf-web
|
||||
run: npm run lint
|
||||
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [java, web]
|
||||
steps:
|
||||
- name: Save rollback state and deploy
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: 192.168.88.88
|
||||
username: root
|
||||
key: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
script_stop: true
|
||||
script: |
|
||||
set -euo pipefail
|
||||
cd /opt/wordpdf
|
||||
umask 077
|
||||
{
|
||||
echo "PREV_APP=$(podman inspect -f '{{.Image}}' wordpdf-prod-app-1)"
|
||||
echo "PREV_WEB=$(podman inspect -f '{{.Image}}' wordpdf-prod-web-1)"
|
||||
echo "PREV_COMMIT=$(git -C src rev-parse HEAD)"
|
||||
} > .rollback.env
|
||||
./restart.sh --build
|
||||
|
||||
autotests:
|
||||
runs-on: ubuntu-latest
|
||||
needs: deploy
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Setup venv
|
||||
run: |
|
||||
python3 -m venv .venv
|
||||
.venv/bin/pip install -q -r prod-autotests/requirements.txt
|
||||
|
||||
- name: Run prod autotests
|
||||
env:
|
||||
WORDPDF_BASE_URL: https://pjandro.ru/pdf-converter
|
||||
WORDPDF_MAX_PAGES: '1000'
|
||||
WORDPDF_API_KEY: ${{ secrets.WORDPDF_API_KEY }}
|
||||
run: cd prod-autotests && ../.venv/bin/python -m pytest -q .
|
||||
|
||||
rollback:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [deploy, autotests]
|
||||
if: failure()
|
||||
steps:
|
||||
- name: Roll back prod to previous images
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: 192.168.88.88
|
||||
username: root
|
||||
key: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
script_stop: true
|
||||
script: |
|
||||
set -euo pipefail
|
||||
cd /opt/wordpdf
|
||||
if [ ! -f .rollback.env ]; then
|
||||
echo "НЕТ .rollback.env — АВТОМАТИЧЕСКИЙ ОТКАТ НЕВОЗМОЖЕН" >&2
|
||||
exit 1
|
||||
fi
|
||||
. ./.rollback.env
|
||||
podman tag "$PREV_APP" wordpdf-app:prod
|
||||
podman tag "$PREV_WEB" wordpdf-web:prod
|
||||
git -C src reset --hard "$PREV_COMMIT"
|
||||
podman-compose up -d --force-recreate app web
|
||||
for _ in $(seq 1 60); do
|
||||
[ "$(podman inspect -f '{{.State.Health.Status}}' wordpdf-prod-app-1)" = healthy ] && break
|
||||
sleep 2
|
||||
done
|
||||
[ "$(podman inspect -f '{{.State.Health.Status}}' wordpdf-prod-app-1)" = healthy ] || { echo "app НЕ healthy после отката" >&2; exit 1; }
|
||||
podman-compose restart gateway
|
||||
curl -fsS http://192.168.88.88:9010/actuator/health
|
||||
Reference in New Issue
Block a user