test archive

This commit is contained in:
2026-03-24 11:30:17 +03:00
parent d6638215f1
commit 4eaa80c563
3 changed files with 393 additions and 22 deletions

View File

@@ -1,28 +1,85 @@
name: CI
name: CI/CD
on:
push:
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
- test
workflow_dispatch:
jobs:
test:
test-backend:
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
cd api
pip install -r requirements.txt
- name: Verify build
run: |
cd api
python -c "from main import app"
- name: Run tests
run: |
pytest -q
cd api
pytest tests/
# test-frontend:
# needs: test-backend
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Set up Node.js
# uses: actions/setup-node@v4
# with:
# node-version: '20'
# - name: Install dependencies
# run: |
# cd web
# npm ci
# - name: Build frontend
# run: |
# cd web
# npm run build
create-archives:
needs: [test-backend, test-frontend]
runs-on: ubuntu-latest
if: success()
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create archives
run: |
# Создаём архивы с исключением ненужных файлов
zip -r api.zip api/ -x "*.pyc" "*__pycache__*" "*.git*" "*.pytest_cache*"
zip -r web.zip web/ -x "node_modules/*" ".git*" "dist/*" "*.log"
# Создаём общий архив
zip -r full-build.zip api/ web/ -x "*/node_modules/*" "*__pycache__*" "*.pyc" "*.git*"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: |
api.zip
web.zip
full-build.zip
retention-days: 30 # сколько дней хранить артефакты

View File

@@ -0,0 +1,314 @@
# name: Release pipeline
# on:
# workflow_dispatch:
# env:
# WEB_IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/tatikoma-web
# WORKER_IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/tatikoma-worker
# PROJECT_DIR: /home/${{ secrets.USER }}/tatikoma
# jobs:
# build-and-push:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
# - name: Log in to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_PASSWORD }}
# - name: Build and push tatikoma-web image
# uses: docker/build-push-action@v5
# with:
# context: .
# file: ./Dockerfile.web
# push: true
# tags: |
# ${{ secrets.DOCKERHUB_USERNAME }}/tatikoma-web:latest
# cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/tatikoma-web:latest
# cache-to: type=inline
# - name: Build and push tatikoma-worker image
# uses: docker/build-push-action@v5
# with:
# context: .
# file: ./Dockerfile.worker
# push: true
# tags: |
# ${{ secrets.DOCKERHUB_USERNAME }}/tatikoma-worker:latest
# cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/tatikoma-worker:latest
# cache-to: type=inline
# - name: Verify push
# run: |
# echo "Docker images successfully built and pushed to Docker Hub"
# echo "Images:"
# echo "- ${{ secrets.DOCKERHUB_USERNAME }}/tatikoma-web:latest"
# echo "- ${{ secrets.DOCKERHUB_USERNAME }}/tatikoma-worker:latest"
# build-and-push-send-success-message:
# runs-on: ubuntu-latest
# needs: build-and-push
# if: success()
# steps:
# - name: Send success message
# uses: appleboy/telegram-action@master
# with:
# to: ${{ secrets.TELEGRAM_TO }}
# token: ${{ secrets.TELEGRAM_TOKEN }}
# format: markdown
# message: |
# *${{ github.workflow }}*
# ✅ New images pushed to Dockerhub 🐳
# Images:
# - `${{ secrets.DOCKERHUB_USERNAME }}/tatikoma-web:latest`
# - `${{ secrets.DOCKERHUB_USERNAME }}/tatikoma-worker:latest`
# Status: Success
# build-and-push-send-failure-message:
# runs-on: ubuntu-latest
# needs: build-and-push
# if: failure()
# steps:
# - name: Send failure message
# uses: appleboy/telegram-action@master
# with:
# to: ${{ secrets.TELEGRAM_TO }}
# token: ${{ secrets.TELEGRAM_TOKEN }}
# format: markdown
# message: |
# *${{ github.workflow }}*
# ❌ Error creating and pushing docker images
# [View failed workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
# deploy:
# name: Deploy to server
# runs-on: ubuntu-latest
# needs: build-and-push
# if: success()
# outputs:
# container_status: ${{ steps.get_status.outputs.status }}
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Create project directory
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USER }}
# password: ${{ secrets.SSH_PASSWORD }}
# script: |
# set -e
# echo "Creating project directory..."
# mkdir -p tatikoma/liquibase
# mkdir -p tatikoma/liquibase/changelog
# - name: Copy project files
# shell: bash
# run: |
# # Копируем docker-compose.yml
# sshpass -p "${{ secrets.SSH_PASSWORD }}" scp -o StrictHostKeyChecking=no \
# docker-compose.yml \
# ${{ secrets.USER }}@${{ secrets.HOST }}:tatikoma/
# # Копируем liquibase файлы
# sshpass -p "${{ secrets.SSH_PASSWORD }}" scp -o StrictHostKeyChecking=no \
# -r ./liquibase/changelog/ \
# ${{ secrets.USER }}@${{ secrets.HOST }}:tatikoma/liquibase/
# # Копируем nginx конфиги
# sshpass -p "${{ secrets.SSH_PASSWORD }}" scp -o StrictHostKeyChecking=no \
# -r ./nginx/ \
# ${{ secrets.USER }}@${{ secrets.HOST }}:tatikoma/
# - name: Create or update environment file
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USER }}
# password: ${{ secrets.SSH_PASSWORD }}
# script: |
# set -e
# cd tatikoma
# rm -f .env
# touch .env
# echo "${{ secrets.ENV_FILE }}" >> .env
# echo "Environment file created/updated"
# - name: Prepare directories
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USER }}
# password: ${{ secrets.SSH_PASSWORD }}
# script: |
# set -e
# cd tatikoma
# mkdir -p {nginx/ssl,nginx/htpasswd,uptime-kuma-data}
# - name: Setup authentication
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USER }}
# password: ${{ secrets.SSH_PASSWORD }}
# script: |
# set -e
# cd tatikoma
# echo "Setting up authentication..."
# mkdir -p nginx/htpasswd
# if ! command -v htpasswd &> /dev/null; then
# echo "Installing apache2-utils..."
# apt-get update && apt-get install -y apache2-utils
# fi
# # Используем echo для передачи пароля через stdin
# # Это безопаснее, чем передавать как аргумент
# htpasswd -b -c nginx/htpasswd/.htpasswd "${{ secrets.UPTIME_KUMA_USER }}" "${{ secrets.UPTIME_KUMA_PASSWORD }}"
# echo "Authentication setup complete"
# - name: Setup SSL certificates (if not exists)
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USER }}
# password: ${{ secrets.SSH_PASSWORD }}
# script: |
# set -e
# cd tatikoma
# echo "Checking SSL certificates..."
# # Проверяем существование SSL сертификатов
# if [ ! -f "nginx/ssl/live/${{ secrets.HOST }}/privkey.pem" ]; then
# echo "ERROR: SSL certificates not found!"
# echo "Please generate SSL certificates manually first:"
# echo "mkdir -p nginx/ssl/live/${{ secrets.HOST }}/"
# echo "Then place privkey.pem and fullchain.pem in that directory"
# exit 1
# else
# echo "SSL certificates found, continuing..."
# fi
# - name: Log in to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_PASSWORD }}
# - name: Clean up old images and containers
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USER }}
# password: ${{ secrets.SSH_PASSWORD }}
# script: |
# set -e
# echo "Stopping and removing Tatikoma containers..."
# docker stop tatikoma_web tatikoma_liquibase tatikoma_worker tatikoma_nginx tatikoma_uptime_kuma 2>/dev/null || true
# docker rm tatikoma_web tatikoma_liquibase tatikoma_worker tatikoma_nginx tatikoma_uptime_kuma 2>/dev/null || true
# echo "Cleaning up old Docker images..."
# docker images lulufox/tatikoma-web --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}\t{{.CreatedAt}}" || true
# docker images lulufox/tatikoma-worker --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}\t{{.CreatedAt}}" || true
# docker rmi $(docker images lulufox/tatikoma-web -q) 2>/dev/null || true
# docker rmi $(docker images lulufox/tatikoma-worker -q) 2>/dev/null || true
# docker image prune -f
# - name: Pull latest images
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USER }}
# password: ${{ secrets.SSH_PASSWORD }}
# script: |
# set -e
# echo "Pulling latest Docker images..."
# docker pull lulufox/tatikoma-web:latest
# docker pull lulufox/tatikoma-worker:latest
# - name: Run migrations
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USER }}
# password: ${{ secrets.SSH_PASSWORD }}
# script: |
# set -e
# cd tatikoma
# echo "Running migrations..."
# docker compose up -d liquibase
# - name: Start application services
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USER }}
# password: ${{ secrets.SSH_PASSWORD }}
# script: |
# set -e
# cd tatikoma
# echo "Starting all services..."
# docker compose up -d
# echo "Waiting for services to start..."
# sleep 30
# echo "Current Tatikoma containers status:"
# docker ps --filter "name=tatikoma" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
# echo "Nginx configuration test:"
# docker exec tatikoma_nginx nginx -t || true
# - name: Get container status
# id: get_status
# run: |
# sleep 15
# status=$(sshpass -p "${{ secrets.SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no \
# ${{ secrets.USER }}@${{ secrets.HOST }} \
# "docker ps -a --filter "name=tatikoma" --format 'table {{.Names}}\t{{.Status}}'")
# echo "status<<EOF" >> $GITHUB_OUTPUT
# echo "$status" >> $GITHUB_OUTPUT
# echo "EOF" >> $GITHUB_OUTPUT
# send_message:
# runs-on: ubuntu-latest
# needs: deploy
# if: always()
# steps:
# - name: send message
# uses: appleboy/telegram-action@master
# with:
# to: ${{ secrets.TELEGRAM_TO }}
# token: ${{ secrets.TELEGRAM_TOKEN }}
# format: markdown
# message: |
# *${{ github.workflow }}*
# Репозиторий: \`${{ github.repository }}\`
# Статус контейнеров:
# ```
# ${{ needs.deploy.outputs.container_status || 'Не удалось получить статус' }}
# ```
# Uptime Kuma доступен по: https://${{ secrets.HOST }}

View File

@@ -1,17 +1,17 @@
name: Test Workflow
# name: Test Workflow
on:
push:
# on:
# push:
jobs:
test:
runs-on: ubuntu-latest
# jobs:
# test:
# runs-on: ubuntu-latest
steps:
- name: Print environment variables
run: |
echo "GITHUB_REPOSITORY: $GITHUB_REPOSITORY"
echo "GITHUB_SHA: $GITHUB_SHA"
echo "GITHUB_REF: $GITHUB_REF"
echo "GITHUB_ACTOR: $GITHUB_ACTOR"
echo "PATH: $PATH"
# steps:
# - name: Print environment variables
# run: |
# echo "GITHUB_REPOSITORY: $GITHUB_REPOSITORY"
# echo "GITHUB_SHA: $GITHUB_SHA"
# echo "GITHUB_REF: $GITHUB_REF"
# echo "GITHUB_ACTOR: $GITHUB_ACTOR"
# echo "PATH: $PATH"