127 lines
4.6 KiB
YAML
127 lines
4.6 KiB
YAML
name: Deploy Telegram Bot
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
env:
|
|
VERSION: 2.7.2
|
|
|
|
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: git.codeanddice.ru # НАПРИМЕР: gitea.my-server.com
|
|
username: toutsu
|
|
password: ${{ secrets.GIT_TOKEN }}
|
|
|
|
- name: Build Bot image
|
|
run: |
|
|
docker build \
|
|
--label "org.opencontainers.image.source=https://git.codeanddice.ru/${{ gitea.repository }}" \
|
|
-f src/GmRelay.Bot/Dockerfile \
|
|
-t git.codeanddice.ru/toutsu/gmrelay-bot:latest \
|
|
-t git.codeanddice.ru/toutsu/gmrelay-bot:${{ env.VERSION }} \
|
|
.
|
|
|
|
- name: Push Bot image
|
|
run: |
|
|
docker push git.codeanddice.ru/toutsu/gmrelay-bot:latest
|
|
docker push git.codeanddice.ru/toutsu/gmrelay-bot:${{ env.VERSION }}
|
|
|
|
- name: Build Discord Bot image
|
|
run: |
|
|
docker build \
|
|
--label "org.opencontainers.image.source=https://git.codeanddice.ru/${{ gitea.repository }}" \
|
|
-f src/GmRelay.DiscordBot/Dockerfile \
|
|
-t git.codeanddice.ru/toutsu/gmrelay-discord-bot:latest \
|
|
-t git.codeanddice.ru/toutsu/gmrelay-discord-bot:${{ env.VERSION }} \
|
|
.
|
|
|
|
- name: Push Discord Bot image
|
|
run: |
|
|
docker push git.codeanddice.ru/toutsu/gmrelay-discord-bot:latest
|
|
docker push git.codeanddice.ru/toutsu/gmrelay-discord-bot:${{ env.VERSION }}
|
|
|
|
- name: Build Web image
|
|
run: |
|
|
docker build \
|
|
--label "org.opencontainers.image.source=https://git.codeanddice.ru/${{ gitea.repository }}" \
|
|
-f src/GmRelay.Web/Dockerfile \
|
|
-t git.codeanddice.ru/toutsu/gmrelay-web:latest \
|
|
-t git.codeanddice.ru/toutsu/gmrelay-web:${{ env.VERSION }} \
|
|
.
|
|
|
|
- name: Push Web image
|
|
run: |
|
|
docker push git.codeanddice.ru/toutsu/gmrelay-web:latest
|
|
docker push git.codeanddice.ru/toutsu/gmrelay-web:${{ env.VERSION }}
|
|
|
|
# ЧАСТЬ 1.5: Сканируем собранные образы на уязвимости
|
|
scan-images:
|
|
needs: build-and-push
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Install Trivy
|
|
run: |
|
|
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
|
|
|
|
- name: Scan Bot image
|
|
run: |
|
|
trivy image \
|
|
--severity HIGH,CRITICAL \
|
|
--exit-code 1 \
|
|
--format table \
|
|
git.codeanddice.ru/toutsu/gmrelay-bot:${{ env.VERSION }}
|
|
|
|
- name: Scan Discord Bot image
|
|
run: |
|
|
trivy image \
|
|
--severity HIGH,CRITICAL \
|
|
--exit-code 1 \
|
|
--format table \
|
|
git.codeanddice.ru/toutsu/gmrelay-discord-bot:${{ env.VERSION }}
|
|
|
|
- name: Scan Web image
|
|
run: |
|
|
trivy image \
|
|
--severity HIGH,CRITICAL \
|
|
--exit-code 1 \
|
|
--format table \
|
|
git.codeanddice.ru/toutsu/gmrelay-web:${{ env.VERSION }}
|
|
|
|
# ЧАСТЬ 2: Запускаем эти образы на самом сервере
|
|
deploy:
|
|
needs: scan-images
|
|
runs-on: ubuntu-latest # Тот же локальный раннер
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Create .env file with secrets
|
|
run: |
|
|
echo "TELEGRAM_BOT_TOKEN=${{ secrets.TELEGRAM_BOT_TOKEN }}" > .env
|
|
echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" >> .env
|
|
echo "DISCORD_BOT_TOKEN=${{ secrets.DISCORD_BOT_TOKEN }}" >> .env
|
|
echo "TELEGRAM_BOT_USERNAME=${{ secrets.TELEGRAM_BOT_USERNAME }}" >> .env
|
|
echo "TELEGRAM_MINI_APP_URL=${{ secrets.TELEGRAM_MINI_APP_URL }}" >> .env
|
|
|
|
- name: Deploy Containers
|
|
run: |
|
|
# Авторизуемся локальным докером в нашей Gitea
|
|
docker login git.codeanddice.ru/ -u toutsu -p ${{ secrets.GIT_TOKEN }}
|
|
|
|
# Pull гарантирует, что мы получили нужную версию.
|
|
docker compose pull bot discord web
|
|
|
|
# Запускаем! Флаг -d оставит их работать в фоне.
|
|
docker compose up -d
|