-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (124 loc) · 5.94 KB
/
gcp-deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Deploy to Google Cloud Run
on:
push:
branches:
- main
env:
# Transport Service
TRANSPORT_SERVICE_DATABASE_URL: ${{ secrets.TRANSPORT_SERVICE_DATABASE_URL }}
TRANSPORT_SERVICE_PORT: 8080
TRANSPORT_SERVICE_LOG_LEVEL: INFO
# Translation Service
TRANSLATION_SERVICE_DATABASE_URL: ${{ secrets.TRANSLATION_SERVICE_DATABASE_URL }}
TRANSLATION_SERVICE_PORT: 8080
TRANSLATION_SERVICE_LOG_LEVEL: INFO
TRANSLATION_SERVICE_SUPPORTED_LANGUAGES: '{"en":"English","ru":"Русский","uk":"Українська","de":"Deutsch","fr":"Français","es":"Español","it":"Italiano"}'
# Telegram Bot Service
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TRANSPORT_SERVICE_URL: ${{ secrets.TRANSPORT_SERVICE_URL }}
TELEGRAM_BOT_DATABASE_URL: ${{ secrets.TELEGRAM_BOT_DATABASE_URL }}
TELEGRAM_BOT_SUPPORTED_LANGUAGES: '{"en":"English","ru":"Русский","uk":"Українська","de":"Deutsch","fr":"Français","es":"Español","it":"Italiano"}'
TELEGRAM_BOT_LOG_LEVEL: INFO
GCP_REGION: ${{ secrets.GCP_REGION }}
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GKE_CLUSTER: ${{ secrets.GKE_CLUSTER_NAME }}
GKE_ZONE: ${{ secrets.GKE_ZONE }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install python-dotenv
pip install -r requirements.txt
pip install pytest pytest-cov
# Тестирование всех сервисов
- name: Run Tests
run: |
# Запуск тестов для каждого сервиса
cd transport_service && pytest
cd ../translation_service && pytest
cd ../telegram_bot_service && pytest
# Авторизация в Google Cloud
- name: Google Cloud Auth
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Configure Docker
run: |
gcloud auth configure-docker ${{ env.GCP_REGION }}-docker.pkg.dev
# Сборка и публикация Docker-образов для каждого сервиса
- name: Build and Push Transport Service
run: |
cd transport_service
docker build -t europe-west12-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/transport-service/service:${{ github.sha }} .
gcloud auth configure-docker europe-west12-docker.pkg.dev
docker push europe-west12-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/transport-service/service:${{ github.sha }}
- name: Build and Push Translation Service
run: |
cd translation_service
docker build -t europe-west12-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/translation-service/service:${{ github.sha }} .
gcloud auth configure-docker europe-west12-docker.pkg.dev
docker push europe-west12-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/translation-service/service:${{ github.sha }}
- name: Build and Push Telegram Bot Service
run: |
cd telegram_bot_service
docker build -t europe-west12-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/telegram-bot/service:${{ github.sha }} .
gcloud auth configure-docker europe-west12-docker.pkg.dev
docker push europe-west12-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/telegram-bot/service:${{ github.sha }}
# Деплой в Cloud Run (если применимо)
- name: Deploy to Cloud Run Transport Service
env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GITHUB_SHA: ${{ github.sha }}
TRANSPORT_SERVICE_URL: ${{ secrets.TRANSPORT_SERVICE_URL }}
DATABASE_URL: ${{ secrets.TRANSPORT_SERVICE_DATABASE_URL }}
run: |
gcloud run deploy transport-service \
--image europe-west12-docker.pkg.dev/$PROJECT_ID/transport-service/service:$GITHUB_SHA \
--platform managed \
--region europe-west12 \
--service-account=923903653655-compute@developer.gserviceaccount.com \
--allow-unauthenticated \
--set-env-vars "TRANSPORT_SERVICE_URL=$TRANSPORT_SERVICE_URL,DATABASE_URL=$DATABASE_URL"
- name: Deploy to Cloud Run Translation Service
env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GITHUB_SHA: ${{ github.sha }}
TRANSLATION_SERVICE_URL: ${{ secrets.TRANSLATION_SERVICE_URL }}
DATABASE_URL: ${{ secrets.TRANSLATION_SERVICE_DATABASE_URL }}
run: |
gcloud run deploy translation-service \
--image europe-west12-docker.pkg.dev/$PROJECT_ID/translation-service/service:$GITHUB_SHA \
--platform managed \
--region europe-west12 \
--service-account=923903653655-compute@developer.gserviceaccount.com \
--allow-unauthenticated \
--set-env-vars "DATABASE_URL=$DATABASE_URL"
- name: Deploy to Cloud Run Telegram Bot Service
env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GITHUB_SHA: ${{ github.sha }}
TELEGRAM_BOT_SERVICE_URL: ${{ secrets.TELEGRAM_BOT_SERVICE_URL }}
DATABASE_URL: ${{ secrets.TELEGRAM_BOT_SERVICE_DATABASE_URL }}
TRANSPORT_SERVICE_URL: ${{ secrets.TRANSPORT_SERVICE_URL }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
run: |
gcloud run deploy telegram-bot \
--image europe-west12-docker.pkg.dev/$PROJECT_ID/telegram-bot/service:$GITHUB_SHA \
--platform managed \
--region europe-west12 \
--service-account=923903653655-compute@developer.gserviceaccount.com \
--allow-unauthenticated \
--set-env-vars "TRANSPORT_SERVICE_URL=$TRANSPORT_SERVICE_URL,DATABASE_URL=$DATABASE_URL,TELEGRAM_BOT_TOKEN=$TELEGRAM_BOT_TOKEN"