All checks were successful
continuous-integration/drone/push Build is passing
160 lines
5.2 KiB
YAML
160 lines
5.2 KiB
YAML
# --- Пайплайн №1: Сборка Docker-образа для backend ---
|
||
kind: pipeline
|
||
type: docker
|
||
name: build-backend
|
||
|
||
clone:
|
||
depth: 0
|
||
recursive: true
|
||
# Запускать только если были изменения в папке backend/
|
||
trigger:
|
||
event: [push, pull_request]
|
||
|
||
steps:
|
||
- name: force-init-submodules
|
||
image: alpine/git
|
||
commands:
|
||
# Очищаем все возможные предыдущие состояния субмодулей
|
||
- git submodule deinit --all --force
|
||
# Синхронизируем конфигурацию с .gitmodules
|
||
- git submodule sync --recursive
|
||
# Снова инициализируем с нуля
|
||
- git submodule update --init --recursive --force
|
||
- echo "Submodule status after forced update:"
|
||
- git submodule status
|
||
#- ls -laR
|
||
- name: build-and-publish-backend
|
||
image: plugins/docker
|
||
settings:
|
||
# Имя репозитория в Docker Registry вашего Gitea
|
||
repo: gitea.mrixs.me/minecraft-platform/backend
|
||
# Адрес вашего Docker Registry
|
||
registry: gitea.mrixs.me
|
||
# Путь к Dockerfile внутри клонированного репозитория
|
||
dockerfile: backend/Dockerfile
|
||
# Контекст сборки
|
||
context: backend
|
||
# Логин и пароль для пуша в Gitea Registry (нужно настроить в секретах Drone)
|
||
username: { from_secret: gitea_username }
|
||
password: { from_secret: gitea_password }
|
||
# Теги для образа: latest и короткий хеш коммита
|
||
tags:
|
||
- latest
|
||
- ${DRONE_COMMIT_SHA:0:7}
|
||
|
||
---
|
||
# --- Пайплайн №2: Сборка Docker-образа для ping-helper ---
|
||
kind: pipeline
|
||
type: docker
|
||
name: build-ping-helper
|
||
|
||
clone:
|
||
depth: 0
|
||
recursive: true
|
||
|
||
trigger:
|
||
event: [push, pull_request]
|
||
|
||
steps:
|
||
- name: force-init-submodules
|
||
image: alpine/git
|
||
commands:
|
||
# Очищаем все возможные предыдущие состояния субмодулей
|
||
- git submodule deinit --all --force
|
||
# Синхронизируем конфигурацию с .gitmodules
|
||
- git submodule sync --recursive
|
||
# Снова инициализируем с нуля
|
||
- git submodule update --init --recursive --force
|
||
- echo "Submodule status after forced update:"
|
||
- git submodule status
|
||
#- ls -laR
|
||
- name: build-and-publish-ping-helper
|
||
image: plugins/docker
|
||
settings:
|
||
repo: gitea.mrixs.me/minecraft-platform/ping-helper
|
||
registry: gitea.mrixs.me
|
||
dockerfile: ping-helper/Dockerfile
|
||
context: ping-helper
|
||
username: { from_secret: gitea_username }
|
||
password: { from_secret: gitea_password }
|
||
tags:
|
||
- latest
|
||
- ${DRONE_COMMIT_SHA:0:7}
|
||
|
||
---
|
||
# --- Пайплайн №3: Сборка Docker-образа для frontend ---
|
||
kind: pipeline
|
||
type: docker
|
||
name: build-frontend
|
||
|
||
clone:
|
||
depth: 0
|
||
recursive: true
|
||
|
||
trigger:
|
||
event: [push, pull_request]
|
||
|
||
steps:
|
||
- name: force-init-submodules
|
||
image: alpine/git
|
||
commands:
|
||
- git submodule deinit --all --force
|
||
- git submodule sync --recursive
|
||
- git submodule update --init --recursive --force
|
||
- echo "Submodule status after forced update:"
|
||
- git submodule status
|
||
- name: build-and-publish-frontend
|
||
image: plugins/docker
|
||
settings:
|
||
repo: gitea.mrixs.me/minecraft-platform/frontend
|
||
registry: gitea.mrixs.me
|
||
dockerfile: frontend/Dockerfile
|
||
context: frontend
|
||
username: { from_secret: gitea_username }
|
||
password: { from_secret: gitea_password }
|
||
tags:
|
||
- latest
|
||
- ${DRONE_COMMIT_SHA:0:7}
|
||
|
||
---
|
||
# --- Пайплайн №4: Развертывание на продакшен-сервере ---
|
||
kind: pipeline
|
||
type: ssh
|
||
name: deploy-production
|
||
|
||
# Запускать только при пуше в ветку master
|
||
trigger:
|
||
ref:
|
||
- refs/heads/master
|
||
event: [push]
|
||
|
||
# Этот пайплайн зависит от успешного выполнения сборок
|
||
depends_on:
|
||
- build-backend
|
||
- build-ping-helper
|
||
- build-frontend
|
||
|
||
# Настройки подключения к вашему серверу
|
||
server:
|
||
host: { from_secret: ssh_host }
|
||
user: { from_secret: ssh_user }
|
||
ssh_key: { from_secret: ssh_key }
|
||
|
||
# Команды, которые будут выполнены на сервере
|
||
commands:
|
||
- echo "--- Starting deployment ---"
|
||
- cd $DEPLOY_PATH # Переходим в директорию проекта
|
||
- echo "1. Updating repository..."
|
||
- git pull origin master # Обновляем основной репозиторий
|
||
- git submodule update --init --recursive # Обновляем все субмодули
|
||
- echo "2. Pulling new Docker images..."
|
||
- docker compose pull # Скачиваем свежесобранные образы (backend, frontend, ping-helper)
|
||
- echo "3. Restarting services..."
|
||
- docker compose up -d --remove-orphans # Перезапускаем все сервисы
|
||
- echo "4. Cleaning up old images..."
|
||
- docker image prune -f # Удаляем неиспользуемые образы
|
||
- echo "--- Deployment finished ---"
|
||
|
||
environment:
|
||
DEPLOY_PATH: { from_secret: deploy_path }
|