diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 46f77b2..8bf3bb8 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -3,11 +3,43 @@ name: Deploy Telegram Bot on: push: branches: - - main # Срабатывает только при пуше в main + - main jobs: + # ЧАСТЬ 1: Собираем образы и кладем в Gitea (чтобы делиться с ребятами) + build-and-push: + runs-on: ubuntu-latest # Замени на метку твоего раннера, если она другая + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Login to Gitea Container Registry + uses: docker/login-action@v3 + with: + registry: https://git.codeanddice.ru # НАПРИМЕР: gitea.my-server.com + username: ${{ gitea.actor }} + password: ${{ secrets.GITEA_TOKEN }} + + - name: Build and push Bot + uses: docker/build-push-action@v5 + with: + context: . + file: src/GmRelay.Bot/Dockerfile + push: true + tags: https://git.codeanddice.ru/${{ gitea.actor }}/gmrelay-bot:latest + + - name: Build and push Web + uses: docker/build-push-action@v5 + with: + context: . + file: src/GmRelay.Web/Dockerfile + push: true + tags: https://git.codeanddice.ru/${{ gitea.actor }}/gmrelay-web:latest + + # ЧАСТЬ 2: Запускаем эти образы на самом сервере deploy: - runs-on: ubuntu-latest + needs: build-and-push + runs-on: ubuntu-latest # Тот же локальный раннер steps: - name: Checkout repository uses: actions/checkout@v4 @@ -17,8 +49,16 @@ jobs: echo "TELEGRAM_BOT_TOKEN=${{ secrets.TELEGRAM_BOT_TOKEN }}" > .env echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" >> .env echo "TELEGRAM_BOT_USERNAME=${{ secrets.TELEGRAM_BOT_USERNAME }}" >> .env - - name: Build and Deploy + + - name: Deploy Containers run: | - # Останавливаем старого бота и поднимаем нового - docker compose down - docker compose up -d --build + # Авторизуемся локальным докером в нашей Gitea + docker login https://git.codeanddice.ru/ -u ${{ gitea.actor }} -p ${{ secrets.GITEA_TOKEN }} + + # Так как раннер на том же сервере, образ уже закэширован, + # но pull гарантирует, что compose подхватит именно свежий latest-тег. + docker compose pull bot web + + # Запускаем! Флаг -d оставит их работать в фоне. + # БД не перезапустится, так как её образ не менялся. + docker compose up -d \ No newline at end of file diff --git a/compose.yaml b/compose.yaml index d68e2e2..65090a1 100644 --- a/compose.yaml +++ b/compose.yaml @@ -12,15 +12,13 @@ services: ports: - "5432:5432" healthcheck: - test: ["CMD-SHELL", "pg_isready -U gmrelay -d gmrelay_db"] + test: [ "CMD-SHELL", "pg_isready -U gmrelay -d gmrelay_db" ] interval: 3s timeout: 3s retries: 10 bot: - build: - context: . - dockerfile: src/GmRelay.Bot/Dockerfile + image: https://git.codeanddice.ru/toutsu/gmrelay-bot:latest container_name: gmrelay_bot restart: always network_mode: host @@ -32,9 +30,7 @@ services: - "Telegram__BotToken=${TELEGRAM_BOT_TOKEN}" web: - build: - context: . - dockerfile: src/GmRelay.Web/Dockerfile + image: https://git.codeanddice.ru/toutsu/gmrelay-web:latest container_name: gmrelay_web restart: always network_mode: host