80 lines
2.4 KiB
YAML
80 lines
2.4 KiB
YAML
name: Build and deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- 'main'
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: self-hosted
|
|
steps:
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
- name: Login to Docker Hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
push: true
|
|
tags: smallbuster/fire-exam:latest
|
|
deploy:
|
|
runs-on: self-hosted
|
|
needs: build
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Login to Docker Hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Set up Docker Compose
|
|
run: |
|
|
docker compose version
|
|
|
|
- name: Stop and remove existing containers
|
|
run: |
|
|
docker compose -f docker-compose.yaml down || true
|
|
|
|
- name: Pull Docker images
|
|
run: |
|
|
docker compose -f docker-compose.yaml pull
|
|
|
|
- name: Start containers
|
|
run: |
|
|
docker compose -f docker-compose.yaml up -d
|
|
|
|
- name: Notify Telegram about success
|
|
if: success()
|
|
uses: appleboy/telegram-action@master
|
|
with:
|
|
to: ${{ secrets.TELEGRAM_CHAT_ID }}
|
|
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
|
|
message: |
|
|
✅ Деплой успешно завершен!
|
|
Репозиторий: ${{ github.repository }}
|
|
Ветка: ${{ github.ref }}
|
|
Коммит: ${{ github.sha }}
|
|
Сервер: ${{ secrets.SERVER_IP }}
|
|
Путь: ${{ secrets.DEPLOY_PATH }}
|
|
|
|
- name: Notify Telegram about failure
|
|
if: failure()
|
|
uses: appleboy/telegram-action@master
|
|
with:
|
|
to: ${{ secrets.TELEGRAM_CHAT_ID }}
|
|
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
|
|
message: |
|
|
❌ Деплой не удался!
|
|
Репозиторий: ${{ github.repository }}
|
|
Ветка: ${{ github.ref }}
|
|
Коммит: ${{ github.sha }}
|
|
Подробности: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |