Update CI/CD workflows with Google Auth and latest actions #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to Google Cloud Run | |
on: | |
push: | |
branches: [ main ] | |
paths: | |
- 'telegram_bot_service/**' | |
- '.github/workflows/gcp-deploy.yml' | |
- '.github/workflows/docker-build.yml' | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.9' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install pytest | |
pip install -r telegram_bot_service/requirements.txt | |
- name: Run tests | |
run: | | |
cd telegram_bot_service | |
pytest tests/ | |
deploy: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
# Новый шаг аутентификации | |
- name: Google Auth | |
id: auth | |
uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} | |
# Настройка Cloud SDK | |
- name: Set up Cloud SDK | |
uses: google-github-actions/setup-gcloud@v2 | |
- name: Authorize Docker | |
run: gcloud auth configure-docker | |
- name: Build Docker Image | |
run: | | |
docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/telegram-bot-service:${{ github.sha }} ./telegram_bot_service | |
- name: Push to Container Registry | |
run: | | |
docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/telegram-bot-service:${{ github.sha }} | |
- name: Deploy to Cloud Run | |
run: | | |
gcloud run deploy telegram-bot-service \ | |
--image gcr.io/${{ secrets.GCP_PROJECT_ID }}/telegram-bot-service:${{ github.sha }} \ | |
--platform managed \ | |
--region ${{ secrets.GCP_REGION }} \ | |
--allow-unauthenticated \ | |
--set-env-vars TELEGRAM_BOT_TOKEN=${{ secrets.TELEGRAM_BOT_TOKEN }} |