Skip to content

gcloud auth in Build and Push #19

gcloud auth in Build and Push

gcloud auth in Build and Push #19

Workflow file for this run

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 ${{ env.GCP_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/transport-service/service:${{ github.sha }} .
gcloud auth configure-docker ${{ env.GCP_REGION }}-docker.pkg.dev
docker push ${{ env.GCP_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/transport-service/service:${{ github.sha }}
- name: Build and Push Translation Service
run: |
cd translation_service
docker build -t ${{ env.GCP_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/translation-service/service:${{ github.sha }} .
gcloud auth configure-docker ${{ env.GCP_REGION }}-docker.pkg.dev
docker push ${{ env.GCP_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/translation-service/service:${{ github.sha }}
- name: Build and Push Telegram Bot Service
run: |
cd telegram_bot_service
docker build -t ${{ env.GCP_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/telegram-bot-service/service:${{ github.sha }} .
gcloud auth configure-docker ${{ env.GCP_REGION }}-docker.pkg.dev
docker push ${{ env.GCP_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/telegram-bot-service/service:${{ github.sha }}
# Деплой в Cloud Run (если применимо)
- name: Deploy to Cloud Run Transport Service
run: |
# Пример деплоя транспортного сервиса
gcloud run deploy transport-service \
--image ${{ env.GCP_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/transport-service/service:${{ github.sha }} \
--platform managed \
--region ${{ env.GCP_REGION }} \
--allow-unauthenticated
- name: Deploy to Cloud Run Translation Service
run: |
# Пример деплоя транспортного сервиса
gcloud run deploy translation-service \
--image ${{ env.GCP_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/translation-service/service:${{ github.sha }} \
--platform managed \
--region ${{ env.GCP_REGION }} \
--allow-unauthenticated \
--port 8080 \
--cpu 1 \
--memory 512Mi \
--max-instances 3 \
--set-env-vars "DATABASE_URL=${{ secrets.DATABASE_URL }}"
- name: Deploy to Cloud Run Telegram Bot Service
run: |
# Пример деплоя транспортного сервиса
gcloud run deploy telegram-bot \
--image ${{ env.GCP_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/telegram-bot-service/service:${{ github.sha }} \
--platform managed \
--region ${{ env.GCP_REGION }} \
--allow-unauthenticated \
--port 8080 \
--cpu 1 \
--memory 512Mi \
--max-instances 3 \
--set-env-vars "TRANSPORT_SERVICE_URL=${{ secrets.TRANSPORT_SERVICE_URL }},TELEGRAM_BOT_TOKEN=${{ secrets.TELEGRAM_BOT_TOKEN }}"